Commits

Ruslan Osmanov committed 5388371

Fix: 3 required params for EvIo::__construct instead of 4
Add: EvTimer class with it's __construct, set, again methods
Fix: doc comments: callback -> callable
Fix: traversing properties of class parents

  • Participants
  • Parent commits 5405401

Comments (0)

Files changed (11)

 tests/*
 !tests/*.phpt
 
-config.*
+config*
 !config.[m4,w32]
 zend_class_entry *ev_loop_class_entry_ptr;
 zend_class_entry *ev_watcher_class_entry_ptr;
 zend_class_entry *ev_io_class_entry_ptr;
+zend_class_entry *ev_timer_class_entry_ptr;
 
 static HashTable classes;
 static HashTable php_ev_properties;
 static HashTable php_ev_watcher_properties;
 static HashTable php_ev_io_properties;
+static HashTable php_ev_timer_properties;
 
 static zend_object_handlers ev_object_handlers;
 
 	while (zend_hash_get_current_data_ex(props, (void **) &entry, &pos) == SUCCESS) {
 	    zval member;
 	    zval *value;
+
 	    INIT_ZVAL(member);
 	    ZVAL_STRINGL(&member, entry->name, entry->name_len, 0);
+
 	    value = php_ev_read_property(object, &member, BP_VAR_IS, 0 TSRMLS_CC);
 	    if (value != EG(uninitialized_zval_ptr)) {
 	        Z_ADDREF_P(value);
 	        zend_hash_add(retval, entry->name, entry->name_len + 1, &value, sizeof(zval *) , NULL);
 	    }       
+
 	    zend_hash_move_forward_ex(props, &pos);
 	}               
 
 	*is_temp = 1;   
+
 	return retval;
 }               
 #endif    
 }
 /* }}} */
 
+/* {{{ php_ev_timer_free_storage() */
+static void php_ev_timer_free_storage(void *object TSRMLS_DC)
+{
+	php_ev_object *obj_ptr = (php_ev_object *) object;
+
+	PHP_EV_ASSERT(obj_ptr->ptr);
+	ev_timer *ptr = (ev_timer *) obj_ptr->ptr;
+
+	/* Free base class members */
+	php_ev_watcher_free_storage((ev_watcher *) ptr TSRMLS_CC);
+
+	/* Free common Ev object members and the object itself */
+	php_ev_object_free_storage(object TSRMLS_CC);
+}
+/* }}} */
+
 /* {{{ php_ev_register_object 
  * Is called AFTER php_ev_object_new() */
 zend_object_value php_ev_register_object(zend_class_entry *ce, php_ev_object *intern TSRMLS_DC)
 	} else if (instanceof_function(ce, ev_io_class_entry_ptr TSRMLS_CC)) {
 		/* EvIo */
 	 	func_free_storage = php_ev_io_free_storage;
+	} else if (instanceof_function(ce, ev_timer_class_entry_ptr TSRMLS_CC)) {
+		/* EvTimer */
+	 	func_free_storage = php_ev_timer_free_storage;
 	} else {
 	 	func_free_storage = php_ev_object_free_storage;
 	}
 	intern->ptr          = NULL;
 	intern->prop_handler = NULL;
 
+#if 0
 	while (ce_parent) {
 	    if (ce_parent == ev_watcher_class_entry_ptr
 	    		|| ce_parent == ev_loop_class_entry_ptr) {
 	    }
 	    ce_parent = ce_parent->parent;
 	}
+#endif
+	while (ce_parent->type != ZEND_INTERNAL_CLASS && ce_parent->parent != NULL) {
+		ce_parent = ce_parent->parent;
+	}
 	zend_hash_find(&classes, ce_parent->name, ce_parent->name_length + 1,
 	        (void **) &intern->prop_handler);
 
 	ce = ev_io_class_entry_ptr;
 	zend_hash_init(&php_ev_io_properties, 0, NULL, NULL, 1);
 	PHP_EV_ADD_CLASS_PROPERTIES(&php_ev_io_properties, ev_io_property_entries);
+	zend_hash_merge(&php_ev_io_properties, &php_ev_watcher_properties, NULL, NULL, sizeof(php_ev_prop_handler), 0);
 	PHP_EV_DECL_CLASS_PROPERTIES(ce, ev_io_property_entry_info);
 	zend_hash_add(&classes, ce->name, ce->name_length + 1, &php_ev_io_properties, sizeof(php_ev_io_properties), NULL);
 	/* }}} */
