static updater_quit_t * updater_connect (updater_t *updater, GMainLoop *ml) { updater_quit_t *quit; gchar *path; g_return_val_if_fail (updater, NULL); g_return_val_if_fail (updater->conn, NULL); g_return_val_if_fail (ml, NULL); path = getenv ("XMMS_PATH"); if (!xmmsc_connect (updater->conn, path)) { g_warning ("Unable to connect to XMMS2"); return NULL; } quit = g_new0 (updater_quit_t, 1); quit->updater = updater; quit->ml = ml; quit->source = xmmsc_mainloop_gmain_init (updater->conn); xmmsc_disconnect_callback_set (updater->conn, updater_quit, quit); return quit; }
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; }
static VALUE c_add_to_glib_mainloop (VALUE self) { RbXmmsClient *xmms = NULL; Data_Get_Struct (self, RbXmmsClient, xmms); xmms->gmain_handle = xmmsc_mainloop_gmain_init (xmms->real); return self; }
int main (int argc, char **argv) { GIOChannel *gio; GMainLoop *ml; gchar *path; gchar *tmp; xmmsc_connection_t *conn; xmmsc_result_t *res; xmonitor_t *mon; gint fd; conn = xmmsc_init ("xmms-medialib-updater"); path = getenv ("XMMS_PATH"); if (!xmmsc_connect (conn, path)) { ERR ("Could not connect to xmms2d %s", xmmsc_get_last_error (conn)); return EXIT_FAILURE; } ml = g_main_loop_new (NULL, FALSE); xmmsc_mainloop_gmain_init (conn); xmmsc_disconnect_callback_set (conn, quit, ml); mon = g_new0 (xmonitor_t, 1); fd = monitor_init (mon); mon->conn = conn; if (fd == -1) { ERR ("Couldn't initalize monitor"); return EXIT_FAILURE; } tmp = getenv("XMMS_DEBUG"); if (!tmp) { g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE | G_LOG_FLAG_RECURSION, message_handler, NULL); } gio = g_io_channel_unix_new (fd); g_io_add_watch (gio, G_IO_IN, s_callback, mon); res = xmmsc_configval_register (conn, "mlibupdater.watch_dirs", ""); xmmsc_result_notifier_set (res, handle_configval, mon); xmmsc_result_unref (res); res = xmmsc_broadcast_configval_changed (conn); xmmsc_result_notifier_set (res, handle_config_changed, mon); xmmsc_result_unref (res); g_main_loop_run (ml); return EXIT_SUCCESS; }
int main (int argc, char **argv) { xmmsc_connection_t *conn; gchar *path; gchar *gp = NULL; gchar **s; gchar **ipcsplit; guint port; int i; printf ("Starting XMMS2 mDNS Agent...\n"); path = getenv ("XMMS_PATH_FULL"); if (!path) { printf ("Sorry you need XMMS_PATH_FULL set\n"); exit (1); } ipcsplit = g_strsplit (path, ";", 0); for (i = 0; ipcsplit[i]; i++) { if (g_ascii_strncasecmp (ipcsplit[i], "tcp://", 6) == 0) { gp = ipcsplit[i]; } } if (!gp) { printf ("Need to have a socket listening to TCP before we can do that!"); exit (1); } s = g_strsplit (gp, ":", 0); if (s && s[2]) { port = strtol (s[2], NULL, 10); } else { port = XMMS_DEFAULT_TCP_PORT; } conn = xmmsc_init ("xmms2-mdns"); if (!conn) { printf ("Could not init xmmsc_connection!\n"); exit (1); } if (!xmmsc_connect (conn, gp)) { printf ("Could not connect to xmms2d: %s\n", xmmsc_get_last_error (conn)); exit (1); } ml = g_main_loop_new (NULL, FALSE); XMMS_CALLBACK_SET (conn, xmmsc_broadcast_quit, handle_quit, ml); xmmsc_disconnect_callback_set (conn, disconnected, NULL); register_service (port); xmmsc_mainloop_gmain_init (conn); g_main_loop_run (ml); DNSServiceRefDeallocate (g_sdref); xmmsc_unref (conn); printf ("XMMS2-mDNS shutting down...\n"); return 0; }
int main (int argc, char **argv) { xmmsc_result_t *res; xmmsv_t *configval; xmmsv_t *val; const char *errmsg; gchar *path = getenv ("XMMS_PATH"); connection = xmmsc_init ("xmms2-vistest"); if (!connection || !xmmsc_connect (connection, path)){ printf ("Couldn't connect to xmms2d: %s\n", xmmsc_get_last_error (connection)); exit (EXIT_FAILURE); } res = xmmsc_visualization_version (connection); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (xmmsv_get_error (val, &errmsg)) { puts (errmsg); exit (EXIT_FAILURE); } else { int32_t version; xmmsv_get_int (val, &version); /* insert the version you need here or instead of complaining, reduce your feature set to fit the version */ if (version < 1) { printf ("The server only supports formats up to version %d (needed is %d)!", version, 1); exit (EXIT_FAILURE); } } xmmsc_result_unref (res); res = xmmsc_visualization_init (connection); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (xmmsv_get_error (val, &errmsg)) { puts (errmsg); exit (EXIT_FAILURE); } vis = xmmsc_visualization_init_handle (res); configval = xmmsv_build_dict (XMMSV_DICT_ENTRY_STR ("type", "peak"), XMMSV_DICT_ENTRY_STR ("stereo", "1"), XMMSV_DICT_END); res = xmmsc_visualization_properties_set (connection, vis, configval); xmmsc_result_wait (res); val = xmmsc_result_get_value (res); if (xmmsv_get_error (val, &errmsg)) { puts (errmsg); exit (EXIT_FAILURE); } xmmsc_result_unref (res); xmmsv_unref (configval); while (!xmmsc_visualization_started (connection, vis)) { res = xmmsc_visualization_start (connection, vis); if (xmmsc_visualization_errored (connection, vis)) { printf ("Couldn't start visualization transfer: %s\n", xmmsc_get_last_error (connection)); exit (EXIT_FAILURE); } if (res) { xmmsc_result_wait (res); xmmsc_visualization_start_handle (connection, res); xmmsc_result_unref (res); } } /* using GTK mainloop */ mainloop = g_main_loop_new (NULL, FALSE); xmmsc_mainloop_gmain_init (connection); g_timeout_add_full (G_PRIORITY_DEFAULT, 20, draw_gtk, NULL, shutdown_gtk); g_main_loop_run (mainloop); /* not using GTK mainloop */ while (xmmsc_visualization_chunk_get (connection, vis, data, 0, 1000) != -1) { draw (); } putchar ('\n'); xmmsc_visualization_shutdown (connection, vis); if (connection) { xmmsc_unref (connection); } return 0; }
int main (int argc, char **argv) { xmmsc_connection_t *conn; GMainLoop *ml; gchar *path; printf ("Starting XMMS2 phone home agent...\n"); path = getenv ("XMMS_PATH"); conn = xmmsc_init ("xmms2-et"); if (!conn) { printf ("Could not init xmmsc_connection!\n"); exit (1); } if (!xmmsc_connect (conn, path)) { printf ("Could not connect to xmms2d: %s\n", xmmsc_get_last_error (conn)); exit (1); } output_plugin = g_strdup ("unknown"); get_systemname (); send_socket = socket (PF_INET, SOCK_DGRAM, 0); ml = g_main_loop_new (NULL, FALSE); memset (&dest_addr, 0, sizeof (dest_addr)); dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons (DEST_PORT); inet_aton (DEST_IP, &dest_addr.sin_addr); start_time = time (NULL); XMMS_CALLBACK_SET (conn, xmmsc_broadcast_playback_current_id, handle_current_id, conn); XMMS_CALLBACK_SET (conn, xmmsc_main_stats, handle_stats, NULL); XMMS_CALLBACK_SET (conn, xmmsc_broadcast_config_value_changed, handle_config, NULL); XMMS_CALLBACK_SET (conn, xmmsc_broadcast_quit, handle_quit, ml); XMMS_CALLBACK_SET (conn, xmmsc_signal_mediainfo_reader_unindexed, handle_mediainfo_reader, NULL); { xmmsc_result_t *res; res = xmmsc_config_get_value (conn, "output.plugin"); xmmsc_result_notifier_set (res, handle_config_val, NULL); xmmsc_result_unref (res); } xmmsc_disconnect_callback_set (conn, disconnected, NULL); xmmsc_mainloop_gmain_init (conn); g_main_loop_run (ml); xmmsc_unref (conn); printf ("XMMS2-ET shutting down...\n"); send_msg ("Clean shutdown", NULL); return 0; }
int main (int argc, char **argv) { /* The mainloop we should use later */ GMainLoop *ml; /* * The first part of this program is * commented on in tut1.c */ xmmsc_connection_t *connection; xmmsc_result_t *result; /* * In an async client we still connect as * normal. Read up on this in earlier * tutorials if you need. */ connection = xmmsc_init ("tutorial6"); 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); } /* * Initialize the mainloop, for more information about GLib mainloop * see the GTK docs. */ ml = g_main_loop_new (NULL, FALSE); /* * The big difference between a sync client and an async client is that the * async client works with callbacks. When you send a command and get an * xmmsc_result_t back you should set up a callback for it and directly * unref it. This means we can't do syncronous operations on this connection. * * In simple cases you can use the XMMS_CALLBACK_SET macro, but in order to * be verbose here I do it all manually. Let's ask for the current id * in an async way instead of the sync way as we did in tut2. */ result = xmmsc_playback_current_id (connection); xmmsc_result_notifier_set (result, my_current_id, ml); xmmsc_result_unref (result); /* * As you see we do it pretty much the same way that we did in tut2, but * instead of being able to access the current id directly (as we would * have if we where blocking) we need to wait until xmms calls our * my_current_id function. This will keep your GUI from hanging while * waiting for xmms2 to answer your command. * * In order to make xmmsclient call your callback functions we need to put * the fd of the connection into the mainloop of our program. For your * convenience the xmmsclient lib ships with automatic integration with * GMainLoop. We just need to link with xmmsclient-glib and do the following * call to make it work. */ xmmsc_mainloop_gmain_init (connection); /* * We are now all set to go. Just run the main loop and watch the magic. */ g_main_loop_run (ml); return EXIT_SUCCESS; }
int main (int argc, char **argv) { /* The mainloop we should use later */ GMainLoop *ml; /* * The first part of this program is * commented on in tut1.c */ xmmsc_connection_t *connection; xmmsc_result_t *result; /* * In an async client we still connect as * normal. Read up on this in earlier * tutorials if you need. */ connection = xmmsc_init ("tutorial6"); 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); } /* * Initialize the mainloop, for more information about GLib mainloop * see the GTK docs. */ ml = g_main_loop_new (NULL, FALSE); /* * We issue two async commands to restart playback. * Since we don't want to set a notifier for those, * we can free the result immediately. */ xmmsc_result_unref (xmmsc_playback_stop (connection)); xmmsc_result_unref (xmmsc_playback_start (connection)); printf ("Playtime: \n"); result = xmmsc_signal_playback_playtime (connection); xmmsc_result_notifier_set (result, my_playtime, ml); xmmsc_result_unref (result); /* * As you see we do it pretty much the same way that we did in tut2, but * instead of being able to access the current id directly (as we would * have if we where blocking) we need to wait until xmms calls our * my_current_id function. This will keep your GUI from hanging while * waiting for xmms2 to answer your command. * * In order to make xmmsclient call your callback functions we need to put * the fd of the connection into the mainloop of our program. For your * convenience the xmmsclient lib ships with automatic integration with * GMainLoop. We just need to link with xmmsclient-glib and do the following * call to make it work. */ xmmsc_mainloop_gmain_init (connection); /* * We are now all set to go. Just run the main loop and watch the magic. */ g_main_loop_run (ml); return EXIT_SUCCESS; }