• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef NET_GRPC_PHP_GRPC_CHANNEL_H_
20 #define NET_GRPC_PHP_GRPC_CHANNEL_H_
21 
22 #include "channel_credentials.h"
23 #include "php_grpc.h"
24 
25 #if PHP_MAJOR_VERSION >= 8
26 #define ZEND_HASH_INIT(hash_table, limit, descriptor, zend_bool) _zend_hash_init(hash_table, limit, descriptor, zend_bool);
27 #else
28 #define ZEND_HASH_INIT(hash_table, limit, descriptor, zend_bool) zend_hash_init_ex(hash_table, limit, NULL, descriptor, zend_bool, 0);
29 #endif
30 
31 /* Class entry for the PHP Channel class */
32 extern zend_class_entry *grpc_ce_channel;
33 
34 typedef struct _grpc_channel_wrapper {
35   grpc_channel *wrapped;
36   char *key;
37   char *target;
38   char *args_hashstr;
39   char *creds_hashstr;
40   size_t ref_count;
41   gpr_mu mu;
42   grpc_channel_args args;
43   wrapped_grpc_channel_credentials *creds;
44 } grpc_channel_wrapper;
45 
46 /* Wrapper struct for grpc_channel that can be associated with a PHP object */
PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_channel)47 PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_channel)
48   grpc_channel_wrapper *wrapper;
49 PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_channel)
50 
51 static inline wrapped_grpc_channel
52 *wrapped_grpc_channel_from_obj(zend_object *obj) {
53   return (wrapped_grpc_channel*)((char*)(obj) -
54                                  XtOffsetOf(wrapped_grpc_channel, std));
55 }
56 
57 /* Initializes the Channel class */
58 GRPC_STARTUP_FUNCTION(channel);
59 
60 /* Iterates through a PHP array and populates args with the contents */
61 int php_grpc_read_args_array(zval *args_array, grpc_channel_args *args
62                              TSRMLS_DC);
63 
64 void generate_sha1_str(char *sha1str, char *str, php_grpc_int len);
65 
66 void php_grpc_delete_persistent_list_entry(char *key, php_grpc_int key_len
67                                            TSRMLS_DC);
68 
69 typedef struct _channel_persistent_le {
70   grpc_channel_wrapper *channel;
71 } channel_persistent_le_t;
72 
73 typedef struct _target_bound_le {
74   int upper_bound;
75   int current_count;
76 } target_bound_le_t;
77 
78 #endif /* NET_GRPC_PHP_GRPC_CHANNEL_H_ */
79