int main (int argc, char **argv) { GMainLoop *ml; xmmsv_t *operands; xmmsc_result_t *result; xmmsc_connection_t *connection; if (argc != 4) { fprintf (stderr, "Usage: %s service-id op1 op2\n", argv[0]); return EXIT_FAILURE; } /* Connect as usual. */ connection = xmmsc_init ("sumclient"); if (!connection) { fprintf (stderr, "OOM!\n"); exit (EXIT_FAILURE); } if (!xmmsc_connect (connection, getenv ("XMMS_PATH"))) { fprintf (stderr, "Connection failed: %s\n", xmmsc_get_last_error (connection)); exit (EXIT_FAILURE); } ml = g_main_loop_new (NULL, FALSE); /* Build a list of two operands for sumservice (tut9). */ operands = xmmsv_build_list (xmmsv_new_int (atoi(argv[2])), xmmsv_new_int (atoi(argv[3])), XMMSV_LIST_END); /* And send the list to the sumservice. * We use the reply policy of only expecting a single reply, * which means the receiving client will get an error from * the server if it attempts to reply to this message more * than once. */ result = xmmsc_c2c_send (connection, atoi(argv[1]), XMMS_C2C_REPLY_POLICY_SINGLE_REPLY, operands); xmmsv_unref (operands); xmmsc_result_notifier_set (result, print_sum, ml); xmmsc_result_unref (result); xmmsc_mainloop_gmain_init (connection); g_main_loop_run (ml); xmmsc_unref (connection); return EXIT_SUCCESS; }
/** * Returns a random entry from a collection * * @param coll The collection to find a random entry in * @return A random entry from the collection, 0 if the collection is empty */ xmms_medialib_entry_t xmms_medialib_query_random_id (xmms_medialib_session_t *session, xmmsv_t *coll) { xmms_medialib_entry_t ret; xmmsv_t *spec, *res; xmms_error_t err; spec = xmmsv_build_list (XMMSV_LIST_ENTRY_STR ("id"), XMMSV_LIST_END); spec = xmmsv_build_dict (XMMSV_DICT_ENTRY_STR ("type", "metadata"), XMMSV_DICT_ENTRY_STR ("aggregate", "random"), XMMSV_DICT_ENTRY ("get", spec), XMMSV_DICT_END); res = xmms_medialib_query (session, coll, spec, &err); xmmsv_get_int (res, &ret); xmmsv_unref (spec); xmmsv_unref (res); return ret; }