abies Thu Aug 14 06:55:02 2003 EDT
Modified files:
/php-src/ext/interbase php_interbase.h interbase.c
Log:
Added ibase_wait_event()
Index: php-src/ext/interbase/php_interbase.h
diff -u php-src/ext/interbase/php_interbase.h:1.47
php-src/ext/interbase/php_interbase.h:1.48
--- php-src/ext/interbase/php_interbase.h:1.47 Tue Aug 12 22:19:14 2003
+++ php-src/ext/interbase/php_interbase.h Thu Aug 14 06:55:02 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_interbase.h,v 1.47 2003/08/13 02:19:14 abies Exp $ */
+/* $Id: php_interbase.h,v 1.48 2003/08/14 10:55:02 abies Exp $ */
#ifndef PHP_INTERBASE_H
#define PHP_INTERBASE_H
@@ -89,6 +89,8 @@
#endif
PHP_FUNCTION(ibase_errmsg);
PHP_FUNCTION(ibase_errcode);
+
+PHP_FUNCTION(ibase_wait_event);
#define IBASE_MSGSIZE 256
#define MAX_ERRMSG (IBASE_MSGSIZE*2)
Index: php-src/ext/interbase/interbase.c
diff -u php-src/ext/interbase/interbase.c:1.139 php-src/ext/interbase/interbase.c:1.140
--- php-src/ext/interbase/interbase.c:1.139 Wed Aug 13 06:35:14 2003
+++ php-src/ext/interbase/interbase.c Thu Aug 14 06:55:02 2003
@@ -17,11 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: interbase.c,v 1.139 2003/08/13 10:35:14 sniper Exp $ */
-
-
-/* TODO: Arrays, roles?
-A lot... */
+/* $Id: interbase.c,v 1.140 2003/08/14 10:55:02 abies Exp $ */
/*
Changes:
@@ -139,6 +135,7 @@
PHP_FE(ibase_modify_user, NULL)
PHP_FE(ibase_delete_user, NULL)
#endif
+ PHP_FE(ibase_wait_event, NULL)
{NULL, NULL, NULL}
};
@@ -698,7 +695,7 @@
php_info_print_table_start();
php_info_print_table_row(2, "Interbase Support", "enabled");
- php_info_print_table_row(2, "Revision", "$Revision: 1.139 $");
+ php_info_print_table_row(2, "Revision", "$Revision: 1.140 $");
#ifdef COMPILE_DL_INTERBASE
php_info_print_table_row(2, "Dynamic Module", "Yes");
#endif
@@ -3798,6 +3795,117 @@
}
/* }}} */
#endif /* SQL_DIALECT_V6 */
+
+/* {{{ _php_ibase_event_block() */
+static void _php_ibase_event_block(ibase_db_link *ib_link, unsigned short count, char
**events,
+ unsigned short *l, char **event_buf, char **result_buf)
+{
+ ISC_STATUS dummy_result[20];
+
+ /**
+ * Unfortunately, there's no clean and portable way in C to pass arguments to
+ * a variadic function if you don't know the number of arguments at compile
time.
+ * (And even if there were a way, the Interbase API doesn't provide a version
of
+ * this function that takes a va_list as an argument)
+ *
+ * In this case, the number of arguments is limited to 18 by the underlying
API,
+ * so we can work around it.
+ */
+
+ *l = (unsigned short) isc_event_block(event_buf, result_buf, count, events[0],
+ events[1], events[2], events[3], events[4], events[5], events[6],
events[7],
+ events[8], events[9], events[10], events[11], events[12], events[13],
events[14]);
+
+ /**
+ * Currently, this is the only way to correctly initialize an event buffer.
+ * This is clearly something that should be fixed, cause the semantics of
+ * isc_wait_for_event() indicate that it blocks until an event occurs.
+ * If the Firebird people ever fix this, these lines should be removed,
+ * otherwise, events will have to fire twice before ibase_wait_event() returns.
+ */
+
+ isc_wait_for_event(dummy_result, &ib_link->handle, *l, *event_buf,
*result_buf);
+ isc_event_counts(dummy_result, *l, *event_buf, *result_buf);
+}
+/* }}} */
+
+/* {{{ _php_ibase_event_free() */
+static void _php_ibase_event_free(char *event_buf, char *result_buf)
+{
+ isc_free(event_buf);
+ isc_free(result_buf);
+}
+/* }}} */
+
+/* {{{ proto string ibase_wait_event([resource link,] string event [, string event [,
...]])
+ Waits for any one of the passed Interbase events to be posted by the database, and
returns its name */
+PHP_FUNCTION(ibase_wait_event)
+{
+ zval ***args;
+ ibase_db_link *ib_link;
+ char *event_buffer, *result_buffer, *events[15];
+ unsigned short i = 0, event_count = 0, buffer_size;
+ ISC_STATUS occurred_event[15];
+
+ RESET_ERRMSG;
+
+ /* no more than 15 events */
+ if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 16) {
+ WRONG_PARAM_COUNT;
+ }
+
+ args = (zval ***) safe_emalloc(sizeof(zval **), ZEND_NUM_ARGS(), 0);
+ if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
+ efree(args);
+ RETURN_FALSE;
+ }
+
+ if (Z_TYPE_PP(args[0]) == IS_RESOURCE) {
+
+ ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, args[0], -1, "InterBase
link", le_link, le_plink);
+ i = 1;
+
+ } else if (ZEND_NUM_ARGS() > 15) {
+ efree(args);
+ WRONG_PARAM_COUNT;
+ }
+
+ ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, NULL, IBG(default_link),
"InterBase link", le_link, le_plink);
+
+ for (; i < ZEND_NUM_ARGS(); ++i) {
+ convert_to_string_ex(args[i]);
+ events[event_count++] = Z_STRVAL_PP(args[i]);
+ }
+
+ /* fills the required data structure with information about the events */
+ _php_ibase_event_block(ib_link, event_count, events, &buffer_size,
&event_buffer, &result_buffer);
+
+ /* now block until an event occurs */
+ if (isc_wait_for_event(IB_STATUS, &ib_link->handle, buffer_size, event_buffer,
result_buffer)) {
+ _php_ibase_error(TSRMLS_C);
+ _php_ibase_event_free(event_buffer,result_buffer);
+ efree(args);
+ RETURN_FALSE;
+ }
+
+ /* find out which event occurred */
+ isc_event_counts(occurred_event, buffer_size, event_buffer, result_buffer);
+ for (i = 0; i < event_count; ++i) {
+ if (occurred_event[i]) {
+ char *result = estrdup(events[i]);
+ _php_ibase_event_free(event_buffer,result_buffer);
+ efree(args);
+ RETURN_STRING(result,0);
+ }
+ }
+
+ /* If we reach this line, isc_wait_for_event() did return, but we don't know
+ which event fired. */
+ _php_ibase_event_free(event_buffer,result_buffer);
+ efree(args);
+ RETURN_FALSE;
+}
+/* }}} */
#endif /* HAVE_IBASE */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php