summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Friloux <guillaume.friloux@gmail.com>2013-08-13 22:35:22 +0200
committerGuillaume Friloux <guillaume.friloux@gmail.com>2013-08-13 22:35:22 +0200
commit32266b74427cadbc8f1fdc44ac68e7f1977acd00 (patch)
tree864d3cdf1710c2cb74fefc5be79821f01ff81c73
parentbd4750e18680c0293862637ffedaf377783ea3f5 (diff)
Module management.
-rw-r--r--Makefile.am1
-rw-r--r--configure.ac25
-rw-r--r--src/include/Skypunch.h3
-rw-r--r--src/lib/Makefile.mk3
-rw-r--r--src/lib/skypunch_main.c82
-rw-r--r--src/lib/skypunch_private.h23
-rw-r--r--src/modules/.deps/libmega.Plo1
-rw-r--r--src/modules/.deps/src_modules_mega_la-mega.Plo1
8 files changed, 123 insertions, 16 deletions
diff --git a/Makefile.am b/Makefile.am
index ac3fd66..177ffba 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,5 +17,6 @@ missing \
17m4/l* 17m4/l*
18 18
19include src/lib/Makefile.mk 19include src/lib/Makefile.mk
20include src/modules/Makefile.mk
20 21
21.PHONY: doc 22.PHONY: doc
diff --git a/configure.ac b/configure.ac
index 08afec9..436ce1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,7 @@ AC_DEFINE_UNQUOTED(VMIC, [v_mic], [Micro version])
23 23
24AC_SUBST(VMAJ) 24AC_SUBST(VMAJ)
25 25
26AM_INIT_AUTOMAKE([1.6 dist-bzip2]) 26AM_INIT_AUTOMAKE([subdir-objects])
27m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 27m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
28 28
29AC_PROG_LIBTOOL 29AC_PROG_LIBTOOL
@@ -34,6 +34,29 @@ AC_PROG_MAKE_SET
34AC_C___ATTRIBUTE__ 34AC_C___ATTRIBUTE__
35AC_FUNC_ALLOCA 35AC_FUNC_ALLOCA
36 36
37case "$host_os" in
38 mingw32ce*)
39 MODULE_ARCH="$host_os-$host_cpu"
40 ;;
41 *)
42 MODULE_ARCH="$host_os-$host_cpu-v_maj.v_min.v_mic"
43 ;;
44esac
45AC_SUBST(MODULE_ARCH)
46AC_DEFINE_UNQUOTED(MODULE_ARCH, "${MODULE_ARCH}", "Module architecture")
47
48case "$host_os" in
49 mingw*)
50 MODULE_EXT=".dll"
51 ;;
52 *)
53 MODULE_EXT=".so"
54 ;;
55esac
56
57AC_DEFINE_UNQUOTED(SHARED_LIB_SUFFIX, "${MODULE_EXT}", [Suffix for shared objects])
58
59
37SKYPUNCH_REQUIRES="eina >= 1.7.7 ecore >= 1.7.7" 60SKYPUNCH_REQUIRES="eina >= 1.7.7 ecore >= 1.7.7"
38AC_SUBST(requirement_skypunch) 61AC_SUBST(requirement_skypunch)
39 62
diff --git a/src/include/Skypunch.h b/src/include/Skypunch.h
index 6f72d06..42f854e 100644
--- a/src/include/Skypunch.h
+++ b/src/include/Skypunch.h
@@ -2,9 +2,6 @@
2#include <Ecore.h> 2#include <Ecore.h>
3#include <Ecore_Con.h> 3#include <Ecore_Con.h>
4 4
5extern int SKYPUNCH_EVENT_CONNECT;
6extern int SKYPUNCH_EVENT_DISCONNECT;
7
8typedef enum _Skypunch_Type 5typedef enum _Skypunch_Type
9{ 6{
10 SKYPUNCH_MEGA 7 SKYPUNCH_MEGA
diff --git a/src/lib/Makefile.mk b/src/lib/Makefile.mk
index 53b0995..a928215 100644
--- a/src/lib/Makefile.mk
+++ b/src/lib/Makefile.mk
@@ -1,6 +1,7 @@
1LIB_CPPFLAGS= \ 1LIB_CPPFLAGS= \
2-I$(top_srcdir) \ 2-I$(top_srcdir) \
3-I$(top_srcdir)/src/include 3-I$(top_srcdir)/src/include \
4-DSKYPUNCH_MODULE_PATH=\"$(libdir)/skypunch/$(MODULE_ARCH)\"
4 5
5noinst_LTLIBRARIES = src/lib/libskypunch.la 6noinst_LTLIBRARIES = src/lib/libskypunch.la
6 7
diff --git a/src/lib/skypunch_main.c b/src/lib/skypunch_main.c
index c7ac053..ffbbcbb 100644
--- a/src/lib/skypunch_main.c
+++ b/src/lib/skypunch_main.c
@@ -3,8 +3,72 @@
3int _skypunch_log_dom_global; 3int _skypunch_log_dom_global;
4static int _skypunch_init_count; 4static int _skypunch_init_count;
5 5
6int SKYPUNCH_EVENT_CONNECT = 0; 6static Eina_Inlist *skypunch_modules = NULL;
7int SKYPUNCH_EVENT_DISCONNECT = 0; 7
8Eina_Bool
9skypunch_module_check(Eina_Module *m, void *d __UNUSED__)
10{
11 const char *filename;
12 Skypunch_Module_Init init;
13 Skypunch_Module *module;
14
15 filename = eina_module_file_get(m);
16 filename = strrchr(filename, '/') + 1;
17 if (strcmp(filename + (strlen(filename) - 3), SHARED_LIB_SUFFIX))
18 return EINA_FALSE;
19
20 if (!eina_module_load(m))
21 {
22 ERR("Could not verify module named '%s'. Error: '%s'",
23 filename, eina_error_msg_get(eina_error_get()));
24 return EINA_FALSE;
25 }
26
27 init = eina_module_symbol_get(m, "skypunch_module_init");
28 if (!init)
29 {
30 ERR("Could not find function skypunch_module_init()");
31 eina_module_unload(m);
32 return EINA_FALSE;
33 }
34
35 module = calloc(1, sizeof(Skypunch_Module));
36 if (!module)
37 {
38 ERR("Memory allocation failure");
39 eina_module_unload(m);
40 return EINA_FALSE;
41 }
42
43 module->type = init(NULL);
44 module->init = init;
45 module->module = m;
46 skypunch_modules = eina_inlist_append(skypunch_modules,
47 EINA_INLIST_GET(module));
48
49 return EINA_TRUE;
50}
51
52Eina_Bool
53skypunch_type_set(Skypunch *sp,
54 Skypunch_Type type)
55{
56 Skypunch_Module *module;
57
58 EINA_SAFETY_ON_NULL_RETURN_VAL(sp, EINA_FALSE);
59
60 memset(&sp->backend, 0, sizeof(sp->backend));
61
62 EINA_INLIST_FOREACH(skypunch_modules, module)
63 {
64 if (type != module->type) continue;
65 module->init(sp);
66 }
67 if (sp->type == type) return EINA_TRUE;
68
69 ERR("No module present for SQL type %u!", type);
70 return EINA_FALSE;
71}
8 72
9Skypunch * 73Skypunch *
10skypunch_new(Skypunch_Type type, 74skypunch_new(Skypunch_Type type,
@@ -18,10 +82,9 @@ skypunch_new(Skypunch_Type type,
18 ERR("Failed to allocate Skypunch structure."); 82 ERR("Failed to allocate Skypunch structure.");
19 return NULL; 83 return NULL;
20 } 84 }
21
22 sp->type = type;
23 sp->auth = strdup(auth); 85 sp->auth = strdup(auth);
24 86
87 skypunch_type_set(sp, type);
25 return sp; 88 return sp;
26} 89}
27 90
@@ -36,6 +99,8 @@ skypunch_free(Skypunch *skypunch)
36int 99int
37skypunch_init(void) 100skypunch_init(void)
38{ 101{
102 Eina_Array *mods;
103
39 if (++_skypunch_init_count != 1) 104 if (++_skypunch_init_count != 1)
40 return _skypunch_init_count; 105 return _skypunch_init_count;
41 106
@@ -63,13 +128,14 @@ skypunch_init(void)
63 goto shutdown_ecore; 128 goto shutdown_ecore;
64 } 129 }
65 130
66 /* Here is a good place to load modules */ 131 mods = eina_module_list_get(NULL, SKYPUNCH_MODULE_PATH, EINA_FALSE,
67 SKYPUNCH_EVENT_CONNECT = ecore_event_type_new(); 132 skypunch_module_check, NULL);
68 SKYPUNCH_EVENT_DISCONNECT = ecore_event_type_new(); 133 if (!mods) goto shutdown_ecorecon;
69 134 eina_array_free(mods);
70 135
71 return _skypunch_init_count; 136 return _skypunch_init_count;
72 137
138shutdown_ecorecon:
73 ecore_con_shutdown(); 139 ecore_con_shutdown();
74shutdown_ecore: 140shutdown_ecore:
75 ecore_shutdown(); 141 ecore_shutdown();
diff --git a/src/lib/skypunch_private.h b/src/lib/skypunch_private.h
index 931f45e..e595e6d 100644
--- a/src/lib/skypunch_private.h
+++ b/src/lib/skypunch_private.h
@@ -1,17 +1,38 @@
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
1 4
2#include <Skypunch.h> 5#include <Skypunch.h>
3 6
4extern int _skypunch_log_dom_global; 7extern int _skypunch_log_dom_global;
5 8
9typedef Skypunch_Type (*Skypunch_Module_Init)(Skypunch *);
10
11typedef struct _Skypunch_Module
12{
13 EINA_INLIST;
14 Skypunch_Type type;
15 Eina_Module *module;
16 Skypunch_Module_Init init;
17} Skypunch_Module;
18
19
6struct _Skypunch 20struct _Skypunch
7{ 21{
8 Skypunch_Type type; 22 Skypunch_Type type;
9 const char *auth; 23 const char *auth;
10};
11 24
25 struct
26 {
27 void *data;
28 Skypunch_Module_Init init;
29 } backend;
30};
12 31
13#define DBG(...) EINA_LOG_DOM_DBG(_skypunch_log_dom_global, __VA_ARGS__) 32#define DBG(...) EINA_LOG_DOM_DBG(_skypunch_log_dom_global, __VA_ARGS__)
14#define INFO(...) EINA_LOG_DOM_INFO(_skypunch_log_dom_global,__VA_ARGS__) 33#define INFO(...) EINA_LOG_DOM_INFO(_skypunch_log_dom_global,__VA_ARGS__)
15#define WARN(...) EINA_LOG_DOM_WARN(_skypunch_log_dom_global, __VA_ARGS__) 34#define WARN(...) EINA_LOG_DOM_WARN(_skypunch_log_dom_global, __VA_ARGS__)
16#define ERR(...) EINA_LOG_DOM_ERR(_skypunch_log_dom_global, __VA_ARGS__) 35#define ERR(...) EINA_LOG_DOM_ERR(_skypunch_log_dom_global, __VA_ARGS__)
17#define CRI(...) EINA_LOG_DOM_CRIT(_skypunch_log_dom_global, __VA_ARGS__) 36#define CRI(...) EINA_LOG_DOM_CRIT(_skypunch_log_dom_global, __VA_ARGS__)
37
38Eina_Bool skypunch_type_set(Skypunch *sp, Skypunch_Type type);
diff --git a/src/modules/.deps/libmega.Plo b/src/modules/.deps/libmega.Plo
deleted file mode 100644
index 9ce06a8..0000000
--- a/src/modules/.deps/libmega.Plo
+++ /dev/null
@@ -1 +0,0 @@
1# dummy
diff --git a/src/modules/.deps/src_modules_mega_la-mega.Plo b/src/modules/.deps/src_modules_mega_la-mega.Plo
deleted file mode 100644
index 9ce06a8..0000000
--- a/src/modules/.deps/src_modules_mega_la-mega.Plo
+++ /dev/null
@@ -1 +0,0 @@
1# dummy