gboolean cli_context_connect (cli_context_t *ctx, gboolean autostart) { gchar *path; xmmsc_result_t *res; /* Open Async connection first */ ctx->conn = xmmsc_init (CLI_CLIENTNAME); if (!ctx->conn) { g_printf (_("Could not init connection!\n")); return FALSE; } path = configuration_get_string (ctx->config, "ipcpath"); if (!xmmsc_connect (ctx->conn, path)) { if (!autostart) { /* Failed to connect, but don't autostart */ xmmsc_unref (ctx->conn); ctx->conn = NULL; return FALSE; } else if (!cli_context_autostart (ctx, path)) { /* Autostart failed, abort now */ if (path) { g_printf (_("Could not connect to server at '%s'!\n"), path); } else { g_printf (_("Could not connect to server at default path!\n")); } xmmsc_unref (ctx->conn); ctx->conn = NULL; return FALSE; } } /* Sync connection */ ctx->sync = xmmsc_init (CLI_CLIENTNAME "-sync"); if (!ctx->sync) { g_printf (_("Could not init sync connection!\n")); return FALSE; } if (!xmmsc_connect (ctx->sync, path)) { if (path) { g_printf (_("Could not connect to server at '%s'!\n"), path); } else { g_printf (_("Could not connect to server at default path!\n")); } xmmsc_unref (ctx->conn); xmmsc_unref (ctx->sync); ctx->conn = NULL; ctx->sync = NULL; return FALSE; } /* Reset the connection state on server quit */ res = xmmsc_broadcast_quit (ctx->conn); xmmsc_disconnect_callback_set (ctx->conn, disconnect_callback, ctx); xmmsc_result_notifier_set (res, &cli_context_disconnect_callback, ctx); xmmsc_result_unref (res); cli_cache_start (ctx->cache, ctx->conn); return TRUE; }
gboolean cli_infos_connect (cli_infos_t *infos, gboolean autostart) { gchar *path; xmmsc_result_t *res; /* Open Async connection first */ infos->conn = xmmsc_init (CLI_CLIENTNAME); if (!infos->conn) { g_printf (_("Could not init connection!\n")); return FALSE; } path = getenv ("XMMS_PATH"); if (!xmmsc_connect (infos->conn, path)) { if (!autostart) { /* Failed to connect, but don't autostart */ xmmsc_unref (infos->conn); infos->conn = NULL; return FALSE; } else if (!cli_infos_autostart (infos, path)) { /* Autostart failed, abort now */ if (path) { g_printf (_("Could not connect to server at '%s'!\n"), path); } else { g_printf (_("Could not connect to server at default path!\n")); } xmmsc_unref (infos->conn); infos->conn = NULL; return FALSE; } } /* Sync connection */ infos->sync = xmmsc_init (CLI_CLIENTNAME "-sync"); if (!infos->sync) { g_printf (_("Could not init sync connection!\n")); return FALSE; } if (!xmmsc_connect (infos->sync, path)) { if (path) { g_printf (_("Could not connect to server at '%s'!\n"), path); } else { g_printf (_("Could not connect to server at default path!\n")); } xmmsc_unref (infos->conn); xmmsc_unref (infos->sync); infos->conn = NULL; infos->sync = NULL; return FALSE; } /* Reset the connection state on server quit */ res = xmmsc_broadcast_quit (infos->conn); xmmsc_result_notifier_set (res, &cli_infos_disconnect_callback, infos); xmmsc_result_unref (res); cli_cache_start (infos); return TRUE; }