allow empdd to start up without connection info
in the case of being started by dbus, no environment variables are available, so making a connection based on the usual MPD_* variables will be impossible; instead, ensure that the daemon can idle peacefully while doing nothing until someone attempts to connect it
This commit is contained in:
parent
627050e55f
commit
5cd08a5df9
|
@ -283,20 +283,21 @@ static void
|
||||||
reconnect(const char *host, int port, const char *pass)
|
reconnect(const char *host, int port, const char *pass)
|
||||||
{
|
{
|
||||||
struct mpd_settings *s = empd->settings;
|
struct mpd_settings *s = empd->settings;
|
||||||
const char *h;
|
const char *h = host;
|
||||||
int p;
|
int p = port;
|
||||||
|
|
||||||
if (pass && (!pass[0]))
|
if (pass && (!pass[0]))
|
||||||
pass = NULL;
|
pass = NULL;
|
||||||
|
|
||||||
h = host && host[0] ? host : mpd_settings_get_host(empd->settings);
|
if (s)
|
||||||
if (h[0] == '/')
|
h = host && host[0] ? host : mpd_settings_get_host(s);
|
||||||
|
if (h && (h[0] == '/'))
|
||||||
p = -1;
|
p = -1;
|
||||||
else
|
else if (s)
|
||||||
p = port == -1 ? (int)mpd_settings_get_port(empd->settings) : port;
|
p = port == -1 ? (int)mpd_settings_get_port(s) : port;
|
||||||
if (host || s)
|
if (host || s)
|
||||||
s = mpd_settings_new(h, p, 3000, NULL, pass);
|
s = mpd_settings_new(h, p, 3000, NULL, pass);
|
||||||
if ((empd->async || empd->svr) &&
|
if ((empd->async || empd->svr) && empd->settings &&
|
||||||
((!host) || (!host[0]) || (!strcmp(host, mpd_settings_get_host(empd->settings)))) &&
|
((!host) || (!host[0]) || (!strcmp(host, mpd_settings_get_host(empd->settings)))) &&
|
||||||
((port == -1) || ((unsigned int)port == mpd_settings_get_port(empd->settings))))
|
((port == -1) || ((unsigned int)port == mpd_settings_get_port(empd->settings))))
|
||||||
{
|
{
|
||||||
|
@ -1263,22 +1264,35 @@ static Eldbus_Message *
|
||||||
_dbus_isconnected_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
|
_dbus_isconnected_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
|
||||||
{
|
{
|
||||||
Eldbus_Message *ret;
|
Eldbus_Message *ret;
|
||||||
|
const char *host = "";
|
||||||
|
unsigned int port = DEFAULT_PORT;
|
||||||
|
|
||||||
ret = eldbus_message_method_return_new(msg);
|
ret = eldbus_message_method_return_new(msg);
|
||||||
eldbus_message_arguments_append(ret, "bsu", empd->connected, mpd_settings_get_host(empd->settings), mpd_settings_get_port(empd->settings));
|
if (empd->settings)
|
||||||
|
{
|
||||||
|
host = mpd_settings_get_host(empd->settings);
|
||||||
|
port = mpd_settings_get_port(empd->settings);
|
||||||
|
}
|
||||||
|
eldbus_message_arguments_append(ret, "bsu", empd->connected, host, port);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eldbus_Message *
|
static Eldbus_Message *
|
||||||
_dbus_connect_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
|
_dbus_connect_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
|
||||||
{
|
{
|
||||||
const char *host, *pass;
|
const char *host = NULL, *pass = NULL;
|
||||||
int port;
|
int port = DEFAULT_PORT;
|
||||||
|
|
||||||
if (!eldbus_message_arguments_get(msg, "sis", &host, &port, &pass))
|
if (!eldbus_message_arguments_get(msg, "sis", &host, &port, &pass))
|
||||||
return eldbus_message_method_return_new(msg);
|
return eldbus_message_method_return_new(msg);
|
||||||
|
|
||||||
reconnect(host, port, pass);
|
if (empd->settings)
|
||||||
|
reconnect(host, port, pass);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
empd->settings = mpd_settings_new(host, port, 3000, NULL, pass);
|
||||||
|
reconnect(NULL, -1, NULL);
|
||||||
|
}
|
||||||
return eldbus_message_method_return_new(msg);
|
return eldbus_message_method_return_new(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1414,7 +1428,6 @@ main(int argc, char *argv[])
|
||||||
else
|
else
|
||||||
settings = mpd_settings_new(argv[1], atoi(argv[2]), 3000, NULL, pass);
|
settings = mpd_settings_new(argv[1], atoi(argv[2]), 3000, NULL, pass);
|
||||||
|
|
||||||
if (!settings) return 1;
|
|
||||||
empd = calloc(1, sizeof(EMPD));
|
empd = calloc(1, sizeof(EMPD));
|
||||||
empd->settings = settings;
|
empd->settings = settings;
|
||||||
ecore_app_no_system_modules();
|
ecore_app_no_system_modules();
|
||||||
|
@ -1439,7 +1452,8 @@ main(int argc, char *argv[])
|
||||||
E_LIST_HANDLER_APPEND(handlers, ECORE_CON_EVENT_SERVER_DEL, del, NULL);
|
E_LIST_HANDLER_APPEND(handlers, ECORE_CON_EVENT_SERVER_DEL, del, NULL);
|
||||||
E_LIST_HANDLER_APPEND(handlers, ECORE_CON_EVENT_SERVER_DATA, data_cb, NULL);
|
E_LIST_HANDLER_APPEND(handlers, ECORE_CON_EVENT_SERVER_DATA, data_cb, NULL);
|
||||||
|
|
||||||
reconnect(NULL, -1, NULL);
|
if (settings)
|
||||||
|
reconnect(NULL, -1, NULL);
|
||||||
ecore_main_loop_begin();
|
ecore_main_loop_begin();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue