void cli_cache_refresh (cli_infos_t *infos) { xmmsc_result_t *res; res = xmmsc_playlist_current_pos (infos->conn, XMMS_ACTIVE_PLAYLIST); xmmsc_result_wait (res); refresh_currpos (xmmsc_result_get_value (res), infos->cache); xmmsc_result_unref (res); res = xmmsc_playback_current_id (infos->conn); xmmsc_result_wait (res); refresh_currid (xmmsc_result_get_value (res), infos->cache); xmmsc_result_unref (res); res = xmmsc_playback_status (infos->conn); xmmsc_result_wait (res); refresh_playback_status (xmmsc_result_get_value (res), infos->cache); xmmsc_result_unref (res); res = xmmsc_playlist_list_entries (infos->conn, XMMS_ACTIVE_PLAYLIST); xmmsc_result_wait (res); refresh_active_playlist (xmmsc_result_get_value (res), infos->cache); xmmsc_result_unref (res); res = xmmsc_playlist_current_active (infos->conn); xmmsc_result_wait (res); refresh_active_playlist_name (xmmsc_result_get_value (res), infos->cache); xmmsc_result_unref (res); }
void plugin_config_setup (xmmsc_connection_t *con) { xmmsc_result_t* res; xmmsv_t *val; const gchar *err, *name; /* call only once */ g_assert(plugins == NULL ); /* get translation of plugins/configs */ plugin_config_init_translation(); /* get list of available plugins */ res = xmmsc_main_list_plugins (con, XMMS_PLUGIN_TYPE_OUTPUT); /* we havn't entered async xmmsc_mainloop, so it's ok todo sync ops */ xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_t *elem; Plugin *plugin; xmmsv_list_iter_entry (it, &elem); xmmsv_dict_entry_get_string (elem, "shortname", &name); /* not blacklisted */ if ( g_strrstr( PLUGIN_BLACKLIST, name ) != NULL ) continue; plugin = g_slice_new( Plugin ); plugin->name = g_strdup(name); plugin->config = NULL; plugins = g_list_append(plugins, plugin); } } else { g_error ( "Server error: %s", err); } xmmsc_result_unref (res); /* get configuration options */ res = xmmsc_config_list_values (con ); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); xmmsv_dict_foreach( val, plugin_config_setup_parameter, NULL); }
void cmd_playlists_list (xmmsc_connection_t *conn, gint argc, gchar **argv) { const gchar *active_name; xmmsc_result_t *res, *active_res; xmmsv_t *val, *active_val; xmmsv_list_iter_t *it; active_res = xmmsc_playlist_current_active (conn); xmmsc_result_wait (active_res); active_val = xmmsc_result_get_value (active_res); if (xmmsv_is_error (active_val) || !xmmsv_get_string (active_val, &active_name)) { active_name = NULL; } res = xmmsc_playlist_list (conn); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (xmmsv_is_error (val)) { print_error ("%s", xmmsv_get_error_old (val)); } xmmsv_get_list_iter (val, &it); while (xmmsv_list_iter_valid (it)) { xmmsv_t *valstr; const gchar *name; xmmsv_list_iter_entry (it, &valstr); if (!xmmsv_get_string (valstr, &name)) { print_error ("Broken resultset"); } /* Hide all lists that start with _ */ if (name[0] != '_') { if (active_name != NULL && strcmp (active_name, name) == 0) { print_info ("->%s", name); } else { print_info (" %s", name); } } xmmsv_list_iter_next (it); } xmmsc_result_unref (res); xmmsc_result_unref (active_res); }
void list_plugins (cli_infos_t *infos, xmmsc_result_t *res) { const gchar *name, *desc, *err; xmmsv_t *val; val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_t *elem; xmmsv_list_iter_entry (it, &elem); xmmsv_dict_entry_get_string (elem, "shortname", &name); xmmsv_dict_entry_get_string (elem, "description", &desc); g_printf ("%s - %s\n", name, desc); } } else { g_printf (_("Server error: %s\n"), err); } xmmsc_result_unref (res); cli_infos_loop_resume (infos); }
void set_volume (cli_infos_t *infos, gchar *channel, gint volume) { xmmsc_result_t *res; xmmsv_t *val; GList *it, *channels = NULL; if (!channel) { /* get all channels */ res = xmmsc_playback_volume_get (infos->sync); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); xmmsv_dict_foreach (val, dict_keys, &channels); xmmsc_result_unref (res); } else { channels = g_list_prepend (channels, g_strdup (channel)); } /* set volumes for channels in list */ for (it = g_list_first (channels); it != NULL; it = g_list_next (it)) { res = xmmsc_playback_volume_set (infos->sync, it->data, volume); xmmsc_result_wait (res); xmmsc_result_unref (res); /* free channel string */ g_free (it->data); } g_list_free (channels); cli_infos_loop_resume (infos); }
bool setup_udp_handle (xmmsc_result_t *res) { bool ret; xmmsc_vis_udp_t *t; xmmsc_visualization_t *visc; visc = xmmsc_result_visc_get (res); if (!visc) { x_api_error_if (1, "non vis result?", -1); } t = &visc->transport.udp; if (!xmmsc_result_iserror (res)) { xmmsv_t *val; int port; val = xmmsc_result_get_value (res); xmmsv_get_int (val, &port); ret = setup_socket (xmmsc_result_get_connection (res), t, visc->id, port); } else { ret = false; } return ret; }
static gboolean ol_player_xmms2_go_rel (int rel) { ol_log_func (); ol_debugf (" rel:%d\n", rel); if (!ol_player_xmms2_ensure_connection ()) return FALSE; xmmsc_result_t *result = xmmsc_playlist_set_next_rel (connection, rel); xmmsc_result_wait (result); xmmsv_t *return_value = xmmsc_result_get_value (result); if (xmmsv_is_error (return_value)) { ol_debug ("Error on setting playlist next"); return FALSE; } xmmsc_result_unref (result); result = xmmsc_playback_tickle (connection); xmmsc_result_wait (result); if (xmmsc_result_iserror (result)) { ol_debug ("Error on tickle playback"); return FALSE; } xmmsc_result_unref (result); return TRUE; }
void coll_save (cli_infos_t *infos, xmmsv_coll_t *coll, xmmsc_coll_namespace_t ns, gchar *name, gboolean force) { xmmsc_result_t *res; xmmsv_t *val; gboolean save = TRUE; if (!force) { xmmsv_coll_t *exists; res = xmmsc_coll_get (infos->sync, name, ns); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (xmmsv_get_coll (val, &exists)) { g_printf (_("Error: A collection already exists " "with the target name!\n")); save = FALSE; } xmmsc_result_unref (res); } if (save) { res = xmmsc_coll_save (infos->sync, coll, name, ns); xmmsc_result_wait (res); done (res, infos); } else { cli_infos_loop_resume (infos); } }
bool setup_shm_handle (xmmsc_result_t *res) { bool ret; xmmsc_visualization_t *visc; xmmsc_vis_unixshm_t *t; visc = xmmsc_result_visc_get (res); if (!visc) { x_api_error_if (1, "non vis result?", -1); } t = &visc->transport.shm; if (!xmmsc_result_iserror (res)) { xmmsv_t *val; t->size = XMMS_VISPACKET_SHMCOUNT; t->pos = 0; val = xmmsc_result_get_value (res); xmmsv_get_int (val, &t->semid); ret = true; } else { /* didn't work, detach from shm to get it removed later on */ shmdt (t->buffer); ret = false; } /* In either case, mark the shared memory segment to be destroyed. The segment will only actually be destroyed after the last process detaches it. */ shmctl (t->shmid, IPC_RMID, NULL); return ret; }
static gboolean ol_player_xmms2_get_music_length (int *len) { /* ol_log_func (); */ ol_assert_ret (len != NULL, FALSE); if (!ol_player_xmms2_ensure_connection ()) return FALSE; *len = 0; int32_t id = ol_player_xmms2_get_currend_id (); if (id > 0) { xmmsc_result_t *result = xmmsc_medialib_get_info (connection, id); xmmsc_result_wait (result); xmmsv_t *return_value = xmmsc_result_get_value (result); if (xmmsv_is_error (return_value)) { ol_error ("Get music info from XMMS2 failed."); } else { xmmsv_t *dict = xmmsv_propdict_to_dict (return_value, NULL); *len = ol_player_xmms2_get_dict_int (return_value, "duration"); xmmsv_unref (dict); } xmmsc_result_unref (result); } return TRUE; }
static int32_t ol_player_xmms2_get_currend_id () { /* ol_log_func (); */ if (!ol_player_xmms2_ensure_connection ()) return 0; int32_t ret = 0; xmmsc_result_t *result = xmmsc_playback_current_id (connection); xmmsc_result_wait (result); xmmsv_t *return_value = xmmsc_result_get_value (result); if (xmmsv_is_error (return_value)) { ol_error ("Error on getting current id"); ret = 0; } else { if (!xmmsv_get_int (return_value, &ret)) { ol_error ("Get id from result failed"); ret = 0; } } xmmsc_result_unref (result); return ret; }
static void print_collections_list (xmmsc_result_t *res, cli_infos_t *infos, gchar *mark, gboolean all) { const gchar *s, *err; xmmsv_t *val; val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); while (xmmsv_list_iter_valid (it)) { xmmsv_t *entry; xmmsv_list_iter_entry (it, &entry); /* Skip hidden playlists if all is FALSE*/ if (xmmsv_get_string (entry, &s) && ((*s != '_') || all)) { /* Highlight active playlist */ if (mark && strcmp (s, mark) == 0) { g_printf ("* %s\n", s); } else { g_printf (" %s\n", s); } } xmmsv_list_iter_next (it); } } else { g_printf (_("Server error: %s\n"), err); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
void collection_print_config (xmmsc_result_t *res, cli_infos_t *infos, gchar *attrname) { xmmsv_coll_t *coll; gchar *attrvalue; xmmsv_t *val; val = xmmsc_result_get_value (res); if (xmmsv_get_coll (val, &coll)) { if (attrname == NULL) { xmmsc_coll_attribute_foreach (coll, coll_print_attributes, NULL); } else { if (xmmsc_coll_attribute_get (coll, attrname, &attrvalue)) { coll_print_attributes (attrname, attrvalue, NULL); } else { g_printf (_("Invalid attribute!\n")); } } } else { g_printf (_("Invalid collection!\n")); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
void positions_print_list (xmmsc_result_t *res, playlist_positions_t *positions, column_display_t *coldisp, gboolean is_search) { cli_infos_t *infos = column_display_infos_get (coldisp); pl_pos_udata_t udata = { infos, coldisp, NULL, NULL, 0, 0}; xmmsv_t *val; GArray *entries; guint id; const gchar *err; /* FIXME: separate function or merge with list_print_row (lot of if(positions))? */ val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_list_iter_t *it; column_display_prepare (coldisp); if (is_search) { column_display_print_header (coldisp); } entries = g_array_sized_new (FALSE, FALSE, sizeof (guint), xmmsv_list_get_size (val)); for (xmmsv_get_list_iter (val, &it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_t *entry; xmmsv_list_iter_entry (it, &entry); if (xmmsv_get_uint (entry, &id)) { g_array_append_val (entries, id); } } udata.entries = entries; playlist_positions_foreach (positions, pos_print_row_cb, TRUE, &udata); } else { g_printf (_("Server error: %s\n"), err); } if (is_search) { column_display_print_footer (coldisp); } else { g_printf ("\n"); column_display_print_footer_totaltime (coldisp); } column_display_free (coldisp); g_array_free (entries, TRUE); cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
static VALUE c_value_get (VALUE self) { RbResult *res = NULL; xmmsv_t *val; Data_Get_Struct (self, RbResult, res); val = xmmsc_result_get_value (res->real); return extract_value (self, val); }
void remove_cached_list (xmmsc_result_t *matching, cli_infos_t *infos) { /* FIXME: w00t at code copy-paste, please modularize */ xmmsc_result_t *rmres; guint plid, id; gint plsize; GArray *playlist; gint i; const gchar *err; xmmsv_t *val; val = xmmsc_result_get_value (matching); plsize = infos->cache->active_playlist->len; playlist = infos->cache->active_playlist; if (xmmsv_get_error (val, &err) || !xmmsv_is_list (val)) { g_printf (_("Error retrieving the media matching the pattern!\n")); } else { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); /* Loop on the playlist (backward, easier to remove) */ for (i = plsize - 1; i >= 0; i--) { plid = g_array_index (playlist, guint, i); /* Loop on the matched media */ for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_t *entry; xmmsv_list_iter_entry (it, &entry); /* If both match, remove! */ if (xmmsv_get_uint (entry, &id) && plid == id) { rmres = xmmsc_playlist_remove_entry (infos->sync, NULL, i); xmmsc_result_wait (rmres); xmmsc_result_unref (rmres); break; } } } } cli_infos_loop_resume (infos); xmmsc_result_unref (matching); }
static void id_coldisp_print_info (cli_infos_t *infos, column_display_t *coldisp, guint id) { xmmsc_result_t *infores; xmmsv_t *info; infores = xmmsc_medialib_get_info (infos->sync, id); xmmsc_result_wait (infores); info = xmmsv_propdict_to_dict (xmmsc_result_get_value (infores), NULL); column_display_print (coldisp, info); xmmsc_result_unref (infores); xmmsv_unref (info); }
void print_config (cli_infos_t *infos, xmmsc_result_t *res, gchar *confname) { const gchar *confval; xmmsv_t *val; if (confname == NULL) { res = xmmsc_configval_list (infos->sync); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); xmmsv_dict_foreach (val, print_config_entry, NULL); } else { res = xmmsc_configval_get (infos->sync, confname); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); xmmsv_get_string (val, &confval); print_config_entry (confname, val, NULL); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
void configure_playlist (xmmsc_result_t *res, cli_infos_t *infos, gchar *playlist, gint history, gint upcoming, xmmsv_coll_type_t type, gchar *input) { xmmsc_result_t *saveres; xmmsv_coll_t *coll; xmmsv_coll_t *newcoll; xmmsv_t *val; gboolean copied = FALSE; val = xmmsc_result_get_value (res); if (xmmsv_get_coll (val, &coll)) { if (type >= 0 && xmmsv_coll_get_type (coll) != type) { newcoll = coll_copy_retype (coll, type); coll = newcoll; copied = TRUE; } if (history >= 0) { coll_int_attribute_set (coll, "history", history); } if (upcoming >= 0) { coll_int_attribute_set (coll, "upcoming", upcoming); } if (input) { /* Replace previous operand. */ newcoll = coll_make_reference (input, XMMS_COLLECTION_NS_COLLECTIONS); xmmsv_list_clear (xmmsv_coll_operands_get (coll)); xmmsv_coll_add_operand (coll, newcoll); xmmsv_coll_unref (newcoll); } saveres = xmmsc_coll_save (infos->sync, coll, playlist, XMMS_COLLECTION_NS_PLAYLISTS); xmmsc_result_wait (saveres); done (saveres, infos); } else { g_printf (_("Cannot find the playlist to configure!\n")); cli_infos_loop_resume (infos); } if (copied) { xmmsv_coll_unref (coll); } xmmsc_result_unref (res); }
/* Dummy callback that resets the action status as finished. */ void done (xmmsc_result_t *res, cli_infos_t *infos) { const gchar *err; xmmsv_t *val; val = xmmsc_result_get_value (res); if (xmmsv_get_error (val, &err)) { g_printf (_("Server error: %s\n"), err); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
char * emusic_album_cover_path(const char *picture_front) { xmmsc_result_t *res; xmmsv_t *return_value; res = xmmsc_bindata_retrieve( em->conn, picture_front ); xmmsc_result_wait (res); return_value = xmmsc_result_get_value (res); char *tmp_buf = _on_cover_retrieve(return_value, picture_front); //xmmsv_unref (return_value); xmmsc_result_unref (res); return tmp_buf; }
static VALUE c_get_error (VALUE self) { RbResult *res; xmmsv_t *val; const char *error; int ret; Data_Get_Struct (self, RbResult, res); val = xmmsc_result_get_value (res->real); ret = xmmsv_get_error (val, &error); return rb_str_new2 (ret ? error : ""); }
static void id_print_info (xmmsc_result_t *res, guint id, gchar *source) { xmmsv_t *val; const gchar *err; val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_dict_foreach (val, propdict_dump, source); } else { g_printf (_("Server error: %s\n"), err); } xmmsc_result_unref (res); }
void cmd_addpls (xmmsc_connection_t *conn, gint argc, gchar **argv) { gchar *playlist; xmmsc_result_t *res, *res2; xmmsv_t *val; xmmsv_coll_t *coll; gchar *url; if (argc < 3) { print_error ("Supply path to playlist file"); } if (argc == 3) { playlist = NULL; url = format_url (argv[2], G_FILE_TEST_IS_REGULAR); } else { playlist = argv[2]; url = format_url (argv[3], G_FILE_TEST_IS_REGULAR); } res = xmmsc_coll_idlist_from_playlist_file (conn, url); g_free (url); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (xmmsv_is_error (val)) { print_error ("%s", xmmsv_get_error_old (val)); } if (!xmmsv_get_coll (val, &coll)) { print_error ("Couldn't get collection from result!"); } res2 = xmmsc_playlist_add_idlist (conn, playlist, coll); xmmsc_result_wait (res2); if (xmmsc_result_iserror (res2)) { print_error ("%s", xmmsc_result_get_error (res2)); } print_info ("Playlist with %d entries added", xmmsv_coll_idlist_get_size (coll)); xmmsc_result_unref (res); xmmsc_result_unref (res2); }
void add_list (xmmsc_result_t *matching, cli_infos_t *infos, gchar *playlist, gint pos) { /* FIXME: w00t at code copy-paste, please modularize */ xmmsc_result_t *insres; guint id; gint offset; const gchar *err; xmmsv_t *val; val = xmmsc_result_get_value (matching); offset = 0; if (xmmsv_get_error (val, &err) || !xmmsv_is_list (val)) { g_printf (_("Error retrieving the media matching the pattern!\n")); } else { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); /* Loop on the matched media */ for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_t *entry; xmmsv_list_iter_entry (it, &entry); if (xmmsv_get_uint (entry, &id)) { insres = xmmsc_playlist_insert_id (infos->sync, playlist, pos + offset, id); xmmsc_result_wait (insres); xmmsc_result_unref (insres); offset++; } } } cli_infos_loop_resume (infos); xmmsc_result_unref (matching); }
/* Apply operation to an idlist */ void apply_ids (cli_infos_t *infos, xmmsc_result_t *res, idlist_command_t cmd) { const gchar *err; xmmsc_result_t *cmdres; xmmsv_t *val; val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_list_iter_t *it; xmmsv_get_list_iter (val, &it); for (xmmsv_list_iter_first (it); xmmsv_list_iter_valid (it); xmmsv_list_iter_next (it)) { xmmsv_t *entry; guint id; xmmsv_list_iter_entry (it, &entry); if (xmmsv_get_uint (entry, &id)) { switch (cmd) { case IDLIST_CMD_REHASH: cmdres = xmmsc_medialib_rehash (infos->sync, id); break; case IDLIST_CMD_REMOVE: cmdres = xmmsc_medialib_remove_entry (infos->sync, id); break; default: break; } xmmsc_result_wait (cmdres); xmmsc_result_unref (cmdres); } } } else { g_printf (_("Server error: %s\n"), err); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
void cmd_playlist_active (xmmsc_connection_t *conn, gint argc, gchar **argv) { const gchar *active_name; xmmsc_result_t *active_res; xmmsv_t *active_val; active_res = xmmsc_playlist_current_active (conn); xmmsc_result_wait (active_res); active_val = xmmsc_result_get_value (active_res); if (!xmmsv_is_error (active_val) && xmmsv_get_string (active_val, &active_name)) { print_info ("%s",active_name); } xmmsc_result_unref (active_res); }
void print_volume (xmmsc_result_t *res, cli_infos_t *infos, gchar *channel) { xmmsv_t *val; const gchar *err; val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_dict_foreach (val, print_volume_entry, channel); } else { g_printf (_("Server error: %s\n"), err); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
void coll_show (cli_infos_t *infos, xmmsc_result_t *res) { const gchar *err; xmmsv_coll_t *coll; xmmsv_t *val; val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_get_coll (val, &coll); coll_dump (coll, 0); } else { g_printf (_("Server error: %s\n"), err); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
static void print_server_stats (xmmsc_result_t *res) { gint uptime; const gchar *version, *err; xmmsv_t *val; val = xmmsc_result_get_value (res); if (!xmmsv_get_error (val, &err)) { xmmsv_dict_entry_get_string (val, "version", &version); xmmsv_dict_entry_get_int (val, "uptime", &uptime); g_printf ("uptime = %d\n" "version = %s\n", uptime, version); } else { g_printf ("Server error: %s\n", err); } }