mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 1 | #include "call.h" |
| 2 | #include "channel.h" |
| 3 | #include "server.h" |
| 4 | #include "completion_queue.h" |
| 5 | #include "event.h" |
| 6 | #include "timeval.h" |
| 7 | #include "credentials.h" |
| 8 | #include "server_credentials.h" |
| 9 | |
| 10 | #ifdef HAVE_CONFIG_H |
| 11 | #include "config.h" |
| 12 | #endif |
| 13 | |
| 14 | #include "php.h" |
| 15 | #include "php_ini.h" |
| 16 | #include "ext/standard/info.h" |
| 17 | #include "php_grpc.h" |
| 18 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 19 | // ZEND_DECLARE_MODULE_GLOBALS(grpc) |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 20 | |
| 21 | /* {{{ grpc_functions[] |
| 22 | * |
| 23 | * Every user visible function must have an entry in grpc_functions[]. |
| 24 | */ |
| 25 | const zend_function_entry grpc_functions[] = { |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 26 | PHP_FE_END /* Must be the last line in grpc_functions[] */ |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 27 | }; |
| 28 | /* }}} */ |
| 29 | |
| 30 | /* {{{ grpc_module_entry |
| 31 | */ |
| 32 | zend_module_entry grpc_module_entry = { |
| 33 | #if ZEND_MODULE_API_NO >= 20010901 |
| 34 | STANDARD_MODULE_HEADER, |
| 35 | #endif |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 36 | "grpc", grpc_functions, PHP_MINIT(grpc), PHP_MSHUTDOWN(grpc), NULL, NULL, |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 37 | PHP_MINFO(grpc), |
| 38 | #if ZEND_MODULE_API_NO >= 20010901 |
| 39 | PHP_GRPC_VERSION, |
| 40 | #endif |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 41 | STANDARD_MODULE_PROPERTIES}; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 42 | /* }}} */ |
| 43 | |
| 44 | #ifdef COMPILE_DL_GRPC |
| 45 | ZEND_GET_MODULE(grpc) |
| 46 | #endif |
| 47 | |
| 48 | /* {{{ PHP_INI |
| 49 | */ |
| 50 | /* Remove comments and fill if you need to have entries in php.ini |
| 51 | PHP_INI_BEGIN() |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 52 | STD_PHP_INI_ENTRY("grpc.global_value", "42", PHP_INI_ALL, OnUpdateLong, |
| 53 | global_value, zend_grpc_globals, grpc_globals) |
| 54 | STD_PHP_INI_ENTRY("grpc.global_string", "foobar", PHP_INI_ALL, |
| 55 | OnUpdateString, global_string, zend_grpc_globals, grpc_globals) |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 56 | PHP_INI_END() |
| 57 | */ |
| 58 | /* }}} */ |
| 59 | |
| 60 | /* {{{ php_grpc_init_globals |
| 61 | */ |
| 62 | /* Uncomment this function if you have INI entries |
| 63 | static void php_grpc_init_globals(zend_grpc_globals *grpc_globals) |
| 64 | { |
| 65 | grpc_globals->global_value = 0; |
| 66 | grpc_globals->global_string = NULL; |
| 67 | } |
| 68 | */ |
| 69 | /* }}} */ |
| 70 | |
| 71 | /* {{{ PHP_MINIT_FUNCTION |
| 72 | */ |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 73 | PHP_MINIT_FUNCTION(grpc) { |
| 74 | /* If you have INI entries, uncomment these lines |
| 75 | REGISTER_INI_ENTRIES(); |
| 76 | */ |
| 77 | /* Register call error constants */ |
| 78 | grpc_init(); |
| 79 | REGISTER_LONG_CONSTANT("Grpc\\CALL_OK", GRPC_CALL_OK, CONST_CS); |
| 80 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR", GRPC_CALL_ERROR, CONST_CS); |
| 81 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_ON_SERVER", |
| 82 | GRPC_CALL_ERROR_NOT_ON_SERVER, CONST_CS); |
| 83 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_ON_CLIENT", |
| 84 | GRPC_CALL_ERROR_NOT_ON_CLIENT, CONST_CS); |
| 85 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_ALREADY_INVOKED", |
| 86 | GRPC_CALL_ERROR_ALREADY_INVOKED, CONST_CS); |
| 87 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_INVOKED", |
| 88 | GRPC_CALL_ERROR_NOT_INVOKED, CONST_CS); |
| 89 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_ALREADY_FINISHED", |
| 90 | GRPC_CALL_ERROR_ALREADY_FINISHED, CONST_CS); |
| 91 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_TOO_MANY_OPERATIONS", |
| 92 | GRPC_CALL_ERROR_TOO_MANY_OPERATIONS, CONST_CS); |
| 93 | REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_INVALID_FLAGS", |
| 94 | GRPC_CALL_ERROR_INVALID_FLAGS, CONST_CS); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 95 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 96 | /* Register op error constants */ |
| 97 | REGISTER_LONG_CONSTANT("Grpc\\OP_OK", GRPC_OP_OK, CONST_CS); |
| 98 | REGISTER_LONG_CONSTANT("Grpc\\OP_ERROR", GRPC_OP_ERROR, CONST_CS); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 99 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 100 | /* Register flag constants */ |
| 101 | REGISTER_LONG_CONSTANT("Grpc\\WRITE_BUFFER_HINT", GRPC_WRITE_BUFFER_HINT, |
| 102 | CONST_CS); |
| 103 | REGISTER_LONG_CONSTANT("Grpc\\WRITE_NO_COMPRESS", GRPC_WRITE_NO_COMPRESS, |
| 104 | CONST_CS); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 105 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 106 | /* Register completion type constants */ |
| 107 | REGISTER_LONG_CONSTANT("Grpc\\QUEUE_SHUTDOWN", GRPC_QUEUE_SHUTDOWN, CONST_CS); |
| 108 | REGISTER_LONG_CONSTANT("Grpc\\READ", GRPC_READ, CONST_CS); |
| 109 | REGISTER_LONG_CONSTANT("Grpc\\INVOKE_ACCEPTED", GRPC_INVOKE_ACCEPTED, |
| 110 | CONST_CS); |
| 111 | REGISTER_LONG_CONSTANT("Grpc\\WRITE_ACCEPTED", GRPC_WRITE_ACCEPTED, CONST_CS); |
| 112 | REGISTER_LONG_CONSTANT("Grpc\\FINISH_ACCEPTED", GRPC_FINISH_ACCEPTED, |
| 113 | CONST_CS); |
| 114 | REGISTER_LONG_CONSTANT("Grpc\\CLIENT_METADATA_READ", |
| 115 | GRPC_CLIENT_METADATA_READ, CONST_CS); |
| 116 | REGISTER_LONG_CONSTANT("Grpc\\FINISHED", GRPC_FINISHED, CONST_CS); |
| 117 | REGISTER_LONG_CONSTANT("Grpc\\SERVER_RPC_NEW", GRPC_SERVER_RPC_NEW, CONST_CS); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 118 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 119 | /* Register status constants */ |
| 120 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_OK", GRPC_STATUS_OK, CONST_CS); |
| 121 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_CANCELLED", GRPC_STATUS_CANCELLED, |
| 122 | CONST_CS); |
| 123 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNKNOWN", GRPC_STATUS_UNKNOWN, CONST_CS); |
| 124 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_INVALID_ARGUMENT", |
| 125 | GRPC_STATUS_INVALID_ARGUMENT, CONST_CS); |
| 126 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_DEADLINE_EXCEEDED", |
| 127 | GRPC_STATUS_DEADLINE_EXCEEDED, CONST_CS); |
| 128 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_NOT_FOUND", GRPC_STATUS_NOT_FOUND, |
| 129 | CONST_CS); |
| 130 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_ALREADY_EXISTS", |
| 131 | GRPC_STATUS_ALREADY_EXISTS, CONST_CS); |
| 132 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_PERMISSION_DENIED", |
| 133 | GRPC_STATUS_PERMISSION_DENIED, CONST_CS); |
| 134 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNAUTHENTICATED", |
| 135 | GRPC_STATUS_UNAUTHENTICATED, CONST_CS); |
| 136 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_RESOURCE_EXHAUSTED", |
| 137 | GRPC_STATUS_RESOURCE_EXHAUSTED, CONST_CS); |
| 138 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_FAILED_PRECONDITION", |
| 139 | GRPC_STATUS_FAILED_PRECONDITION, CONST_CS); |
| 140 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_ABORTED", GRPC_STATUS_ABORTED, CONST_CS); |
| 141 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_OUT_OF_RANGE", GRPC_STATUS_OUT_OF_RANGE, |
| 142 | CONST_CS); |
| 143 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNIMPLEMENTED", |
| 144 | GRPC_STATUS_UNIMPLEMENTED, CONST_CS); |
| 145 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_INTERNAL", GRPC_STATUS_INTERNAL, |
| 146 | CONST_CS); |
| 147 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNAVAILABLE", GRPC_STATUS_UNAVAILABLE, |
| 148 | CONST_CS); |
| 149 | REGISTER_LONG_CONSTANT("Grpc\\STATUS_DATA_LOSS", GRPC_STATUS_DATA_LOSS, |
| 150 | CONST_CS); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 151 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 152 | grpc_init_call(TSRMLS_C); |
| 153 | grpc_init_channel(TSRMLS_C); |
| 154 | grpc_init_server(TSRMLS_C); |
| 155 | grpc_init_completion_queue(TSRMLS_C); |
| 156 | grpc_init_timeval(TSRMLS_C); |
| 157 | grpc_init_credentials(TSRMLS_C); |
| 158 | grpc_init_server_credentials(TSRMLS_C); |
| 159 | return SUCCESS; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 160 | } |
| 161 | /* }}} */ |
| 162 | |
| 163 | /* {{{ PHP_MSHUTDOWN_FUNCTION |
| 164 | */ |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 165 | PHP_MSHUTDOWN_FUNCTION(grpc) { |
| 166 | /* uncomment this line if you have INI entries |
| 167 | UNREGISTER_INI_ENTRIES(); |
| 168 | */ |
| 169 | grpc_shutdown_timeval(TSRMLS_C); |
| 170 | grpc_shutdown(); |
| 171 | return SUCCESS; |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 172 | } |
| 173 | /* }}} */ |
| 174 | |
| 175 | /* {{{ PHP_MINFO_FUNCTION |
| 176 | */ |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 177 | PHP_MINFO_FUNCTION(grpc) { |
| 178 | php_info_print_table_start(); |
| 179 | php_info_print_table_header(2, "grpc support", "enabled"); |
| 180 | php_info_print_table_end(); |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 181 | |
Craig Tiller | b5dcec5 | 2015-01-13 11:13:42 -0800 | [diff] [blame] | 182 | /* Remove comments if you have entries in php.ini |
| 183 | DISPLAY_INI_ENTRIES(); |
| 184 | */ |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 185 | } |
| 186 | /* }}} */ |
| 187 | /* The previous line is meant for vim and emacs, so it can correctly fold and |
| 188 | unfold functions in source code. See the corresponding marks just before |
| 189 | function definition, where the functions purpose is also documented. Please |
| 190 | follow this convention for the convenience of others editing your code. |
| 191 | */ |
| 192 | |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 193 | /* |
| 194 | * Local variables: |
| 195 | * tab-width: 4 |
| 196 | * c-basic-offset: 4 |
| 197 | * End: |
| 198 | * vim600: noet sw=4 ts=4 fdm=marker |
| 199 | * vim<600: noet sw=4 ts=4 |
| 200 | */ |