add master/slave mode for metadata locking between instances

This commit is contained in:
zmike 2014-08-09 23:17:54 -04:00
parent b284cde4f3
commit bfc9463bf2
13 changed files with 107 additions and 27 deletions

2
.gitignore vendored
View File

@ -4,6 +4,8 @@ Empd_Common.c
Empd_Common.h
Empd_Common_Azy.c
Empd_Common_Azy.h
eldbus_empd_empdd.c
eldbus_empd_empdd.h
eldbus_empd_empc.c
eldbus_empd_empc.h
eldbus_utils.h

2
TODO
View File

@ -21,8 +21,6 @@ EMPDD
BUGS
* need master/slave mode for metadata
* search entry use in filesystem
* filter main text with black outline
* fucking genlist item focus bugs
* fallback for no metadata found -> show info + hide logo

View File

@ -1,3 +1,3 @@
[D-BUS Service]
Name=org.empd.empc
Name=org.empd.empdd
Exec=@prefix@/bin/empdd

View File

@ -23,6 +23,8 @@ src_bin_empc_LDADD = \
ELDBUS_SRC = \
src/bin/eldbus_empd_empdd.c \
src/bin/eldbus_empd_empdd.h \
src/bin/eldbus_empd_empc.c \
src/bin/eldbus_empd_empc.h \
src/bin/eldbus_utils.h
AZY_SRC = \
@ -46,7 +48,8 @@ $(AZY_SRC): src/bin/empdd.azy
@AZY_PARSER@ -H -o $(top_builddir)/src/bin src/bin/empdd.azy
$(ELDBUS_SRC): src/bin/empdd.xml
@cd $(top_builddir)/src/bin && eldbus-codegen $(abs_top_srcdir)/src/bin/empdd.xml
@cd $(top_builddir)/src/bin && \
eldbus-codegen $(abs_top_srcdir)/src/bin/empdd.xml
EXTRA_DIST += \
src/bin/empdd.xml \

View File

