Source

pecl-ev / prepare.c

Diff from to

File prepare.c

 #include "watcher.h"
 
 /* {{{ php_ev_prepare_object_ctor */
-void php_ev_prepare_object_ctor(INTERNAL_FUNCTION_PARAMETERS, zval *loop)
+void php_ev_prepare_object_ctor(INTERNAL_FUNCTION_PARAMETERS, zval *loop, zend_bool ctor, zend_bool start)
 {
 	zval                  *self;
 	php_ev_object         *o_self;
 	php_ev_object         *o_loop;
-	ev_prepare            *prepare_watcher;
+	ev_prepare            *w;
 
-	zval                  *data            = NULL;
-	zend_fcall_info        fci             = empty_fcall_info;
-	zend_fcall_info_cache  fcc             = empty_fcall_info_cache;
-	long                   priority        = 0;
+	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, "f|z!l",
 				&fci, &fcc, &data, &priority) == FAILURE) {
 		return;
 	}
 
-	/* If loop is NULL, then we're in __construct() */
-	if (loop) {
-		PHP_EV_INIT_CLASS_OBJECT(return_value, ev_prepare_class_entry_ptr);
-		self = return_value; 
+	if (ctor) {
+		self = getThis();
 	} else {
+		PHP_EV_INIT_CLASS_OBJECT(return_value, ev_io_class_entry_ptr);
+		self = return_value; 
+	}
+
+	if (!loop) {
 		loop = php_ev_default_loop(TSRMLS_C);
-		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);
-	prepare_watcher = (ev_prepare *) php_ev_new_watcher(sizeof(ev_prepare), self,
+	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);
+	w      = (ev_prepare *) php_ev_new_watcher(sizeof(ev_prepare), self,
 			PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(o_loop),
 			&fci, &fcc, data, priority TSRMLS_CC);
 
-	prepare_watcher->type = EV_PREPARE;
+	w->type = EV_PREPARE;
 
-	o_self->ptr = (void *) prepare_watcher;
+	o_self->ptr = (void *) w;
+
+	if (start) {
+		PHP_EV_WATCHER_START(ev_prepare, w);
+	}
 }
 /* }}} */
 
 /* {{{ proto EvPrepare::__construct(callable callback[, mixed data = NULL[, int priority = 0]]) */
 PHP_METHOD(EvPrepare, __construct)
 {
-	php_ev_prepare_object_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL);
+	PHP_EV_WATCHER_CTOR(prepare, NULL);
+}
+/* }}} */
+
+/* {{{ proto EvPrepare::createStopped(callable callback[, mixed data = NULL[, int priority = 0]]) */
+PHP_METHOD(EvPrepare, createStopped)
+{
+	PHP_EV_WATCHER_FACTORY_NS(prepare, NULL);
 }
 /* }}} */