pecl-ev / stat.c

Diff from to
 /* }}} */
 
 /* {{{ php_ev_stat_object_ctor */
-void php_ev_stat_object_ctor(INTERNAL_FUNCTION_PARAMETERS, zval *loop)
+void php_ev_stat_object_ctor(INTERNAL_FUNCTION_PARAMETERS, zval *loop, zend_bool ctor, zend_bool start)
 {
 	char                  *path;
 	int                    path_len;
 	zval                  *self         = NULL;
 	php_ev_object         *o_self;
 	php_ev_object         *o_loop;
-	ev_stat               *stat_watcher;
+	ev_stat               *w;
 	php_ev_stat           *stat_ptr;
 
 	zval                  *data         = NULL;
 	zend_fcall_info_cache  fcc          = empty_fcall_info_cache;
 	long                   priority     = 0;
 
-
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pdf|z!l",
 				&path, &path_len, &interval, &fci, &fcc,
 				&data, &priority) == FAILURE) {
 		return;
 	}
 
-	/* If loop is NULL, then we're in __construct() */
-	if (loop) {
+	if (ctor) {
+		self = getThis();
+	} else {
 		PHP_EV_INIT_CLASS_OBJECT(return_value, ev_stat_class_entry_ptr);
-
-		PHP_EV_ASSERT((self == NULL));
 		self = return_value; 
-	} else {
+	}
+
+	if (!loop) {
 		loop = php_ev_default_loop(TSRMLS_C);
-		self = getThis();
 	}
 
 	stat_ptr = (php_ev_stat *) emalloc(sizeof(php_ev_stat));
 	
 	stat_ptr->path = estrndup(path, path_len); 
 
-	stat_watcher = &stat_ptr->stat;
+	w = &stat_ptr->stat;
 
-	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);
+	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);
 
-	php_ev_set_watcher((ev_watcher *)stat_watcher, sizeof(ev_stat), self,
+	php_ev_set_watcher((ev_watcher *)w, sizeof(ev_stat), self,
 			PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(o_loop),
 			&fci, &fcc, data, priority TSRMLS_CC);
 
-	stat_watcher->type = EV_STAT;
+	w->type = EV_STAT;
 	
-	ev_stat_set(stat_watcher, stat_ptr->path, interval);
+	ev_stat_set(w, stat_ptr->path, interval);
 
 	o_self->ptr = (void *) stat_ptr;
+
+	if (start) {
+		PHP_EV_WATCHER_START(ev_stat, w);
+	}
 }
 /* }}} */
 
 /* {{{ proto EvStat::__construct(string path, double interval, callable callback[, mixed data = NULL[, int priority = 0]]) */
 PHP_METHOD(EvStat, __construct)
 {
-	php_ev_stat_object_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL);
+	PHP_EV_WATCHER_CTOR(stat, NULL);
+}
+/* }}} */
+
+/* {{{ proto EvStat::createStopped(string path, double interval, callable callback[, mixed data = NULL[, int priority = 0]]) */
+PHP_METHOD(EvStat, createStopped)
+{
+	PHP_EV_WATCHER_FACTORY_NS(stat, NULL);
 }
 /* }}} */
 
 	char          *path;
 	int            path_len;
 	double         interval;
-	ev_stat       *stat_watcher;
+	ev_stat       *w;
 	php_ev_stat   *stat_ptr;
 	php_ev_object *ev_obj;
 
 		return;
 	}
 
-	stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_THIS();
+	w = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_THIS();
 
 	ev_obj       = (php_ev_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
 	stat_ptr     = (php_ev_stat *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(ev_obj);
-	stat_watcher = (ev_stat *) stat_ptr;
+	w = (ev_stat *) stat_ptr;
 
 	PHP_EV_ASSERT(stat_ptr->path);
 	efree(stat_ptr->path);
 	stat_ptr->path = estrndup(path, path_len);
 
-	PHP_EV_WATCHER_RESET(ev_stat, stat_watcher, (stat_watcher, stat_ptr->path, interval));
+	PHP_EV_WATCHER_RESET(ev_stat, w, (w, stat_ptr->path, interval));
 }
 /* }}} */
 
 /* {{{ proto mixed EvStat::attr(void) */
 PHP_METHOD(EvStat, attr)
 {
-	ev_stat     *stat_watcher;
+	ev_stat     *w;
 	ev_statdata *st;
 
 	if (zend_parse_parameters_none() == FAILURE) {
 		return;
 	}
 
-	stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_THIS();
-	st           = &stat_watcher->attr;
+	w  = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_THIS();
+	st = &w->attr;
 
 	if (!st->st_nlink) {
 		errno = ENOENT;
 /* {{{ proto mixed EvStat::prev(void) */
 PHP_METHOD(EvStat, prev)
 {
-	ev_stat     *stat_watcher;
+	ev_stat     *w;
 	ev_statdata *st;
 
 	if (zend_parse_parameters_none() == FAILURE) {
 		return;
 	}
 
-	stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_THIS();
-	st           = &stat_watcher->prev;
+	w  = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_THIS();
+	st = &w->prev;
 
 	if (!st->st_nlink) {
 		errno = ENOENT;
 PHP_METHOD(EvStat, stat)
 {
 	php_ev_object *ev_obj;
-	ev_stat       *stat_watcher;
+	ev_stat       *w;
 	ev_statdata   *st;
 
 	if (zend_parse_parameters_none() == FAILURE) {
 		return;
 	}
 
-	ev_obj       = (php_ev_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
-	stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(ev_obj);
+	ev_obj = (php_ev_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
+	w      = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(ev_obj);
 
-	st = &stat_watcher->attr;
+	st = &w->attr;
 
-	ev_stat_stat(PHP_EV_LOOP_FETCH_FROM_OBJECT(ev_obj), stat_watcher);
+	ev_stat_stat(PHP_EV_LOOP_FETCH_FROM_OBJECT(ev_obj), w);
 
 	if (st->st_nlink) {
 		RETURN_TRUE;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.