cvs: pear /XMMS php_xmms.h xmms.c
| From: | Rasmus Lerdorf | Date: | Tue, 14 Aug 2001 07:50:01 +0000 |
| Subject: | cvs: pear /XMMS php_xmms.h xmms.c | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-502@lists.php.net to get a copy of this message | ||
rasmus Tue Aug 14 03:50:01 2001 EDT
Modified files:
/pear/XMMS php_xmms.h xmms.c
Log:
Add an OO interface to be more PEAR'ish
Still have a bit of work to do in the various methods to have them
update relevant properties when they are called.
Index: pear/XMMS/php_xmms.h
diff -u pear/XMMS/php_xmms.h:1.7 pear/XMMS/php_xmms.h:1.8
--- pear/XMMS/php_xmms.h:1.7 Sun Aug 12 13:45:53 2001
+++ pear/XMMS/php_xmms.h Tue Aug 14 03:50:00 2001
@@ -38,7 +38,7 @@
PHP_MSHUTDOWN_FUNCTION(xmms);
PHP_MINFO_FUNCTION(xmms);
-PHP_FUNCTION(xmms_start);
+PHP_NAMED_FUNCTION(php_xmms_start);
PHP_FUNCTION(xmms_is_running);
PHP_FUNCTION(xmms_playlist_length);
PHP_FUNCTION(xmms_playlist_pos);
@@ -66,6 +66,7 @@
PHP_FUNCTION(xmms_main_win);
PHP_FUNCTION(xmms_pl_win);
PHP_FUNCTION(xmms_eq_win);
+PHP_FUNCTION(xmms);
ZEND_BEGIN_MODULE_GLOBALS(xmms)
int session;
Index: pear/XMMS/xmms.c
diff -u pear/XMMS/xmms.c:1.13 pear/XMMS/xmms.c:1.14
--- pear/XMMS/xmms.c:1.13 Mon Aug 13 16:58:30 2001
+++ pear/XMMS/xmms.c Tue Aug 14 03:50:00 2001
@@ -32,7 +32,7 @@
* Every user visible function must have an entry in xmms_functions[].
*/
function_entry xmms_functions[] = {
- PHP_FE(xmms_start, NULL)
+ PHP_STATIC_FE("xmms_start", php_xmms_start, NULL)
PHP_FE(xmms_is_running, NULL)
PHP_FE(xmms_playlist_length, NULL)
PHP_FE(xmms_playlist_pos, NULL)
@@ -60,10 +60,43 @@
PHP_FE(xmms_main_win, NULL)
PHP_FE(xmms_pl_win, NULL)
PHP_FE(xmms_eq_win, NULL)
- {NULL, NULL, NULL} /* Must be the last line in xmms_functions[] */
+ {NULL, NULL, NULL}
};
/* }}} */
+/* An OO interface as well */
+static zend_class_entry *xmms_class_entry_ptr;
+
+static zend_function_entry php_xmms_class_functions[] = {
+ PHP_FE(xmms, NULL)
+ PHP_STATIC_FE("start", php_xmms_start, NULL)
+ PHP_FALIAS(play, xmms_play, NULL)
+ PHP_FALIAS(stop, xmms_stop, NULL)
+ PHP_FALIAS(pause, xmms_pause, NULL)
+ PHP_FALIAS(quit, xmms_quit, NULL)
+ PHP_FALIAS(next, xmms_next, NULL)
+ PHP_FALIAS(prev, xmms_prev, NULL)
+ PHP_FALIAS(playlist_length, xmms_playlist_length, NULL)
+ PHP_FALIAS(playlist_pos, xmms_playlist_pos, NULL)
+ PHP_FALIAS(playlist, xmms_playlist, NULL)
+ PHP_FALIAS(status, xmms_status, NULL)
+ PHP_FALIAS(repeat, xmms_repeat, NULL)
+ PHP_FALIAS(shuffle, xmms_shuffle, NULL)
+ PHP_FALIAS(add, xmms_add, NULL)
+ PHP_FALIAS(delete, xmms_delete, NULL)
+ PHP_FALIAS(clear, xmms_clear, NULL)
+ PHP_FALIAS(current, xmms_current, NULL)
+ PHP_FALIAS(volume, xmms_volume, NULL)
+ PHP_FALIAS(url, xmms_url, NULL)
+ PHP_FALIAS(skin, xmms_skin, NULL)
+ PHP_FALIAS(time, xmms_time, NULL)
+ PHP_FALIAS(main_win, xmms_main_win, NULL)
+ PHP_FALIAS(pl_win, xmms_pl_win, NULL)
+ PHP_FALIAS(eq_win, xmms_eq_win, NULL)
+ {NULL, NULL, NULL}
+};
+
+
/* {{{ xmms_module_entry
*/
zend_module_entry xmms_module_entry = {
@@ -98,7 +131,11 @@
*/
PHP_MINIT_FUNCTION(xmms)
{
+ zend_class_entry xmms_class_entry;
+
ZEND_INIT_MODULE_GLOBALS(xmms, php_xmms_init_globals, NULL);
+ INIT_CLASS_ENTRY(xmms_class_entry, "xmms", php_xmms_class_functions);
+ xmms_class_entry_ptr = zend_register_internal_class(&xmms_class_entry TSRMLS_CC);
REGISTER_INI_ENTRIES();
return SUCCESS;
@@ -159,12 +196,14 @@
/* {{{ proto int xmms_start(void)
Start up XMMS if it is not already running */
-PHP_FUNCTION(xmms_start)
+PHP_NAMED_FUNCTION(php_xmms_start)
{
pid_t pid;
char *av[] = { "xmms",NULL };
- if(ZEND_NUM_ARGS() != 0) {
+ /* slight hack here, ignore a single argument which
+ might come in from the xmms constructor */
+ if(ZEND_NUM_ARGS() > 1) {
WRONG_PARAM_COUNT;
}
@@ -798,6 +837,37 @@
}
xmms_remote_eq_win_toggle(XG(session),setting);
+}
+/* }}} */
+
+/* {{{ proto object xmms([bool start])
+ XMMS class */
+PHP_FUNCTION(xmms)
+{
+ int argc = ZEND_NUM_ARGS();
+ zend_bool start = 0;
+
+ if (zend_parse_parameters(argc TSRMLS_CC, "|b", &start) == FAILURE)
+ return;
+
+ if(argc && start) {
+ if(!xmms_remote_is_running(XG(session))) {
+ php_xmms_start(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ }
+ }
+
+ if(xmms_remote_is_running(XG(session))) {
+ add_property_long(this_ptr, "version", xmms_remote_get_version(XG(session)));
+ add_property_bool(this_ptr, "is_running", 1);
+ add_property_bool(this_ptr, "is_repeat", xmms_remote_is_repeat(XG(session)));
+ add_property_bool(this_ptr, "is_shuffle", xmms_remote_is_shuffle(XG(session)));
+ add_property_bool(this_ptr, "shuffle", 1);
+ } else {
+ add_property_long(this_ptr, "version", 0);
+ add_property_bool(this_ptr, "is_running", 0);
+ add_property_bool(this_ptr, "is_repeat", 0);
+ add_property_bool(this_ptr, "is_shuffle", 0);
+ }
}
/* }}} */