summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2014-06-16 23:22:25 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-14 23:33:17 -0300
commit7c4bf1e07ef110b187965f5806a3658ff21f840c (patch)
tree27dd0f1fd013332c0e868a04e121edc638036f00
parentef84767e8dadef00d29b043a1be4e72dc4280e6c (diff)
emix: Adding callbacks for events
Adding callbacks to be used for the backends when they need to inform that an event happened (new sink available, new sink input, ...).
-rw-r--r--src/lib/backends/alsa/alsa.c21
-rw-r--r--src/lib/emix.c27
-rw-r--r--src/lib/emix.h10
3 files changed, 55 insertions, 3 deletions
diff --git a/src/lib/backends/alsa/alsa.c b/src/lib/backends/alsa/alsa.c
index 9b62e36..b2b42fb 100644
--- a/src/lib/backends/alsa/alsa.c
+++ b/src/lib/backends/alsa/alsa.c
@@ -1,14 +1,33 @@
1#include <Eina.h> 1#include <Eina.h>
2#include <emix.h> 2#include <emix.h>
3 3
4typedef struct _Context {
5 sink_event_cb sink_cb;
6 sink_input_event_cb sink_input_cb;
7 source_event_cb source_cb;
8 disconnect_event_cb disconnect_cb;
9} Context;
10
11static Context *ctx = NULL;
12
4static void 13static void
5_alsa_init(void) 14_alsa_init(sink_event_cb sink_cb, sink_input_event_cb input_cb,
15 source_event_cb source_cb, disconnect_event_cb disconnect_cb)
6{ 16{
17 if (!ctx)
18 ctx = calloc(1, sizeof(Context));
19
20 ctx->sink_cb = sink_cb;
21 ctx->sink_input_cb = input_cb;
22 ctx->source_cb = source_cb;
23 ctx->disconnect_cb = disconnect_cb;
7} 24}
8 25
9static void 26static void
10_alsa_shutdown(void) 27_alsa_shutdown(void)
11{ 28{
29 free(ctx);
30 ctx = NULL;
12} 31}
13 32
14static Emix_Backend 33static Emix_Backend
diff --git a/src/lib/emix.c b/src/lib/emix.c
index 50d0b91..74fa00c 100644
--- a/src/lib/emix.c
+++ b/src/lib/emix.c
@@ -19,6 +19,30 @@ int EMIX_SINK_INPUT_EVENT = 0;
19int EMIX_SOURCE_EVENT = 0; 19int EMIX_SOURCE_EVENT = 0;
20int EMIX_DISCONNECTED_EVENT = 0; 20int EMIX_DISCONNECTED_EVENT = 0;
21 21
22static void
23_disconnect_cb(void)
24{
25 ecore_event_add(EMIX_DISCONNECTED_EVENT, NULL, NULL, NULL);
26}
27
28static void
29_sink_cb(Emix_Sink *sink, Emix_Event_Type type)
30{
31 ecore_event_add(EMIX_SINK_EVENT, sink, NULL, (void *)type);
32}
33
34static void
35_sink_input_cb(Emix_Sink_Input *input, Emix_Event_Type type)
36{
37 ecore_event_add(EMIX_SINK_INPUT_EVENT, input, NULL, (void *)type);
38}
39
40static void
41_source_cb(Emix_Source *source, Emix_Event_Type type)
42{
43 ecore_event_add(EMIX_SOURCE_EVENT, source, NULL, (void *)type);
44}
45
22static Eina_Bool 46static Eina_Bool
23_backend_get_cb(Eina_Module *module, void *data EINA_UNUSED) 47_backend_get_cb(Eina_Module *module, void *data EINA_UNUSED)
24{ 48{
@@ -133,7 +157,8 @@ emix_backend_set(const char *backend)
133 if (!ctx->loaded || !ctx->loaded->ebackend_init) 157 if (!ctx->loaded || !ctx->loaded->ebackend_init)
134 return EINA_FALSE; 158 return EINA_FALSE;
135 159
136 ctx->loaded->ebackend_init(); 160 ctx->loaded->ebackend_init(_sink_cb, _sink_input_cb, _source_cb,
161 _disconnect_cb);
137 return EINA_TRUE; 162 return EINA_TRUE;
138} 163}
139 164
diff --git a/src/lib/emix.h b/src/lib/emix.h
index a9c6cfb..06638b1 100644
--- a/src/lib/emix.h
+++ b/src/lib/emix.h
@@ -39,9 +39,17 @@ typedef enum _Emix_Event_Type {
39 EMIX_EVENT_REMOVED 39 EMIX_EVENT_REMOVED
40} Emix_Event_Type; 40} Emix_Event_Type;
41 41
42typedef void (*sink_event_cb)(Emix_Sink *sink, Emix_Event_Type type);
43typedef void (*sink_input_event_cb)(Emix_Sink_Input *input,
44 Emix_Event_Type type);
45typedef void (*source_event_cb)(Emix_Source *source, Emix_Event_Type type);
46typedef void (*disconnect_event_cb)(void);
42 47
43typedef struct _Emix_Backend { 48typedef struct _Emix_Backend {
44 void (*ebackend_init)(void); 49 void (*ebackend_init)(sink_event_cb sink_cb,
50 sink_input_event_cb input_cb,
51 source_event_cb source_cb,
52 disconnect_event_cb disconnect_cb);
45 void (*ebackend_shutdown)(void); 53 void (*ebackend_shutdown)(void);
46 54
47 const Eina_List* (*ebackend_sinks_get)(void); 55 const Eina_List* (*ebackend_sinks_get)(void);