#include "ext/standard/info.h"
#include "php_rpc.h"
+#include "rpc.h"
#include "layer.h"
ZEND_DECLARE_MODULE_GLOBALS(rpc)
+static void rpc_globals_ctor(zend_rpc_globals *rpc_globals TSRMLS_DC);
+static void rpc_instance_dtor(void *pDest);
+static void rpc_handlers_dtor(void *pDest);
static zend_object_value rpc_create_object(zend_class_entry *class_type TSRMLS_DC);
/* object handler */
static int rpc_compare(zval *object1, zval *object2 TSRMLS_DC);
/**/
-ZEND_FUNCTION(rpc_ctor);
+ZEND_FUNCTION(CONSTRUCTOR);
-static int le_rpc;
static zend_object_handlers rpc_handlers = {
rpc_add_ref,
rpc_del_ref,
};
/* }}} */
+static HashTable *instance;
+
#ifdef COMPILE_DL_RPC
ZEND_GET_MODULE(rpc)
#endif
PHP_INI_END()
/* }}} */
-/* {{{ php_rpc_init_globals
- */
-static void php_rpc_init_globals(zend_rpc_globals *rpc_globals)
+static void rpc_globals_ctor(zend_rpc_globals *rpc_globals TSRMLS_DC)
{
+ RPC_G(handle) = 0;
+
+ RPC_G(handlers) = (HashTable *) pemalloc(sizeof(HashTable), TRUE);
+ RPC_G(instance) = (HashTable *) pemalloc(sizeof(HashTable), TRUE);
+
+ zend_hash_init(RPC_G(handlers), 0, NULL, NULL, TRUE);
+ zend_hash_init(RPC_G(instance), 0, NULL, rpc_instance_dtor, TRUE);
}
-/* }}} */
/* {{{ PHP_MINIT_FUNCTION
*/
{
int i;
- ZEND_INIT_MODULE_GLOBALS(rpc, php_rpc_init_globals, NULL);
+ ZEND_INIT_MODULE_GLOBALS(rpc, rpc_globals_ctor, NULL);
REGISTER_INI_ENTRIES();
- RPC_G(handle) = 0;
- ALLOC_HASHTABLE(RPC_G(instance));
- zend_hash_init(RPC_G(instance), 0, NULL, ZVAL_PTR_DTOR, 0);
-
for (i=0; i < (sizeof(handler_entries) / sizeof(rpc_handler_entry)); i++) {
handler_entries[i].rpc_handler_init();
handler_entries[i].ce->create_object = rpc_create_object;
zend_register_internal_class(handler_entries[i].ce TSRMLS_CC);
+ zend_hash_add(RPC_G(handlers), handler_entries[i].name, strlen(handler_entries[i].name), &(handler_entries[i].handlers), sizeof(rpc_object_handlers *), NULL);
}
return SUCCESS;
*/
PHP_MSHUTDOWN_FUNCTION(rpc)
{
+ zend_hash_destroy(RPC_G(handlers));
+ zend_hash_destroy(RPC_G(instance));
+
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
}
/* }}} */
+static void rpc_instance_dtor(void *pDest)
+{
+ rpc_internal **intern;
+
+ intern = (rpc_internal **) pDest;
+
+ /* destruct intern */
+}
+
static zend_object_value rpc_create_object(zend_class_entry *class_type TSRMLS_DC)
{
zend_object_value *zov;
+ rpc_internal *intern;
- zov = (zend_object_value*) emalloc(sizeof(zend_object_value));
+ zov = (zend_object_value*) pemalloc(sizeof(zend_object_value), TRUE);
+ intern = (rpc_internal *) pemalloc(sizeof(rpc_internal), TRUE);
+
zov->handle = RPC_G(handle)++;
zov->handlers = &rpc_handlers;
- zend_hash_index_update_or_next_insert(RPC_G(instance), zov->handle, class_type, sizeof(zend_class_entry),NULL, HASH_ADD);
+ intern->ce = class_type;
+ intern->refcount = 0;
+ intern->data = NULL;
+ zend_hash_find(RPC_G(handlers), class_type->name, class_type->name_length, (void **) &(intern->handlers));
+
+ zend_hash_index_update_or_next_insert(RPC_G(instance), zov->handle, &intern, sizeof(rpc_internal *), NULL, HASH_ADD);
return *zov;
}
+/**/
static void rpc_add_ref(zval *object)
{
+ ZVAL_ADDREF(object);
}
static void rpc_del_ref(zval *object)
{
+ if (ZVAL_REFCOUNT(object) > 0) {
+ ZVAL_DELREF(object);
+ }
+
+ if (ZVAL_REFCOUNT(object) == 0) {
+ rpc_delete(object);
+ }
}
static void rpc_delete(zval *object)
{
+ TSRMLS_FETCH();
+ GET_INTERNAL(intern);
+
+ rpc_instance_dtor(intern);
}
static zend_object_value rpc_clone(zval *object)
{
+// TSRMLS_FETCH();
+// GET_INTERNAL(intern);
+
+ /* FIXME */
+ return object->value.obj;
}
static zval* rpc_read(zval *object, zval *member, int type TSRMLS_DC)
{
+// GET_INTERNAL(intern);
+
+ /* FIXME */
+ return NULL;
}
static void rpc_write(zval *object, zval *member, zval *value TSRMLS_DC)
{
+// GET_INTERNAL(intern);
}
static zval** rpc_get_property(zval *object, zval *member TSRMLS_DC)
{
+// GET_INTERNAL(intern);
+
+ /* FIXME */
+ return NULL;
}
static zval **rpc_get_property_zval(zval *object, zval *member TSRMLS_DC)
{
+// GET_INTERNAL(intern);
+
+ /* FIXME */
+ return NULL;
}
static zval* rpc_get(zval *property TSRMLS_DC)
{
+// GET_INTERNAL(intern);
+
+ /* FIXME */
+ return NULL;
}
static void rpc_set(zval **property, zval *value TSRMLS_DC)
{
+// GET_INTERNAL(intern);
}
static int rpc_has_property(zval *object, zval *member, int check_empty TSRMLS_DC)
{
+// GET_INTERNAL(intern);
+
+ /* FIXME */
+ return FAILURE;
}
static void rpc_unset_property(zval *object, zval *member TSRMLS_DC)
{
+// GET_INTERNAL(intern);
}
static HashTable* rpc_get_properties(zval *object TSRMLS_DC)
{
+// GET_INTERNAL(intern);
+
+ /* FIXME */
+ return NULL;
}
static union _zend_function* rpc_get_method(zval *object, char *method, int method_len TSRMLS_DC)
{
+// GET_INTERNAL(intern);
+
+ /* FIXME */
+ return NULL;
}
static int rpc_call(char *method, INTERNAL_FUNCTION_PARAMETERS)
{
- zval *object = getThis();
+// zval *object = getThis();
+// GET_INTERNAL(intern);
+
+ return SUCCESS;
}
static union _zend_function* rpc_get_constructor(zval *object TSRMLS_DC)
{
- zend_function *rpc_ctor;
+ zend_internal_function *rpc_ctor;
+ GET_INTERNAL(intern);
- rpc_ctor = (zend_function *) emalloc(sizeof(zend_function));
+ rpc_ctor = (zend_internal_function *) emalloc(sizeof(zend_internal_function));
- rpc_ctor->common.function_name = "__construct";
- zend_hash_index_find(RPC_G(instance), object->value.obj.handle, &(rpc_ctor->common.scope));
+ rpc_ctor->type = ZEND_INTERNAL_FUNCTION;
+ rpc_ctor->scope = (*intern)->ce;
+ rpc_ctor->handler = CONSTRUCTOR_FN;
- return rpc_ctor;
+ return (zend_function *) rpc_ctor;
}
static int rpc_get_classname(zval *object, char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC)
{
+// GET_INTERNAL(intern);
+
+ /* FIXME */
+ return FAILURE;
}
static int rpc_compare(zval *object1, zval *object2 TSRMLS_DC)
+{
+ /* FIXME */
+ return FAILURE;
+}
+
+ZEND_FUNCTION(CONSTRUCTOR)
{
}