Commits

Ruslan Osmanov  committed 3fd6fe9

Add: EvPeriodic
Fix: EvTimer properties were not destroyed in MSHUTDOWN

  • Participants
  • Parent commits 59a17c7

Comments (0)

Files changed (7)

 zend_class_entry *ev_watcher_class_entry_ptr;
 zend_class_entry *ev_io_class_entry_ptr;
 zend_class_entry *ev_timer_class_entry_ptr;
+zend_class_entry *ev_periodic_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 HashTable php_ev_periodic_properties;
 
 static zend_object_handlers ev_object_handlers;
 
 }
 /* }}} */
 
+/* {{{ php_ev_periodic_free_storage() */
+static void php_ev_periodic_free_storage(void *object TSRMLS_DC)
+{
+	php_ev_object *obj_ptr = (php_ev_object *) object;
+
+	PHP_EV_ASSERT(obj_ptr->ptr);
+	ev_periodic *ptr = (ev_periodic *) 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_timer_class_entry_ptr TSRMLS_CC)) {
 		/* EvTimer */
 	 	func_free_storage = php_ev_timer_free_storage;
+	} else if (instanceof_function(ce, ev_periodic_class_entry_ptr TSRMLS_CC)) {
+		/* EvPeriodic */
+	 	func_free_storage = php_ev_periodic_free_storage;
 	} else {
 	 	func_free_storage = php_ev_object_free_storage;
 	}
 	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);
 	/* }}} */
+
+	/* {{{ EvPeriodic */
+	PHP_EV_REGISTER_CLASS_ENTRY_EX("EvPeriodic", ev_periodic_class_entry_ptr, ev_periodic_class_entry_functions, ev_watcher_class_entry_ptr);
+	ce = ev_periodic_class_entry_ptr;
+	zend_hash_init(&php_ev_periodic_properties, 0, NULL, NULL, 1);
+	PHP_EV_ADD_CLASS_PROPERTIES(&php_ev_periodic_properties, ev_periodic_property_entries);
+	zend_hash_merge(&php_ev_periodic_properties, &php_ev_watcher_properties, NULL, NULL, sizeof(php_ev_prop_handler), 0);
+	PHP_EV_DECL_CLASS_PROPERTIES(ce, ev_periodic_property_entry_info);
+	zend_hash_add(&classes, ce->name, ce->name_length + 1, &php_ev_periodic_properties, sizeof(php_ev_periodic_properties), NULL);
+	/* }}} */
 }
 /* }}} */
 
 	zend_hash_destroy(&php_ev_properties);
 	zend_hash_destroy(&php_ev_watcher_properties);
 	zend_hash_destroy(&php_ev_io_properties);
+	zend_hash_destroy(&php_ev_timer_properties);
+	zend_hash_destroy(&php_ev_periodic_properties);
 	zend_hash_destroy(&classes);
 
 	return SUCCESS;
 #include "loop.c" 
 #include "io.c"
 #include "timer.c"
+#include "periodic.c"
 
 #endif /* HAVE_EV */
 
 ZEND_END_ARG_INFO();
 /* }}} */
 
+/* {{{ EvPeriodic */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_periodic, 0, 0, 4)
+	ZEND_ARG_INFO(0, offset)
+	ZEND_ARG_INFO(0, interval)
+	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_periodic_set, 0, 0, 2)
+	ZEND_ARG_INFO(0, offset)
+	ZEND_ARG_INFO(0, interval)
+ZEND_END_ARG_INFO();
+/* }}} */
+
 /* ARGINFO }}} */
 
 
 };
 /* }}} */
 
+/* {{{ ev_periodic_class_entry_functions */
+const zend_function_entry ev_periodic_class_entry_functions[] = {
+	PHP_ME(EvPeriodic, __construct, arginfo_ev_periodic,       ZEND_ACC_PUBLIC  | ZEND_ACC_CTOR)
+	PHP_ME(EvPeriodic, set,         arginfo_ev_periodic_set,   ZEND_ACC_PUBLIC)
+	{ NULL, NULL, NULL }
+};
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4
 PHP_METHOD(EvTimer, again);
 /* }}} */
 
