Commits

Ruslan Osmanov committed 82e0def

Dev: EvStat

Comments (0)

Files changed (8)

 	zend_fcall_info_cache *fcc;
 } php_ev_periodic;
 
+typedef struct php_ev_stat {
+	struct ev_stat  stat;   /* Contains common watcher vars embedded */
+	char *path;
+} php_ev_stat;
+
 #endif /* PHP_EV_EMBED_H */
 /*
  * Local variables:
 	php_ev_object *obj_ptr = (php_ev_object *) object;
 
 	PHP_EV_ASSERT(obj_ptr->ptr);
-	ev_stat *ptr = (ev_stat *) obj_ptr->ptr;
+	ev_stat *ptr          = (ev_stat *) obj_ptr->ptr;
+	php_ev_stat *stat_ptr = (php_ev_stat *) obj_ptr->ptr;
+
+	efree(stat_ptr->path);
 
 	/* Free base class members */
 	php_ev_watcher_free_storage((ev_watcher *) ptr TSRMLS_CC);
 	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();
-
 /* }}} */
 
 #if EV_PERIODIC_ENABLE
 const zend_function_entry ev_stat_class_entry_functions[] = {
 	PHP_ME(EvStat, __construct, arginfo_ev_stat,     ZEND_ACC_PUBLIC  | ZEND_ACC_CTOR)
 	PHP_ME(EvStat, set,         arginfo_ev_stat_set, ZEND_ACC_PUBLIC)
+	PHP_ME(EvStat, attr,        arginfo_ev__void,    ZEND_ACC_PUBLIC)
+	PHP_ME(EvStat, prev,        arginfo_ev__void,    ZEND_ACC_PUBLIC)
 
 	{ NULL, NULL, NULL }
 };
 /* {{{ EvStat */
 PHP_METHOD(EvStat, __construct);
 PHP_METHOD(EvStat, set);
+PHP_METHOD(EvStat, attr);
+PHP_METHOD(EvStat, prev);
 /* }}} */
 #endif
 
 {
 	PHP_EV_ASSERT(obj->ptr);
 
-	ev_stat *stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(obj);
+	/*ev_stat *stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(obj);*/
+	php_ev_stat *stat_ptr = (php_ev_stat *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(obj);
+
 
 	MAKE_STD_ZVAL(*retval);
-	ZVAL_STRING(*retval, stat_watcher->path, 0);
+	ZVAL_STRING(*retval, stat_ptr->path, 1);
 
 	return SUCCESS;
 }
 }
 /* }}} */
 
-/* {{{ ev_stat_prop_attr_read*/
-static int ev_stat_prop_attr_read(php_ev_object *obj, zval **retval TSRMLS_DC)
-{
-	PHP_EV_ASSERT(obj->ptr);
-
-	ev_stat *stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(obj);
-
-	MAKE_STD_ZVAL(*retval);
-	/* TODO: */
-
-	return SUCCESS;
-}
-/* }}} */
-
-/* {{{ ev_stat_prop_previous_read*/
-static int ev_stat_prop_previous_read(php_ev_object *obj, zval **retval TSRMLS_DC)
-{
-	PHP_EV_ASSERT(obj->ptr);
-
-	ev_stat *stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(obj);
-
-	MAKE_STD_ZVAL(*retval);
-	/* TODO: */
-
-	return SUCCESS;
-}
-/* }}} */
-
 /* }}} */
 #endif
 
 const php_ev_property_entry ev_stat_property_entries[] = {
 	{"path",     sizeof("path")     - 1, ev_stat_prop_path_read,     NULL},
 	{"interval", sizeof("interval") - 1, ev_stat_prop_interval_read, NULL},
-	{"attr",     sizeof("attr")     - 1, ev_stat_prop_attr_read,     NULL},
-	{"previous", sizeof("previous") - 1, ev_stat_prop_previous_read, NULL},
     {NULL, 0, NULL, NULL}
 };
 /* }}} */
 const zend_property_info ev_stat_property_entry_info[] = {
 	{ZEND_ACC_PUBLIC, "path",     sizeof("path")     - 1, -1, 0, NULL, 0, NULL},
 	{ZEND_ACC_PUBLIC, "interval", sizeof("interval") - 1, -1, 0, NULL, 0, NULL},
-	{ZEND_ACC_PUBLIC, "attr",     sizeof("attr")     - 1, -1, 0, NULL, 0, NULL},
-	{ZEND_ACC_PUBLIC, "previous", sizeof("previous") - 1, -1, 0, NULL, 0, NULL},
 	{0, NULL, 0, -1, 0, NULL, 0, NULL},
 };
 /* }}} */
 	php_ev_object         *o_self;
 	php_ev_object         *o_loop;
 	ev_periodic           *periodic_watcher;
+	php_ev_periodic       *periodic_ptr;
 
 	zval                  *loop;
 	zval                  *data             = NULL;
 
 	PHP_EV_CHECK_REPEAT(interval);
 
