cvs: pear /XMMS php_xmms.h xmms.c

From: Date: Sun, 12 Aug 2001 17:45:53 +0000
Subject: cvs: pear /XMMS php_xmms.h xmms.c
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-483@lists.php.net to get a copy of this message
rasmus Sun Aug 12 13:45:53 2001 EDT Modified files: /pear/XMMS php_xmms.h xmms.c Log: - Add xmms_is_running() - Unfortunately we coredump in libxmms if we try to call an xmms_* function when xmms isn't running, so add a check to each function - You can now pass xmms_playlist() an array of playlist entries to fetch info on

Index: pear/XMMS/php_xmms.h diff -u pear/XMMS/php_xmms.h:1.6 pear/XMMS/php_xmms.h:1.7 --- pear/XMMS/php_xmms.h:1.6 Sun Aug 12 12:18:24 2001 +++ pear/XMMS/php_xmms.h Sun Aug 12 13:45:53 2001 @@ -39,6 +39,7 @@ PHP_MINFO_FUNCTION(xmms); PHP_FUNCTION(xmms_start); +PHP_FUNCTION(xmms_is_running); PHP_FUNCTION(xmms_playlist_length); PHP_FUNCTION(xmms_playlist_pos); PHP_FUNCTION(xmms_playlist); Index: pear/XMMS/xmms.c diff -u pear/XMMS/xmms.c:1.8 pear/XMMS/xmms.c:1.9 --- pear/XMMS/xmms.c:1.8 Sun Aug 12 12:18:24 2001 +++ pear/XMMS/xmms.c Sun Aug 12 13:45:53 2001 @@ -33,6 +33,7 @@ */ function_entry xmms_functions[] = { PHP_FE(xmms_start, NULL) + PHP_FE(xmms_is_running, NULL) PHP_FE(xmms_playlist_length, NULL) PHP_FE(xmms_playlist_pos, NULL) PHP_FE(xmms_playlist, NULL) @@ -189,13 +190,29 @@ } /* }}} */ -/* {{{ proto void xmms_playlist_length(void) +/* {{{ proto bool xmms_is_running(void) + Check if XMMS is running */ +PHP_FUNCTION(xmms_is_running) +{ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) + return; + + RETURN_BOOL(xmms_remote_is_running(XG(session))?1:0); +} +/* }}} */ + +/* {{{ proto int xmms_playlist_length(void) Get the number of songs in the playlist */ PHP_FUNCTION(xmms_playlist_length) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + RETURN_LONG(xmms_remote_get_playlist_length(XG(session))); } /* }}} */ @@ -207,39 +224,69 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + RETURN_LONG(xmms_remote_get_playlist_pos(XG(session))); } /* }}} */ -/* {{{ proto array xmms_playlist([int pos]) - Get full playlist */ +/* {{{ proto array xmms_playlist([mixed pos]) + Get full or partial playlist info */ PHP_FUNCTION(xmms_playlist) { int argc = ZEND_NUM_ARGS(); - long pos; - pval *tmp; - int len, i; + long pos=-1; + pval *tmp_arr, **tmp, *var; + int len, i, single=0; - if (zend_parse_parameters(argc, "|l", &pos) == FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &var) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + + if(argc && Z_TYPE_P(var) != IS_ARRAY) { + convert_to_long(var); + pos = Z_LVAL_P(var); + single=1; + } + array_init(return_value); if(!argc) { len = xmms_remote_get_playlist_length(XG(session)); for(i=0; i<len; i++) { - MAKE_STD_ZVAL(tmp); - array_init(tmp); - add_assoc_string(tmp, "title", xmms_remote_get_playlist_title(XG(session),i), 1); - add_assoc_string(tmp, "file", xmms_remote_get_playlist_file(XG(session),i), 1); - add_assoc_double(tmp, "time", xmms_remote_get_playlist_time(XG(session),i)/1000.0); - zend_hash_index_update(return_value->value.ht, i, &tmp, sizeof(tmp), NULL); + MAKE_STD_ZVAL(tmp_arr); + array_init(tmp_arr); + add_assoc_string(tmp_arr, "title", xmms_remote_get_playlist_title(XG(session),i), 1); + add_assoc_string(tmp_arr, "file", xmms_remote_get_playlist_file(XG(session),i), 1); + add_assoc_double(tmp_arr, "time", xmms_remote_get_playlist_time(XG(session),i)/1000.0); + zend_hash_index_update(Z_ARRVAL_P(return_value), i, &tmp_arr, sizeof(tmp_arr), NULL); } } else { - array_init(return_value); - add_assoc_string(return_value, "title", xmms_remote_get_playlist_title(XG(session),pos), 1); - add_assoc_string(return_value, "file", xmms_remote_get_playlist_file(XG(session),pos), 1); - add_assoc_double(return_value, "time", xmms_remote_get_playlist_time(XG(session),pos)/1000.0); + if(single) { + add_assoc_string(return_value, "title", xmms_remote_get_playlist_title(XG(session),pos), 1); + add_assoc_string(return_value, "file", xmms_remote_get_playlist_file(XG(session),pos), 1); + add_assoc_double(return_value, "time", xmms_remote_get_playlist_time(XG(session),pos)/1000.0); + } else { + /* We were passed an array of playlist positions to get info on */ + zend_hash_internal_pointer_reset(Z_ARRVAL_P(var)); + while (zend_hash_get_current_data(Z_ARRVAL_P(var), (void **)&tmp) == SUCCESS) { + convert_to_long_ex(tmp); + MAKE_STD_ZVAL(tmp_arr); + array_init(tmp_arr); + add_assoc_string(tmp_arr, "title", xmms_remote_get_playlist_title(XG(session),Z_LVAL_PP(tmp)), 1); + add_assoc_string(tmp_arr, "file", xmms_remote_get_playlist_file(XG(session),Z_LVAL_PP(tmp)), 1); + add_assoc_double(tmp_arr, "time", xmms_remote_get_playlist_time(XG(session),Z_LVAL_PP(tmp))/1000.0); + zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(tmp), &tmp_arr, sizeof(tmp_arr), NULL); + zend_hash_move_forward(Z_ARRVAL_P(var)); + } + } } } /* }}} */ @@ -254,6 +301,11 @@ if (zend_parse_parameters(argc, "|l", &pos) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + if(argc) xmms_remote_set_playlist_pos(XG(session), pos); xmms_remote_play(XG(session)); } @@ -266,6 +318,10 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } xmms_remote_stop(XG(session)); } /* }}} */ @@ -277,6 +333,10 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } xmms_remote_pause(XG(session)); } /* }}} */ @@ -288,6 +348,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + xmms_remote_quit(XG(session)); } /* }}} */ @@ -301,6 +366,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + version = xmms_remote_get_version(XG(session)); RETURN_LONG(version); } @@ -313,6 +383,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + xmms_remote_playlist_next(XG(session)); } /* }}} */ @@ -324,6 +399,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + xmms_remote_playlist_prev(XG(session)); } /* }}} */ @@ -337,6 +417,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + playing = xmms_remote_is_playing(XG(session)); paused = xmms_remote_is_paused(XG(session)); @@ -359,6 +444,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + RETURN_BOOL(xmms_remote_is_repeat(XG(session))); } /* }}} */ @@ -374,6 +464,11 @@ if (zend_parse_parameters(argc, "|b", &setting) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + if(argc) { current = xmms_remote_is_repeat(XG(session)); if(current) current=1; @@ -397,6 +492,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + RETURN_BOOL(xmms_remote_is_shuffle(XG(session))); } /* }}} */ @@ -412,6 +512,11 @@ if (zend_parse_parameters(argc, "|b", &setting) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + if(argc) { current = xmms_remote_is_shuffle(XG(session)); if(current) current=1; @@ -436,6 +541,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &songs) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + php_error(E_WARNING, "xmms_add: not yet implemented"); } /* }}} */ @@ -450,6 +560,11 @@ if (zend_parse_parameters(argc, "l", &pos) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + php_error(E_WARNING, "xmms_delete: not yet implemented"); } /* }}} */ @@ -461,6 +576,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + php_error(E_WARNING, "xmms_clear: not yet implemented"); } /* }}} */ @@ -478,6 +598,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + playing = xmms_remote_is_playing(XG(session)); paused = xmms_remote_is_paused(XG(session)); timepos = xmms_remote_get_output_time(XG(session)); @@ -520,6 +645,11 @@ if (zend_parse_parameters(argc, "|ll", &level, &right_level) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + php_error(E_WARNING, "xmms_volume: not yet implemented"); } /* }}} */ @@ -534,6 +664,11 @@ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &url, &url_len) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + xmms_remote_playlist_add_url_string(XG(session), url); } /* }}} */ @@ -549,6 +684,11 @@ if (zend_parse_parameters(argc, "|s", &skin_file, &skin_file_len) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + php_error(E_WARNING, "xmms_skin: not yet implemented"); } /* }}} */ @@ -563,6 +703,11 @@ if (zend_parse_parameters(argc, "|d", &time_pos) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + switch (argc) { case 1: xmms_remote_jump_to_time(XG(session), (int)(time_pos*1000)); @@ -585,6 +730,11 @@ if (zend_parse_parameters(argc, "|b", &setting) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + xmms_remote_main_win_toggle(XG(session),setting); } /* }}} */ @@ -599,6 +749,11 @@ if (zend_parse_parameters(argc, "|b", &setting) == FAILURE) return; + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } + xmms_remote_pl_win_toggle(XG(session),setting); } /* }}} */ @@ -612,6 +767,11 @@ if (zend_parse_parameters(argc, "|b", &setting) == FAILURE) return; + + if(!xmms_remote_is_running(XG(session))) { + php_error(E_WARNING, "XMMS is not running"); + RETURN_FALSE; + } xmms_remote_eq_win_toggle(XG(session),setting); }
« previous php.pear.cvs (#483) next »