+
+	/* {{{ EvTimer */
+	PHP_EV_REGISTER_CLASS_ENTRY_EX("EvTimer", ev_timer_class_entry_ptr, ev_timer_class_entry_functions, ev_watcher_class_entry_ptr);
+	ce = ev_timer_class_entry_ptr;
+	zend_hash_init(&php_ev_timer_properties, 0, NULL, NULL, 1);
+	PHP_EV_ADD_CLASS_PROPERTIES(&php_ev_timer_properties, ev_timer_property_entries);
+	zend_hash_merge(&php_ev_timer_properties, &php_ev_watcher_properties, NULL, NULL, sizeof(php_ev_prop_handler), 0);
+	PHP_EV_DECL_CLASS_PROPERTIES(ce, ev_timer_property_entry_info);
+	zend_hash_add(&classes, ce->name, ce->name_length + 1, &php_ev_timer_properties, sizeof(php_ev_timer_properties), NULL);
+	/* }}} */
 }
 /* }}} */
 
 
 #include "loop.c" 
 #include "io.c"
+#include "timer.c"
 
 #endif /* HAVE_EV */
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_watcher_invoke, 0, 0, 1)
 	ZEND_ARG_INFO(0, revents)
 ZEND_END_ARG_INFO();
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_watcher_feed, 0, 0, 1)
 	ZEND_ARG_INFO(0, revents)
 ZEND_END_ARG_INFO();
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_watcher_keepalive, 0, 0, 0)
 	ZEND_ARG_INFO(0, value)
 ZEND_END_ARG_INFO();
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_watcher_set_callback, 0, 0, 1)
 	ZEND_ARG_INFO(0, callback)
 ZEND_END_ARG_INFO();
 /* EvWatcher }}} */
 
 /* {{{ EvIo */
-ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_io, 0, 0, 3)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_io, 0, 0, 4)
 	ZEND_ARG_INFO(0, fd)
 	ZEND_ARG_INFO(0, events)
 	ZEND_ARG_INFO(0, loop)
 	ZEND_ARG_INFO(0, data)
 	ZEND_ARG_INFO(0, priority)
 ZEND_END_ARG_INFO();
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_io_set, 0, 0, 2)
 	ZEND_ARG_INFO(0, fd)
 	ZEND_ARG_INFO(0, events)
 ZEND_END_ARG_INFO();
 /* EvIo }}} */
+
+/* {{{ EvTimer */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_timer, 0, 0, 4)
+	ZEND_ARG_INFO(0, after)
+	ZEND_ARG_INFO(0, repeat)
+	ZEND_ARG_INFO(0, loop)
+	ZEND_ARG_INFO(0, callback)
+	ZEND_ARG_INFO(0, data)
+	ZEND_ARG_INFO(0, priority)
+ZEND_END_ARG_INFO();
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_timer_set, 0, 0, 2)
+	ZEND_ARG_INFO(0, after)
+	ZEND_ARG_INFO(0, repeat)
+ZEND_END_ARG_INFO();
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_timer_again, 0, 0, 0)
+	ZEND_ARG_INFO(0, after)
+	ZEND_ARG_INFO(0, repeat)
+ZEND_END_ARG_INFO();
+
+ZEND_BEGIN_ARG_INFO(arginfo_ev__timer_void, 0)
+ZEND_END_ARG_INFO();
+/* }}} */
+
 /* ARGINFO }}} */
 
 
 };
 /* }}} */
 
+/* {{{ ev_timer_class_entry_functions */
+const zend_function_entry ev_timer_class_entry_functions[] = {
+	PHP_ME(EvTimer, __construct, arginfo_ev_timer,       ZEND_ACC_PUBLIC  | ZEND_ACC_CTOR)
+	PHP_ME(EvTimer, set,         arginfo_ev_timer_set,   ZEND_ACC_PUBLIC)
+	PHP_ME(EvTimer, again,       arginfo_ev__timer_void, ZEND_ACC_PUBLIC)
+	{ NULL, NULL, NULL }
+};
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4
 PHP_METHOD(EvIo, set);
 /* }}} */
 
+/* {{{ EvTimer */
+PHP_METHOD(EvTimer, __construct);
+PHP_METHOD(EvTimer, set);
+PHP_METHOD(EvTimer, again);
+/* }}} */
+
 #endif /* PHP_EV_FE_H */
 
 /* 
 */
 #include "watcher.h"
 
-/* {{{ proto EvIo::__construct(resource fd, int events, EvLoop loop, callback callback[, mixed data = NULL[, int priority = 0]]) */
+/* {{{ proto EvIo::__construct(resource fd, int events, EvLoop loop, callable callback[, mixed data = NULL[, int priority = 0]]) */
 PHP_METHOD(EvIo, __construct)
 {
 	zval                  *self;
 }
 /* }}} */
 
-/* {{{ proto EvLoop EvLoop::default_loop([int flags = EVLAG_AUTO[, callback callback = NULL[, mixed data = NULL[, double io_collect_interval = 0.[, double timeout_collect_interval = 0.]]]]])
+/* {{{ proto EvLoop EvLoop::default_loop([int flags = EVLAG_AUTO[, callable callback = NULL[, mixed data = NULL[, double io_collect_interval = 0.[, double timeout_collect_interval = 0.]]]]])
 */
 PHP_METHOD(EvLoop, default_loop)
 {
 }
 /* }}} */
 