-	php_ev_periodic *periodic_ptr = (php_ev_periodic *) emalloc(sizeof(php_ev_periodic));
+	periodic_ptr = (php_ev_periodic *) emalloc(sizeof(php_ev_periodic));
 	memset(periodic_ptr, 0, sizeof(php_ev_periodic));
 
 	periodic_watcher = &periodic_ptr->periodic;
 */
 #include "watcher.h"
 
+/* {{{ php_ev_stat_to_zval */
+static void php_ev_stat_to_zval(const ev_statdata *st, zval *z)
+{
+	array_init(z);
+
+	add_assoc_long(z, "dev",   st->st_dev);
+	add_assoc_long(z, "ino",   st->st_ino);
+	add_assoc_long(z, "mode",  st->st_mode);
+	add_assoc_long(z, "nlink", st->st_nlink);
+	add_assoc_long(z, "uid",   st->st_uid);
+	add_assoc_long(z, "size",  st->st_size);
+	add_assoc_long(z, "gid",   st->st_gid);
+#ifdef HAVE_ST_RDEV
+	add_assoc_long(z, "rdev", st->st_rdev);
+#else
+	add_assoc_long(z, "rdev", -1);
+#endif
+
+#ifdef HAVE_ST_BLKSIZE
+	add_assoc_long(z, "blksize", st->st_blksize);
+#else
+	add_assoc_long(z, "blksize", -1);
+#endif
+#ifdef HAVE_ST_BLOCKS
+	add_assoc_long(z, "blocks", st->st_blocks);
+#else
+	add_assoc_long(z, "blocks", -1);
+#endif
+
+	add_assoc_long(z, "atime", st->st_atime);
+	add_assoc_long(z, "mtime", st->st_mtime);
+	add_assoc_long(z, "ctime", st->st_ctime);
+}
+/* }}} */
+
+
 /* {{{ proto EvStat::__construct(string path, double interval, EvLoop loop, callable callback[, mixed data = NULL[, int priority = 0]]) */
 PHP_METHOD(EvStat, __construct)
 {
-	char          *path;
-	int            path_len;
-	double         interval;
-	zval          *self;
-	php_ev_object *o_self;
-	php_ev_object *o_loop;
-	ev_stat       *stat_watcher;
+	char                  *path;
+	int                    path_len;
+	double                 interval;
+	zval                  *self;
+	php_ev_object         *o_self;
+	php_ev_object         *o_loop;
+	ev_stat               *stat_watcher;
+	php_ev_stat           *stat_ptr;
 
 	zval                  *loop;
-	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, "pdOf|z!l",
 				&path, &path_len, &interval, &loop, ev_loop_class_entry_ptr, &fci, &fcc,
 		return;
 	}
 
+	stat_ptr = (php_ev_stat *) emalloc(sizeof(php_ev_stat));
+	memset(stat_ptr, 0, sizeof(php_ev_stat));
+	
+	stat_ptr->path = estrdup(path); 
+
+	stat_watcher = &stat_ptr->stat;
+
 	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);
 			PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(o_loop),
 			&fci, &fcc, data, priority TSRMLS_CC);
 
+
 	stat_watcher->type = EV_STAT;
 	
-	ev_stat_set(stat_watcher, path, interval);
+	ev_stat_set(stat_watcher, stat_ptr->path, interval);
 
-	o_self->ptr = (void *) stat_watcher;
+	o_self->ptr = (void *) stat_ptr;
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ proto void EvStat::stat(void) */
-PHP_METHOD(EvStat, stat)
+/* {{{ proto mixed EvStat::attr(void) */
+PHP_METHOD(EvStat, attr)
 {
-	ev_stat *stat_watcher;
+	ev_stat     *stat_watcher;
+	ev_statdata *st;
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_THIS();
+	st           = &stat_watcher->attr;
+
+	if (!st->st_nlink) {
+		errno = ENOENT;
+		RETURN_FALSE;
+	}
+
+	php_ev_stat_to_zval(st, return_value);
+}
+/* }}} */
+
+/* {{{ proto mixed EvStat::prev(void) */
+PHP_METHOD(EvStat, prev)
+{
+	ev_stat     *stat_watcher;
+	ev_statdata *st;
 
 	if (zend_parse_parameters_none() == FAILURE) {
 		return;
 	}
 
 	stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_THIS();
+	st           = &stat_watcher->prev;
+
+	if (!st->st_nlink) {
+		errno = ENOENT;
+		RETURN_FALSE;
+	}
 
-	ev_stat_stat(php_ev_watcher_loop_ptr(stat_watcher), stat_watcher);
+	php_ev_stat_to_zval(st, return_value);
 }
 /* }}} */
 
 
 		PHP_EV_EXIT_LOOP(EV_A);
 	}
+#if 0
 #if EV_STAT_ENABLE
 	/* TODO: php_ev_stat_update()*/
 	else if (revents & EV_STAT /* && php_ev_stat_update(watcher) */) {
 		PHP_EV_EXIT_LOOP(EV_A);
 	}
 #endif
+#endif 
 	else if (ZEND_FCI_INITIALIZED(*pfci)) {
 		/* Setup callback args */
 		key1 = self;
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.