Commits

Ruslan Osmanov committed b21b0e7

Add: EvIdle

Comments (0)

Files changed (5)

 #if EV_STAT_ENABLE
 zend_class_entry *ev_stat_class_entry_ptr;
 #endif
+#if EV_IDLE_ENABLE
+zend_class_entry *ev_idle_class_entry_ptr;
+#endif
 
 static HashTable classes;
 static HashTable php_ev_properties;
 /* }}} */
 #endif
 
+#if EV_IDLE_ENABLE
+/* {{{ php_ev_idle_free_storage() */
+static void php_ev_idle_free_storage(void *object TSRMLS_DC)
+{
+	php_ev_object *obj_ptr = (php_ev_object *) object;
+
+	PHP_EV_ASSERT(obj_ptr->ptr);
+	ev_idle *ptr = (ev_idle *) 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);
+}
+/* }}} */
+#endif
+
 /* {{{ 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)
 		/* EvStat */
 	 	func_free_storage = php_ev_stat_free_storage;
 #endif
+#if EV_IDLE_ENABLE
+	} else if (instanceof_function(ce, ev_idle_class_entry_ptr TSRMLS_CC)) {
+		/* EvIdle */
+	 	func_free_storage = php_ev_idle_free_storage;
+#endif
 	} else {
 	 	func_free_storage = php_ev_object_free_storage;
 	}
 	/* }}} */
 #endif
 
+#if EV_IDLE_ENABLE
+	/* {{{ EvIdle */
+	PHP_EV_REGISTER_CLASS_ENTRY_EX("EvIdle", ev_idle_class_entry_ptr, ev_idle_class_entry_functions, ev_watcher_class_entry_ptr);
+	ce = ev_idle_class_entry_ptr;
+	zend_hash_add(&classes, ce->name, ce->name_length + 1, &php_ev_watcher_properties, sizeof(php_ev_watcher_properties), NULL);
+	/* }}} */
+#endif
+
 }
 /* }}} */
 
 #if EV_STAT_ENABLE
 # include "stat.c";
 #endif
+#if EV_IDLE_ENABLE
+# include "idle.c";
+#endif
 
 #endif /* HAVE_EV */
 
 /* }}} */
 #endif
 
+#if EV_IDLE_ENABLE
+/* {{{ EvIdle */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ev_idle, 0, 0, 2)
+	ZEND_ARG_INFO(0, loop)
+	ZEND_ARG_INFO(0, callback)
+	ZEND_ARG_INFO(0, data)
+	ZEND_ARG_INFO(0, priority)
+ZEND_END_ARG_INFO();
+/* }}} */
+#endif
+
 /* ARGINFO }}} */
 
 
 /* }}} */
 #endif
 
+#if EV_IDLE_ENABLE
+/* {{{ ev_idle_class_entry_functions */
+const zend_function_entry ev_idle_class_entry_functions[] = {
+	PHP_ME(EvIdle, __construct, arginfo_ev_idle, ZEND_ACC_PUBLIC  | ZEND_ACC_CTOR)
+	{ NULL, NULL, NULL }
+};
+/* }}} */
+#endif
 
 /*
  * Local variables:
 /* }}} */
 #endif
 
+#if EV_IDLE_ENABLE
+/* {{{ EvIdle */
+PHP_METHOD(EvIdle, __construct);
+/* }}} */
+#endif
+
 #endif /* PHP_EV_FE_H */
 
 /* 
+/*
+   +----------------------------------------------------------------------+
+   | 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 EvIdle::__construct(EvLoop loop, callable callback[, mixed data = NULL[, int priority = 0]]) */
+PHP_METHOD(EvIdle, __construct)
+{
+	zval          *self;
+	php_ev_object *o_self;
+	php_ev_object *o_loop;
+	ev_idle      *idle_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, "Of|z!l",
+				&loop, ev_loop_class_entry_ptr, &fci, &fcc,
+				&data, &priority) == FAILURE) {
+		return;
+	}
+
+	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);
+	idle_watcher = (ev_idle *) php_ev_new_watcher(sizeof(ev_idle), self,
+			PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(o_loop),
+			&fci, &fcc, data, priority TSRMLS_CC);
+
+	idle_watcher->type = EV_IDLE;
+
+	o_self->ptr = (void *) idle_watcher;
+}
+/* }}} */
+
+/*
+ * 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_signal_class_entry_functions[];
 extern const zend_function_entry ev_child_class_entry_functions[];
 extern const zend_function_entry ev_stat_class_entry_functions[];
+extern const zend_function_entry ev_idle_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_signal_property_entries[];
 extern const php_ev_property_entry ev_child_property_entries[];
 extern const php_ev_property_entry ev_stat_property_entries[];
+extern const php_ev_property_entry ev_idle_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_signal_property_entry_info[];
 extern const zend_property_info ev_child_property_entry_info[];
 extern const zend_property_info ev_stat_property_entry_info[];
+extern const zend_property_info ev_idle_property_entry_info[];
 
 #endif /* PHP_EV_PRIV_H */
 
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.