@ -1,12 +1,21 @@
#include "empc_private.h"
#include "eldbus_empd_empdd.h"
#include "eldbus_empd_empc.h"
#include "Empd_Common_Azy.h"
#define EMPC_METHOD_BASE "org.empd.empc"
#define WEIGHT evas_object_size_hint_weight_set
#define ALIGN evas_object_size_hint_align_set
#define EXPAND(X) WEIGHT((X), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND)
#define FILL(X) ALIGN((X), EVAS_HINT_FILL, EVAS_HINT_FILL)
typedef enum
{
EMPC_SIGNAL_BACKGROUND_CHANGED,
} EMPC_Signals;
enum
{
MPD_STATE_UNKNOWN = 0,
@ -31,6 +40,8 @@ typedef struct Empc_Entity
static Eina_Bool selecting, unselecting;
Eina_Bool master = EINA_FALSE;
static Eina_Stringshare *empd_host;
static unsigned int empd_port;
@ -76,6 +87,8 @@ static unsigned int clipboard_paste_length = 0;
int empc_log_dom = -1;
static Eldbus_Proxy *empd_proxy = NULL;
static Eldbus_Proxy *empc_proxy = NULL;
static Eldbus_Service_Interface *empc_iface = NULL;
static Eina_List *handlers = NULL;
static Eina_Hash *empd_current_queue = NULL;
@ -336,6 +349,7 @@ save_image(Evas_Object *img, const char *uri, const char *artist, const char *al
Empc_Module *mod;
Eina_Bool nosave = EINA_FALSE, override = EINA_FALSE;
if (!master) return;
if (img)
{
override = !!evas_object_data_get(img, "__empc_override");
@ -356,6 +370,7 @@ save_text(Evas_Object *obj, const char *artist, const char *song)
{
Empc_Module *mod;
if (!master) return;
if (evas_object_data_get(obj, "__empc_nosave")) return;
EINA_INLIST_FOREACH(empc_modules[EMPC_MODULE_TYPE_METADATA_SAVER], mod)
{
@ -442,6 +457,18 @@ bg_update_propogate(const char *artist, const char *album)
elm_genlist_item_fields_update(it, "empc.swallow.content", ELM_GENLIST_ITEM_FIELD_CONTENT);
}
static void
bg_update_signal(void)
{
if (master)
eldbus_service_signal_emit(empc_iface, EMPC_SIGNAL_BACKGROUND_CHANGED);
else
{
bg_ignore = EINA_TRUE;
empd_empc_change_background_call(empc_proxy);
}
}
static void
bg_paste_download_start(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
@ -457,8 +484,7 @@ bg_paste_download_done(void *data EINA_UNUSED, Evas_Object *obj, void *event_inf
elm_object_signal_emit(layout, "empc,bg,next", "empc");
save_image(obj, NULL, empd_song_artist, empd_song_album);
bg_update_propogate(empd_song_artist, empd_song_album);
empd_empdd_change_background_call(empd_proxy);
bg_ignore = EINA_TRUE;
bg_update_signal();
}
static Eina_Bool
@ -482,8 +508,7 @@ bg_paste(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Elm_Selection_Dat
bgselector_clear(bg[background_num]);
save_image(img, NULL, empd_song_artist, empd_song_album);
bg_update_propogate(empd_song_artist, empd_song_album);
empd_empdd_change_background_call(empd_proxy);
bg_ignore = EINA_TRUE;
bg_update_signal();
}
bgselector_image_add(bg[num], img);
}
@ -513,8 +538,7 @@ bg_paste(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Elm_Selection_Dat
bgselector_clear(bg[num]);
save_image(NULL, buf, empd_song_artist, empd_song_album);
bg_update_propogate(empd_song_artist, empd_song_album);
empd_empdd_change_background_call(empd_proxy);
bg_ignore = EINA_TRUE;
bg_update_signal();
}
bgselector_image_add(bg[num], img);
}
@ -1231,7 +1255,7 @@ bg_changed_post(void *d EINA_UNUSED, void *d2 EINA_UNUSED)
}
static Eina_Bool
empc_bg_changed(void *d EINA_UNUSED, int t EINA_UNUSED, Empd_Empdd_Connected_Data *ev EINA_UNUSED)
empc_bg_changed()
{
Empd_Empdd_Song *so;
const char *uri = NULL;
@ -2443,6 +2467,7 @@ module_check(Eina_Module *m, void *d EINA_UNUSED)
Empc_Module *mod;
Empc_Module_Type type = EMPC_MODULE_TYPE_LAST;
Empc_Module_Type_Cb type_cb;
Empc_Module_Remote_Cb remote_cb;
Empc_Module_Priority_Cb prio_cb;
filename = eina_module_file_get(m);
@ -2465,11 +2490,14 @@ module_check(Eina_Module *m, void *d EINA_UNUSED)
goto error;
}
prio_cb = eina_module_symbol_get(m, "empc_module_priority");
remote_cb = eina_module_symbol_get(m, "empc_module_remote");
mod = calloc(1, empc_module_size[type]);
mod->type = type;
if (prio_cb)
mod->priority = prio_cb();
if (remote_cb)
mod->remote = remote_cb();
mod->module = m;
empc_modules[type] = eina_inlist_sorted_insert(empc_modules[type], EINA_INLIST_GET(mod), (Eina_Compare_Cb)module_sort_cb);
@ -2586,8 +2614,7 @@ bg_chooser_hide(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char
bgchooser = EINA_FALSE;
bg_update_propogate(artist, album);
empd_empdd_change_background_call(empd_proxy);
bg_ignore = EINA_TRUE;
bg_update_signal();
}
static void
@ -2678,6 +2705,37 @@ login_port_filter(void *d EINA_UNUSED, Evas_Object *obj EINA_UNUSED, char **text
}
}
static void
dbus_request_name(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
{
master = !eldbus_message_error_get(msg, NULL, NULL);
}
static Eldbus_Message *
dbus_bgchange(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
{
eldbus_service_signal_emit(empc_iface, EMPC_SIGNAL_BACKGROUND_CHANGED);
empc_bg_changed();
return eldbus_message_method_return_new(msg);
}
static const Eldbus_Signal empc_signals[] =
{
[EMPC_SIGNAL_BACKGROUND_CHANGED] = {"BackgroundChanged", NULL, 0},
{NULL, NULL, 0}
};
static const Eldbus_Method empc_methods[] =
{
{ "ChangeBackground", NULL, NULL, dbus_bgchange, 0},
{NULL, NULL, NULL, NULL, 0}
};
static const Eldbus_Service_Interface_Desc base_desc =
{
EMPC_METHOD_BASE, NULL, empc_signals, NULL, NULL, NULL
};
int
main(int argc, char *argv[])
{
@ -2728,6 +2786,10 @@ main(int argc, char *argv[])
dbus_conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
empd_proxy = empd_empdd_proxy_get(dbus_conn, EMPDD_METHOD_BASE, NULL);
empc_proxy = empd_empc_proxy_get(dbus_conn, EMPC_METHOD_BASE, NULL);
eldbus_name_request(dbus_conn, EMPC_METHOD_BASE, 0, dbus_request_name, NULL);
empc_iface = eldbus_service_interface_register(dbus_conn, "/", &base_desc);
E_LIST_HANDLER_APPEND(handlers, EMPD_EMPDD_CONNECTED_EVENT, empc_connected, NULL);
E_LIST_HANDLER_APPEND(handlers, EMPD_EMPDD_DISCONNECTED_EVENT, empc_disconnected, NULL);
E_LIST_HANDLER_APPEND(handlers, EMPD_EMPDD_LOGIN_FAILED_EVENT, empc_login_fail, NULL);
@ -2735,7 +2797,7 @@ main(int argc, char *argv[])
E_LIST_HANDLER_APPEND(handlers, EMPD_EMPDD_STATUS_EVENT, empc_status, NULL);
E_LIST_HANDLER_APPEND(handlers, EMPD_EMPDD_QUEUE_LIST_EVENT, empc_queue_list, NULL);
E_LIST_HANDLER_APPEND(handlers, EMPD_EMPDD_DATABASE_UPDATE_EVENT, empc_database, NULL);
E_LIST_HANDLER_APPEND(handlers, EMPD_EMPDD_BACKGROUND_CHANGED_EVENT, empc_bg_changed, NULL);
E_LIST_HANDLER_APPEND(handlers, EMPD_EMPC_BACKGROUND_CHANGED_EVENT, empc_bg_changed, NULL);
empd_empdd_is_connected_call(empd_proxy, empc_isconnected, NULL);
@ -2974,6 +3036,7 @@ main(int argc, char *argv[])
metadata_shutdown();
empd_empdd_proxy_unref(empd_proxy);
empd_empdd_proxy_unref(empc_proxy);
E_FREE_LIST(handlers, ecore_event_handler_del);
eldbus_connection_unref(dbus_conn);
eldbus_shutdown();

View File

@ -16,6 +16,7 @@ typedef enum
typedef struct Empc_Fetch_Request Empc_Fetch_Request;
typedef Eina_Bool (*Empc_Module_Remote_Cb)(void);
typedef Empc_Module_Type (*Empc_Module_Type_Cb)(void);
typedef int (*Empc_Module_Priority_Cb)(void);
typedef void (*Empc_Module_Metadata_Save_Image_Cb)(Evas_Object *obj, const char *uri, const char *artist, const char *album);
@ -42,3 +43,4 @@ void empc_metadata_image_download(Empc_Fetch_Request *req, const char *url);
void empc_metadata_image_download_queue(Empc_Fetch_Request *req, const char *url);
extern Eina_Stringshare *empd_music_directory;
extern Eina_Bool master;

View File

@ -140,6 +140,7 @@ metadata_fetch_continue(Empc_Fetch_Request_Internal *ireq)
EINA_INLIST_FOREACH(mods, mod)
{
Empc_Module_Metadata_Fetch *em = (Empc_Module_Metadata_Fetch*)mod;
if (mod->remote && (!master)) continue;
if (!em->fetch((Empc_Fetch_Request*)ireq)) continue;
//INF("METADATA FETCH(%s)", strrchr(eina_module_file_get(mod->module), '/') + 1);
ireq->module = mod;

View File

@ -27,6 +27,7 @@ typedef struct Empc_Module
int priority; //lower = better
Empc_Module_Type type;
Eina_Module *module;
Eina_Bool remote : 1;
} Empc_Module;
typedef struct Empc_Module_Metadata_Fetch

View File

@ -118,7 +118,6 @@ typedef enum
EMPD_SIGNAL_CURRENT_SONG,
EMPD_SIGNAL_QUEUE_LIST,
EMPD_SIGNAL_DATABASE_UPDATE,
EMPD_SIGNAL_BACKGROUND_CHANGED,
} EMPD_Signals;
static const Eldbus_Signal empd_signals[] =
@ -138,7 +137,6 @@ static const Eldbus_Signal empd_signals[] =
{"s", "name"}, {"s", "date"}, {"s", "disc"}, {"i", "song_pos"}, {"i", "songid"}), 0},
[EMPD_SIGNAL_QUEUE_LIST] = {"QueueList", ELDBUS_ARGS({"a(stusssisssii)", "array_of_songs"}), 0},
[EMPD_SIGNAL_DATABASE_UPDATE] = {"DatabaseUpdate", NULL, 0},
[EMPD_SIGNAL_BACKGROUND_CHANGED] = {"BackgroundChanged", NULL, 0},
{NULL, NULL, 0}
};
@ -1192,13 +1190,6 @@ _dbus_update_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_
return eldbus_message_method_return_new(msg);
}
static Eldbus_Message *
_dbus_bgchange_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
{
eldbus_service_signal_emit(empd_iface, EMPD_SIGNAL_BACKGROUND_CHANGED);
return eldbus_message_method_return_new(msg);
}
static Eldbus_Message *
_dbus_isconnected_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
{
@ -1264,7 +1255,6 @@ static const Eldbus_Method empd_methods[] =
{ "Consume", ELDBUS_ARGS({"b", "mode"}), NULL, _dbus_consume_cb, 0},
{ "ListInfo", ELDBUS_ARGS({"s", "path"}), ELDBUS_ARGS({"a(iv)", "array_of_infos"}), _dbus_listinfo_cb, 0},
{ "Update", ELDBUS_ARGS({"s", "path"}), NULL, _dbus_update_cb, 0},
{ "ChangeBackground", NULL, NULL, _dbus_bgchange_cb, 0},
{NULL, NULL, NULL, NULL, 0}
};

