summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2015-09-06 22:17:52 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2015-09-06 22:21:20 -0400
commit71427769dec951e073fa7c73fc2435efac381992 (patch)
treeb24db1b6d0fbb515f8dcaa6e08666072cb365c35 /src
parent5cd08a5df93d130d674cd6a6f4dbc52ddf6e2a7c (diff)
explicitly attempt to start empdd from empc on startup
this fixes autoconnection on more pedantic systems: gentoo doesn't seem to need it, yet fedora does? by making StartServiceByName the first call, it's easier to know if empdd needs a connect() method call and then to send it before any other method calls so that startup remains smooth behind the scenes
Diffstat (limited to 'src')
-rw-r--r--src/bin/empc.c61
1 files changed, 58 insertions, 3 deletions
diff --git a/src/bin/empc.c b/src/bin/empc.c
index dc538fb..3a83b3b 100644
--- a/src/bin/empc.c
+++ b/src/bin/empc.c
@@ -3669,6 +3669,62 @@ static const Eldbus_Service_Interface_Desc base_desc =
3669 EMPC_METHOD_BASE, empc_methods, empc_signals, NULL, NULL, NULL 3669 EMPC_METHOD_BASE, empc_methods, empc_signals, NULL, NULL, NULL
3670}; 3670};
3671 3671
3672static void
3673empd_send_connect(void)
3674{
3675 const char *h, *pass = NULL, *p = NULL;
3676 char host[PATH_MAX] = {0};
3677 int port = DEFAULT_PORT;
3678
3679 pass = getenv("MPD_PASSWORD");
3680 p = getenv("MPD_PORT");
3681 h = getenv("MPD_HOST");
3682 if (h)
3683 {
3684 if (!p)
3685 p = strchr(h, ':');
3686 if (p)
3687 {
3688 if (p - h > PATH_MAX - 1)
3689 {
3690 fprintf(stderr, "MPD_HOST longer than 4096 chars? I don't believe you.\n");
3691 /* FIXME */
3692 error_o_doom();
3693 return;
3694 }
3695 port = strtol(p + 1, NULL, 10);
3696 memcpy(host, h, p - h);
3697 h = host;
3698 }
3699 }
3700 else
3701 {
3702 struct stat st;
3703
3704 if (!stat("/var/lib/mpd/socket", &st))
3705 h = "/var/lib/mpd/socket";
3706 else if (!stat("/run/mpd/socket", &st))
3707 h = "/run/mpd/socket";
3708 }
3709 empd_empdd_connect_call(empd_proxy, h ?: "", port, pass ?: "");
3710}
3711
3712static void
3713empd_name_start(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
3714{
3715 unsigned flag = 0;
3716
3717 if ((!eldbus_message_arguments_get(msg, "u", &flag)) || (!flag))
3718 {
3719 error_o_doom();
3720 return;
3721 }
3722 if (flag == ELDBUS_NAME_START_REPLY_SUCCESS)
3723 empd_send_connect();
3724 else
3725 empd_empdd_is_connected_call(empd_proxy, empc_isconnected, NULL);
3726}
3727
3672int 3728int
3673main(int argc, char *argv[]) 3729main(int argc, char *argv[])
3674{ 3730{
@@ -3718,8 +3774,9 @@ main(int argc, char *argv[])
3718 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); 3774 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
3719 3775
3720 dbus_conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION); 3776 dbus_conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
3721 empd_proxy = empd_empdd_proxy_get(dbus_conn, EMPDD_METHOD_BASE, NULL); 3777 eldbus_name_start(dbus_conn, EMPDD_METHOD_BASE, 0, empd_name_start, NULL);
3722 empc_proxy = empd_empc_proxy_get(dbus_conn, EMPC_METHOD_BASE, NULL); 3778 empc_proxy = empd_empc_proxy_get(dbus_conn, EMPC_METHOD_BASE, NULL);
3779 empd_proxy = empd_empdd_proxy_get(dbus_conn, EMPDD_METHOD_BASE, NULL);
3723 eldbus_name_request(dbus_conn, EMPC_METHOD_BASE, 0, dbus_request_name, NULL); 3780 eldbus_name_request(dbus_conn, EMPC_METHOD_BASE, 0, dbus_request_name, NULL);
3724 eldbus_name_owner_changed_callback_add(dbus_conn, EMPC_METHOD_BASE, dbus_name_changed, NULL, EINA_FALSE); 3781 eldbus_name_owner_changed_callback_add(dbus_conn, EMPC_METHOD_BASE, dbus_name_changed, NULL, EINA_FALSE);
3725 empc_iface = eldbus_service_interface_register(dbus_conn, "/", &base_desc); 3782 empc_iface = eldbus_service_interface_register(dbus_conn, "/", &base_desc);
@@ -3744,8 +3801,6 @@ main(int argc, char *argv[])
3744 E_LIST_HANDLER_APPEND(handlers, EMPD_EMPDD_DATABASE_UPDATE_END_EVENT, empc_database_end, NULL); 3801 E_LIST_HANDLER_APPEND(handlers, EMPD_EMPDD_DATABASE_UPDATE_END_EVENT, empc_database_end, NULL);
3745 E_LIST_HANDLER_APPEND(handlers, EMPD_EMPC_BACKGROUND_CHANGED_EVENT, empc_bg_changed, NULL); 3802 E_LIST_HANDLER_APPEND(handlers, EMPD_EMPC_BACKGROUND_CHANGED_EVENT, empc_bg_changed, NULL);
3746 3803
3747 empd_empdd_is_connected_call(empd_proxy, empc_isconnected, NULL);
3748
3749 win = elm_win_add(NULL, "empc", ELM_WIN_BASIC); 3804 win = elm_win_add(NULL, "empc", ELM_WIN_BASIC);
3750 elm_object_style_set(win, "empc"); 3805 elm_object_style_set(win, "empc");
3751 elm_win_title_set(win, "empc"); 3806 elm_win_title_set(win, "empc");