-/* {{{ proto EvLoop EvLoop::__construct([int flags = EVLAG_AUTO[, callback callback = NULL[, mixed data = NULL[, double io_collect_interval = 0.[, double timeout_collect_interval = 0.]]]]]) */
+/* {{{ proto EvLoop EvLoop::__construct([int flags = EVLAG_AUTO[, callable callback = NULL[, mixed data = NULL[, double io_collect_interval = 0.[, double timeout_collect_interval = 0.]]]]]) */
 PHP_METHOD(EvLoop, __construct) 
 {
 	php_ev_loop_object_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU,
         REPLACE_ZVAL_VALUE(ppz, value, 1);                              \
     } while (0)
 
+#define PHP_EV_CHECK_REPEAT(repeat)                                                  \
+{                                                                                    \
+    if (repeat < 0.) {                                                               \
+        php_error_docref(NULL TSRMLS_CC, E_ERROR, # repeat " value must be >= 0."); \
+        return;                                                                      \
+    }                                                                                \
+}
+
 #endif /* PHP_EV_MACROS_H*/
 
 /*
 
 /* {{{ ev_loop_property_entry_info[] */
 const zend_property_info ev_loop_property_entry_info[] = {
-	{ZEND_ACC_PUBLIC, "data",            sizeof("data") - 1,            -1, 0, NULL, 0, NULL},
-	{ZEND_ACC_PUBLIC, "backend",         sizeof("backend") - 1,         -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "data",            sizeof("data")            - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "backend",         sizeof("backend")         - 1, -1, 0, NULL, 0, NULL},
 	{ZEND_ACC_PUBLIC, "is_default_loop", sizeof("is_default_loop") - 1, -1, 0, NULL, 0, NULL},
-	{ZEND_ACC_PUBLIC, "iteration",       sizeof("iteration") - 1,       -1, 0, NULL, 0, NULL},
-	{ZEND_ACC_PUBLIC, "pending",         sizeof("pending") - 1,         -1, 0, NULL, 0, NULL},
-	{0,                NULL,             0,                             -1, 0, NULL, 0, NULL}
+	{ZEND_ACC_PUBLIC, "iteration",       sizeof("iteration")       - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "pending",         sizeof("pending")         - 1, -1, 0, NULL, 0, NULL},
+	{0, NULL, 0, -1, 0, NULL, 0, NULL}
 };
 /* }}} */
 
 };
 /* }}} */
 
+/* {{{ ev_timer_property_entries[] */
+const php_ev_property_entry ev_timer_property_entries[] = {
+    {NULL, 0, NULL, NULL}
+};
+/* }}} */
+
+/* {{{ ev_timer_property_entry_info[] */
+const zend_property_info ev_timer_property_entry_info[] = {
+	{0, NULL, 0, -1, 0, NULL, 0, NULL},
+};
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4
 #include "types.h"
 #include "macros.h"
 
-
 extern const zend_function_entry ev_functions[];
 extern const zend_function_entry ev_loop_class_entry_functions[];
 extern const zend_function_entry ev_watcher_class_entry_functions[];
 extern const zend_function_entry ev_io_class_entry_functions[];
+extern const zend_function_entry ev_timer_class_entry_functions[];
 
 extern const php_ev_property_entry ev_test_property_entries[];
 extern const php_ev_property_entry ev_loop_property_entries[];
 extern const php_ev_property_entry ev_watcher_property_entries[];
 extern const php_ev_property_entry ev_io_property_entries[];
+extern const php_ev_property_entry ev_timer_property_entries[];
 
 extern const zend_property_info ev_test_property_entry_info[];
 extern const zend_property_info ev_loop_property_entry_info[];
 extern const zend_property_info ev_watcher_property_entry_info[];
 extern const zend_property_info ev_io_property_entry_info[];
+extern const zend_property_info ev_timer_property_entry_info[];
 
 #endif /* PHP_EV_PRIV_H */
 

tests/ev_loop_props.phpt

 $loop       = EvLoop::default_loop();
 $loop->data = "ld";
 $io_watcher = new EvIo(STDIN, EV_READ, $loop, "cb", "data", 2);
-var_dump($io_watcher->getLoop());
+var_dump($io_watcher->get_loop());
 var_dump($io_watcher->priority);
 var_dump($io_watcher->data);
 

tests/ev_watcher_construct_variation.phpt

 	return FALSE;
 }
 
-$fd   = fopen("listen_to_me", "r");
-
 $loop = new EvLoop();
-$io_watcher = new EvIo($fd, EV_READ, $loop, "cb");
+$io_watcher = new EvIo(STDIN, EV_READ, $loop, "cb");
 var_dump($io_watcher);
 
-fclose($fd);
+
 ?>
 --EXPECTF--