View File

@ -124,9 +124,6 @@
<arg type="s" name="path" direction="in" />
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true" />
</method>
<method name="ChangeBackground">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true" />
</method>
<signal name="Status">
<arg type="i" name="volume" direction="out" /><!-- volume % -->
<arg type="b" name="repeat" direction="out" />
@ -183,6 +180,11 @@
</signal>
<signal name="DatabaseUpdate">
</signal>
</interface>
<interface name="org.empd.empc">
<method name="ChangeBackground">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true" />
</method>
<signal name="BackgroundChanged">
</signal>
</interface>

View File

@ -129,6 +129,12 @@ empc_module_metadata_fetch(const Empc_Fetch_Request *req)
return EINA_TRUE;
}
EAPI Eina_Bool
empc_module_remote(void)
{
return EINA_TRUE;
}
EAPI Empc_Module_Type
empc_module_type(void)
{

View File

@ -158,6 +158,12 @@ empc_module_metadata_fetch(Empc_Fetch_Request *req)
return !!exe;
}
EAPI Eina_Bool
empc_module_remote(void)
{
return EINA_TRUE;
}
EAPI Empc_Module_Type
empc_module_type(void)
{

View File

@ -158,6 +158,12 @@ empc_module_metadata_fetch(Empc_Fetch_Request *req)
return EINA_TRUE;
}
EAPI Eina_Bool
empc_module_remote(void)
{
return EINA_TRUE;
}
EAPI Empc_Module_Type
empc_module_type(void)
{