+/* {{{ EvPeriodic */
+PHP_METHOD(EvPeriodic, __construct);
+PHP_METHOD(EvPeriodic, set);
+/* }}} */
+
 #endif /* PHP_EV_FE_H */
 
 /* 
 };
 /* }}} */
 
+/* {{{ ev_periodic_property_entries[] */
+const php_ev_property_entry ev_periodic_property_entries[] = {
+    {NULL, 0, NULL, NULL}
+};
+/* }}} */
+
+/* {{{ ev_periodic_property_entry_info[] */
+const zend_property_info ev_periodic_property_entry_info[] = {
+	{0, NULL, 0, -1, 0, NULL, 0, NULL},
+};
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 5                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2012 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 3.01 of the PHP license,      |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available through the world-wide-web at the following url:           |
+   | http://www.php.net/license/3_01.txt                                  |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
+   +----------------------------------------------------------------------+
+   | Author: Ruslan Osmanov <osmanov@php.net>                             |
+   +----------------------------------------------------------------------+
+*/
+#include "watcher.h"
+
+/* {{{ proto EvPeriodic::__construct(double offset, double interval, EvLoop loop, callable callback[, mixed data = NULL[, int priority = 0]]) */
+PHP_METHOD(EvPeriodic, __construct)
+{
+	double         offset;
+	double         interval;
+	zval          *self;
+	php_ev_object *o_self;
+	php_ev_object *o_loop;
+	ev_periodic   *periodic_watcher;
+
+	zval                  *loop;
+	zval                  *data       = NULL;
+	zend_fcall_info        fci        = empty_fcall_info;
+	zend_fcall_info_cache  fcc        = empty_fcall_info_cache;
+	long                   priority   = 0;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ddOf|z!l",
+				&offset, &interval, &loop, ev_loop_class_entry_ptr, &fci, &fcc,
+				&data, &priority) == FAILURE) {
+		return;
+	}
+
+	PHP_EV_CHECK_REPEAT(interval);
+
+	self             = getThis();
+	o_self           = (php_ev_object *) zend_object_store_get_object(self TSRMLS_CC);
+	o_loop           = (php_ev_object *) zend_object_store_get_object(loop TSRMLS_CC);
+	periodic_watcher = (ev_periodic *) php_ev_new_watcher(sizeof(ev_periodic), self,
+			PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(o_loop),
+			&fci, &fcc, data, priority TSRMLS_CC);
+
+	periodic_watcher->type = EV_PERIODIC;
+	
+	php_printf("ev_periodic_set(%f, %f)\n", offset, interval);
+	ev_periodic_set(periodic_watcher, offset, interval, 0);
+
+	o_self->ptr = (void *) periodic_watcher;
+}
+/* }}} */
+
+/* {{{ proto void EvPeriodic::set(double offset, double interval) */
+PHP_METHOD(EvPeriodic, set)
+{
+	double       offset;
+	double       interval;
+	ev_periodic *periodic_watcher;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd",
+				&offset, &interval) == FAILURE) {
+		return;
+	}
+
+	PHP_EV_CHECK_REPEAT(interval);
+
+	periodic_watcher = (ev_periodic *) PHP_EV_WATCHER_FETCH_FROM_THIS();
+
+	PHP_EV_WATCHER_RESET(ev_periodic, periodic_watcher, (periodic_watcher, offset, interval, 0));
+}
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 sts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4 sts=4
+ */
 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 zend_function_entry ev_periodic_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 php_ev_property_entry ev_periodic_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[];
+extern const zend_property_info ev_periodic_property_entry_info[];
 
 #endif /* PHP_EV_PRIV_H */
 
 {
 	double      after;
 	double      repeat;
-	php_stream *fd_stream;
 	ev_timer   *timer_watcher;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd",