Commits

Ruslan Osmanov  committed 0e51ffa

Refact: arginfo
Add: EvPeriodic props: offset, interval; methods: at, again

  • Participants
  • Parent commits a692c0d

Comments (0)

Files changed (4)

 
 /* {{{ ARGINFO */
 
-/* {{{ EvLoop */
-ZEND_BEGIN_ARG_INFO(arginfo_ev__loop_void, 0)
+ZEND_BEGIN_ARG_INFO(arginfo_ev__void, 0)
 ZEND_END_ARG_INFO();
 
+/* {{{ EvLoop */
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_default_loop, 0, 0, 0)
 	ZEND_ARG_INFO(0, flags)
 	ZEND_ARG_INFO(0, callback)
 /* EvLoop }}} */
 
 /* {{{ EvWatcher */
-ZEND_BEGIN_ARG_INFO(arginfo_ev__watcher_void, 0)
-ZEND_END_ARG_INFO();
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_watcher_invoke, 0, 0, 1)
 	ZEND_ARG_INFO(0, revents)
 	ZEND_ARG_INFO(0, repeat)
 ZEND_END_ARG_INFO();
 
-ZEND_BEGIN_ARG_INFO(arginfo_ev__timer_void, 0)
-ZEND_END_ARG_INFO();
 /* }}} */
 
 #if EV_PERIODIC_ENABLE
 const zend_function_entry ev_loop_class_entry_functions[] = {
 	PHP_ME(EvLoop, __construct,          arginfo_ev_default_loop,      ZEND_ACC_PUBLIC  | ZEND_ACC_CTOR)
 	PHP_ME(EvLoop, default_loop,         arginfo_ev_default_loop,      ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-	PHP_ME(EvLoop, loop_fork,            arginfo_ev__loop_void,        ZEND_ACC_PUBLIC)
-	PHP_ME(EvLoop, verify,               arginfo_ev__loop_void,        ZEND_ACC_PUBLIC)
-	PHP_ME(EvLoop, invoke_pending,       arginfo_ev__loop_void,        ZEND_ACC_PUBLIC)
-	PHP_ME(EvLoop, now_update,           arginfo_ev__loop_void,        ZEND_ACC_PUBLIC)
-	PHP_ME(EvLoop, suspend,              arginfo_ev__loop_void,        ZEND_ACC_PUBLIC)
-	PHP_ME(EvLoop, resume,               arginfo_ev__loop_void,        ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, loop_fork,            arginfo_ev__void,             ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, verify,               arginfo_ev__void,             ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, invoke_pending,       arginfo_ev__void,             ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, now_update,           arginfo_ev__void,             ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, suspend,              arginfo_ev__void,             ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, resume,               arginfo_ev__void,             ZEND_ACC_PUBLIC)
 
-	PHP_ME(EvLoop, supported_backends,   arginfo_ev__loop_void,        ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-	PHP_ME(EvLoop, recommended_backends, arginfo_ev__loop_void,        ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-	PHP_ME(EvLoop, embeddable_backends,  arginfo_ev__loop_void,        ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
+	PHP_ME(EvLoop, supported_backends,   arginfo_ev__void,             ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
+	PHP_ME(EvLoop, recommended_backends, arginfo_ev__void,             ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
+	PHP_ME(EvLoop, embeddable_backends,  arginfo_ev__void,             ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
 
 	PHP_ME(EvLoop, sleep,                arginfo_ev_sleep,             ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-	PHP_ME(EvLoop, time,                 arginfo_ev__loop_void,        ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-	PHP_ME(EvLoop, now,                  arginfo_ev__loop_void,        ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, time,                 arginfo_ev__void,             ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
+	PHP_ME(EvLoop, now,                  arginfo_ev__void,             ZEND_ACC_PUBLIC)
 
 	PHP_ME(EvLoop, run,                  arginfo_ev_run,               ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, break,                arginfo_ev_break,             ZEND_ACC_PUBLIC)
 const zend_function_entry ev_watcher_class_entry_functions[] = {
 	PHP_ABSTRACT_ME(EvWatcher, __construct, NULL)
 
-	PHP_ME(EvWatcher, start,        arginfo_ev__watcher_void,        ZEND_ACC_PUBLIC)
-	PHP_ME(EvWatcher, stop,         arginfo_ev__watcher_void,        ZEND_ACC_PUBLIC)
-	PHP_ME(EvWatcher, clear,        arginfo_ev__watcher_void,        ZEND_ACC_PUBLIC)
+	PHP_ME(EvWatcher, start,        arginfo_ev__void,                ZEND_ACC_PUBLIC)
+	PHP_ME(EvWatcher, stop,         arginfo_ev__void,                ZEND_ACC_PUBLIC)
+	PHP_ME(EvWatcher, clear,        arginfo_ev__void,                ZEND_ACC_PUBLIC)
 	PHP_ME(EvWatcher, invoke,       arginfo_ev_watcher_invoke,       ZEND_ACC_PUBLIC)
 	PHP_ME(EvWatcher, feed,         arginfo_ev_watcher_feed,         ZEND_ACC_PUBLIC)
-	PHP_ME(EvWatcher, get_loop,     arginfo_ev__watcher_void,        ZEND_ACC_PUBLIC)
+	PHP_ME(EvWatcher, get_loop,     arginfo_ev__void,                ZEND_ACC_PUBLIC)
 	PHP_ME(EvWatcher, keepalive,    arginfo_ev_watcher_keepalive,    ZEND_ACC_PUBLIC)
 	PHP_ME(EvWatcher, set_callback, arginfo_ev_watcher_set_callback, ZEND_ACC_PUBLIC)
 
 
 /* {{{ 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)
+	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__void,     ZEND_ACC_PUBLIC)
+
 	{ NULL, NULL, NULL }
 };
 /* }}} */
 #if EV_PERIODIC_ENABLE
 /* {{{ 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)
+	PHP_ME(EvPeriodic, __construct, arginfo_ev_periodic,     ZEND_ACC_PUBLIC  | ZEND_ACC_CTOR)
+	PHP_ME(EvPeriodic, set,         arginfo_ev_periodic_set, ZEND_ACC_PUBLIC)
+	PHP_ME(EvPeriodic, again,       arginfo_ev__void,        ZEND_ACC_PUBLIC)
+	PHP_ME(EvPeriodic, at,          arginfo_ev__void,        ZEND_ACC_PUBLIC)
+
 	{ NULL, NULL, NULL }
 };
 /* }}} */
 /* {{{ EvPeriodic */
 PHP_METHOD(EvPeriodic, __construct);
 PHP_METHOD(EvPeriodic, set);
+PHP_METHOD(EvPeriodic, again);
+PHP_METHOD(EvPeriodic, at);
 /* }}} */
 #endif
 
 #if EV_PERIODIC_ENABLE
 /* {{{ EvPeriodic property handlers */
 
+/* {{{ ev_periodic_prop_offset_read */
+static int ev_periodic_prop_offset_read(php_ev_object *obj, zval **retval TSRMLS_DC)
+{
+	PHP_EV_ASSERT(obj->ptr);
+
+	ev_periodic *w = (ev_periodic *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(obj);
+
+	MAKE_STD_ZVAL(*retval);
+	ZVAL_DOUBLE(*retval, w->offset);
+
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ ev_periodic_prop_offset_write */
+static int ev_periodic_prop_offset_write(php_ev_object *obj, zval *value TSRMLS_DC)
+{
+	PHP_EV_ASSERT(obj->ptr);
+
+	ev_periodic *w = (ev_periodic *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(obj);
+
+	w->offset = (ev_tstamp) Z_DVAL_P(value);
+
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ ev_periodic_prop_interval_read */
+static int ev_periodic_prop_interval_read(php_ev_object *obj, zval **retval TSRMLS_DC)
+{
+	PHP_EV_ASSERT(obj->ptr);
+
+	ev_periodic *w = (ev_periodic *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(obj);
+
+	MAKE_STD_ZVAL(*retval);
+	ZVAL_DOUBLE(*retval, w->interval);
+
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ ev_periodic_prop_interval_write*/
+static int ev_periodic_prop_interval_write(php_ev_object *obj, zval *value TSRMLS_DC)
+{
+	double interval;
+
+	PHP_EV_ASSERT(obj->ptr);
+
+	ev_periodic *w = (ev_periodic *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(obj);
+	interval       = (ev_tstamp) Z_DVAL_P(value);
+
+	PHP_EV_CHECK_REPEAT_RET(interval, FAILURE);
+
+	w->interval = interval;
+
+	return SUCCESS;
+}
+/* }}} */
+
 /* }}} */
 #endif
 
 #if EV_PERIODIC_ENABLE
 /* {{{ ev_periodic_property_entries[] */
 const php_ev_property_entry ev_periodic_property_entries[] = {
+	{"offset",   sizeof("offset")   - 1, ev_periodic_prop_offset_read,   ev_periodic_prop_offset_write},
+	{"interval", sizeof("interval") - 1, ev_periodic_prop_interval_read, ev_periodic_prop_interval_write},
     {NULL, 0, NULL, NULL}
 };
 /* }}} */
 
 /* {{{ ev_periodic_property_entry_info[] */
 const zend_property_info ev_periodic_property_entry_info[] = {
+	{ZEND_ACC_PUBLIC, "offset",   sizeof("offset")   - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "interval", sizeof("interval") - 1, -1, 0, NULL, 0, NULL},
 	{0, NULL, 0, -1, 0, NULL, 0, NULL},
 };
 /* }}} */
 }
 /* }}} */
 
+/* {{{ proto void EvPeriodic::again(void) */
+PHP_METHOD(EvPeriodic, again)
+{
+	ev_periodic *periodic_watcher;
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	periodic_watcher = (ev_periodic *) PHP_EV_WATCHER_FETCH_FROM_THIS();
+
+	ev_periodic_again(php_ev_watcher_loop_ptr(periodic_watcher), periodic_watcher);
+	PHP_EV_WATCHER_UNREF(periodic_watcher); 
+}
+/* }}} */
+
+/* {{{ proto double EvPeriodic::at(void) */
+PHP_METHOD(EvPeriodic, at)
+{
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	RETURN_DOUBLE(ev_periodic_at((ev_periodic *)PHP_EV_WATCHER_FETCH_FROM_THIS()));
+}
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4