• 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 
20 #ifndef PHP_GRPC_H
21 #define PHP_GRPC_H
22 
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include <stdbool.h>
28 
29 #include <php.h>
30 #include <php_ini.h>
31 #include <ext/standard/info.h>
32 
33 #include <grpc/grpc.h>
34 
35 #include "php7_wrapper.h"
36 #include "version.h"
37 
38 extern zend_module_entry grpc_module_entry;
39 #define phpext_grpc_ptr &grpc_module_entry
40 
41 #ifdef PHP_WIN32
42 #define PHP_GRPC_API __declspec(dllexport)
43 #elif defined(__GNUC__) && __GNUC__ >= 4
44 #define PHP_GRPC_API __attribute__((visibility("default")))
45 #else
46 #define PHP_GRPC_API
47 #endif
48 
49 #ifdef ZTS
50 #include "TSRM.h"
51 #endif
52 
53 /* These are all function declarations */
54 /* Code that runs at module initialization */
55 PHP_MINIT_FUNCTION(grpc);
56 /* Code that runs at module shutdown */
57 PHP_MSHUTDOWN_FUNCTION(grpc);
58 /* Displays information about the module */
59 PHP_MINFO_FUNCTION(grpc);
60 /* Code that runs at request start */
61 PHP_RINIT_FUNCTION(grpc);
62 
63 /*
64   Declare any global variables you may need between the BEGIN
65   and END macros here:
66 */
67 ZEND_BEGIN_MODULE_GLOBALS(grpc)
68   zend_bool initialized;
69 ZEND_END_MODULE_GLOBALS(grpc)
70 
71 /* In every utility function you add that needs to use variables
72    in php_grpc_globals, call TSRMLS_FETCH(); after declaring other
73    variables used by that function, or better yet, pass in TSRMLS_CC
74    after the last function argument and declare your utility function
75    with TSRMLS_DC after the last declared argument.  Always refer to
76    the globals in your function as GRPC_G(variable).  You are
77    encouraged to rename these macros something shorter, see
78    examples in any other php module directory.
79 */
80 
81 #ifdef ZTS
82 #define GRPC_G(v) TSRMG(grpc_globals_id, zend_grpc_globals *, v)
83 #else
84 #define GRPC_G(v) (grpc_globals.v)
85 #endif
86 
87 #define GRPC_STARTUP_FUNCTION(module)  ZEND_MINIT_FUNCTION(grpc_##module)
88 #define GRPC_STARTUP(module)           \
89   ZEND_MODULE_STARTUP_N(grpc_##module)(INIT_FUNC_ARGS_PASSTHRU)
90 
91 #endif /* PHP_GRPC_H */
92