|
| 1 | +/* |
| 2 | + * Copyright 2021-present MongoDB, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <php.h> |
| 18 | +#include <Zend/zend_interfaces.h> |
| 19 | + |
| 20 | +#ifdef HAVE_CONFIG_H |
| 21 | +#include "config.h" |
| 22 | +#endif |
| 23 | + |
| 24 | +#include "phongo_compat.h" |
| 25 | +#include "php_phongo.h" |
| 26 | + |
| 27 | +zend_class_entry* php_phongo_serverchangedevent_ce; |
| 28 | + |
| 29 | +/* {{{ proto string ServerChangedEvent::getHost() |
| 30 | + Returns this event's host */ |
| 31 | +static PHP_METHOD(ServerChangedEvent, getHost) |
| 32 | +{ |
| 33 | + php_phongo_serverchangedevent_t* intern = Z_SERVERCHANGEDEVENT_OBJ_P(getThis()); |
| 34 | + |
| 35 | + PHONGO_PARSE_PARAMETERS_NONE(); |
| 36 | + |
| 37 | + RETVAL_STRING(intern->host); |
| 38 | +} /* }}} */ |
| 39 | + |
| 40 | +/* {{{ proto integer ServerChangedEvent::getPort() |
| 41 | + Returns this event's port */ |
| 42 | +static PHP_METHOD(ServerChangedEvent, getPort) |
| 43 | +{ |
| 44 | + php_phongo_serverchangedevent_t* intern = Z_SERVERCHANGEDEVENT_OBJ_P(getThis()); |
| 45 | + |
| 46 | + PHONGO_PARSE_PARAMETERS_NONE(); |
| 47 | + |
| 48 | + RETVAL_LONG(intern->port); |
| 49 | +} /* }}} */ |
| 50 | + |
| 51 | +/* {{{ proto MongoDB\Driver\ServerDescription ServerChangedEvent::getNewDescription() |
| 52 | + Returns this event's new description */ |
| 53 | +static PHP_METHOD(ServerChangedEvent, getNewDescription) |
| 54 | +{ |
| 55 | + mongoc_server_description_t* server_description; |
| 56 | + php_phongo_serverchangedevent_t* intern = Z_SERVERCHANGEDEVENT_OBJ_P(getThis()); |
| 57 | + |
| 58 | + PHONGO_PARSE_PARAMETERS_NONE(); |
| 59 | + |
| 60 | + server_description = mongoc_server_description_new_copy(intern->new_server_description); |
| 61 | + |
| 62 | + phongo_serverdescription_init(return_value, server_description); |
| 63 | +} /* }}} */ |
| 64 | + |
| 65 | +/* {{{ proto MongoDB\Driver\ServerDescription ServerChangedEvent::getPreviousDescription() |
| 66 | + Returns this event's previous description */ |
| 67 | +static PHP_METHOD(ServerChangedEvent, getPreviousDescription) |
| 68 | +{ |
| 69 | + mongoc_server_description_t* server_description; |
| 70 | + php_phongo_serverchangedevent_t* intern = Z_SERVERCHANGEDEVENT_OBJ_P(getThis()); |
| 71 | + |
| 72 | + PHONGO_PARSE_PARAMETERS_NONE(); |
| 73 | + |
| 74 | + server_description = mongoc_server_description_new_copy(intern->old_server_description); |
| 75 | + |
| 76 | + phongo_serverdescription_init(return_value, server_description); |
| 77 | +} /* }}} */ |
| 78 | + |
| 79 | +/* {{{ proto MongoDB\BSON\ObjectId ServerChangedEvent::getTopologyId() |
| 80 | + Returns this event's topology id */ |
| 81 | +static PHP_METHOD(ServerChangedEvent, getTopologyId) |
| 82 | +{ |
| 83 | + php_phongo_objectid_t* topology_id; |
| 84 | + php_phongo_serverchangedevent_t* intern = Z_SERVERCHANGEDEVENT_OBJ_P(getThis()); |
| 85 | + |
| 86 | + PHONGO_PARSE_PARAMETERS_NONE(); |
| 87 | + |
| 88 | + object_init_ex(return_value, php_phongo_objectid_ce); |
| 89 | + |
| 90 | + topology_id = Z_OBJECTID_OBJ_P(return_value); |
| 91 | + bson_oid_to_string(&intern->topology_id, topology_id->oid); |
| 92 | + topology_id->initialized = true; |
| 93 | +} /* }}} */ |
| 94 | + |
| 95 | +/* {{{ MongoDB\Driver\Monitoring\ServerChangedEvent function entries */ |
| 96 | +ZEND_BEGIN_ARG_INFO_EX(ai_ServerChangedEvent_void, 0, 0, 0) |
| 97 | +ZEND_END_ARG_INFO() |
| 98 | + |
| 99 | +static zend_function_entry php_phongo_serverchangedevent_me[] = { |
| 100 | + /* clang-format off */ |
| 101 | + ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_ServerChangedEvent_void, ZEND_ACC_PRIVATE | ZEND_ACC_FINAL) |
| 102 | + PHP_ME(ServerChangedEvent, getHost, ai_ServerChangedEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) |
| 103 | + PHP_ME(ServerChangedEvent, getPort, ai_ServerChangedEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) |
| 104 | + PHP_ME(ServerChangedEvent, getNewDescription, ai_ServerChangedEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) |
| 105 | + PHP_ME(ServerChangedEvent, getPreviousDescription, ai_ServerChangedEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) |
| 106 | + PHP_ME(ServerChangedEvent, getTopologyId, ai_ServerChangedEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) |
| 107 | + ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_ServerChangedEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) |
| 108 | + PHP_FE_END |
| 109 | + /* clang-format on */ |
| 110 | +}; |
| 111 | +/* }}} */ |
| 112 | + |
| 113 | +/* {{{ MongoDB\Driver\Monitoring\ServerChangedEvent object handlers */ |
| 114 | +static zend_object_handlers php_phongo_handler_serverchangedevent; |
| 115 | + |
| 116 | +static void php_phongo_serverchangedevent_free_object(zend_object* object) /* {{{ */ |
| 117 | +{ |
| 118 | + php_phongo_serverchangedevent_t* intern = Z_OBJ_SERVERCHANGEDEVENT(object); |
| 119 | + |
| 120 | + zend_object_std_dtor(&intern->std); |
| 121 | + |
| 122 | + if (intern->new_server_description) { |
| 123 | + mongoc_server_description_destroy(intern->new_server_description); |
| 124 | + } |
| 125 | + |
| 126 | + if (intern->old_server_description) { |
| 127 | + mongoc_server_description_destroy(intern->old_server_description); |
| 128 | + } |
| 129 | +} /* }}} */ |
| 130 | + |
| 131 | +static zend_object* php_phongo_serverchangedevent_create_object(zend_class_entry* class_type) /* {{{ */ |
| 132 | +{ |
| 133 | + php_phongo_serverchangedevent_t* intern = NULL; |
| 134 | + |
| 135 | + intern = PHONGO_ALLOC_OBJECT_T(php_phongo_serverchangedevent_t, class_type); |
| 136 | + |
| 137 | + zend_object_std_init(&intern->std, class_type); |
| 138 | + object_properties_init(&intern->std, class_type); |
| 139 | + |
| 140 | + intern->std.handlers = &php_phongo_handler_serverchangedevent; |
| 141 | + |
| 142 | + return &intern->std; |
| 143 | +} /* }}} */ |
| 144 | + |
| 145 | +static HashTable* php_phongo_serverchangedevent_get_debug_info(phongo_compat_object_handler_type* object, int* is_temp) /* {{{ */ |
| 146 | +{ |
| 147 | + php_phongo_serverchangedevent_t* intern; |
| 148 | + zval retval = ZVAL_STATIC_INIT; |
| 149 | + char topology_id[25]; |
| 150 | + |
| 151 | + intern = Z_OBJ_SERVERCHANGEDEVENT(PHONGO_COMPAT_GET_OBJ(object)); |
| 152 | + *is_temp = 1; |
| 153 | + array_init_size(&retval, 4); |
| 154 | + |
| 155 | + ADD_ASSOC_STRING(&retval, "host", intern->host); |
| 156 | + ADD_ASSOC_LONG_EX(&retval, "port", intern->port); |
| 157 | + |
| 158 | + bson_oid_to_string(&intern->topology_id, topology_id); |
| 159 | + ADD_ASSOC_STRING(&retval, "topologyId", topology_id); |
| 160 | + |
| 161 | + { |
| 162 | + zval new_server_description; |
| 163 | + php_phongo_server_description_to_zval(&new_server_description, intern->new_server_description); |
| 164 | + ADD_ASSOC_ZVAL_EX(&retval, "newServerDescription", &new_server_description); |
| 165 | + } |
| 166 | + |
| 167 | + { |
| 168 | + zval old_server_description; |
| 169 | + php_phongo_server_description_to_zval(&old_server_description, intern->old_server_description); |
| 170 | + ADD_ASSOC_ZVAL_EX(&retval, "oldServerDescription", &old_server_description); |
| 171 | + } |
| 172 | + |
| 173 | + return Z_ARRVAL(retval); |
| 174 | +} /* }}} */ |
| 175 | +/* }}} */ |
| 176 | + |
| 177 | +void php_phongo_serverchangedevent_init_ce(INIT_FUNC_ARGS) /* {{{ */ |
| 178 | +{ |
| 179 | + zend_class_entry ce; |
| 180 | + (void) type; |
| 181 | + (void) module_number; |
| 182 | + |
| 183 | + INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Monitoring", "ServerChangedEvent", php_phongo_serverchangedevent_me); |
| 184 | + php_phongo_serverchangedevent_ce = zend_register_internal_class(&ce); |
| 185 | + php_phongo_serverchangedevent_ce->create_object = php_phongo_serverchangedevent_create_object; |
| 186 | + PHONGO_CE_FINAL(php_phongo_serverchangedevent_ce); |
| 187 | + PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_serverchangedevent_ce); |
| 188 | + |
| 189 | + memcpy(&php_phongo_handler_serverchangedevent, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); |
| 190 | + php_phongo_handler_serverchangedevent.get_debug_info = php_phongo_serverchangedevent_get_debug_info; |
| 191 | + php_phongo_handler_serverchangedevent.free_obj = php_phongo_serverchangedevent_free_object; |
| 192 | + php_phongo_handler_serverchangedevent.offset = XtOffsetOf(php_phongo_serverchangedevent_t, std); |
| 193 | + |
| 194 | + return; |
| 195 | +} /* }}} */ |
| 196 | + |
| 197 | +/* |
| 198 | + * Local variables: |
| 199 | + * tab-width: 4 |
| 200 | + * c-basic-offset: 4 |
| 201 | + * End: |
| 202 | + * vim600: noet sw=4 ts=4 fdm=marker |
| 203 | + * vim<600: noet sw=4 ts=4 |
| 204 | + */ |
0 commit comments