浏览代码

topos: export intermodule api to set storage functions

Daniel-Constantin Mierla 8 年之前
父节点
当前提交
9e6f94e0ed
共有 3 个文件被更改,包括 71 次插入1 次删除
  1. 34 0
      src/modules/topos/api.h
  2. 25 1
      src/modules/topos/topos_mod.c
  3. 12 0
      src/modules/topos/tps_storage.c

+ 34 - 0
src/modules/topos/api.h

@@ -29,6 +29,7 @@
 #ifndef _TOPOS_API_H_
 #ifndef _TOPOS_API_H_
 #define _TOPOS_API_H_
 #define _TOPOS_API_H_
 
 
+#include "../../core/sr_module.h"
 #include "tps_storage.h"
 #include "tps_storage.h"
 
 
 typedef int (*tps_insert_dialog_f)(tps_data_t *td);
 typedef int (*tps_insert_dialog_f)(tps_data_t *td);
@@ -51,4 +52,37 @@ typedef struct tps_storage_api {
 	tps_end_dialog_f end_dialog;
 	tps_end_dialog_f end_dialog;
 } tps_storage_api_t;
 } tps_storage_api_t;
 
 
+
+typedef int (*tps_set_storage_api_f)(tps_storage_api_t *tsa);
+int tps_set_storage_api(tps_storage_api_t *tsa);
+
+
+/**
+ * @brief TOPOS API structure
+ */
+typedef struct topos_api {
+	tps_set_storage_api_f set_storage_api;
+} topos_api_t;
+
+typedef int (*bind_topos_f)(topos_api_t* api);
+
+/**
+ * @brief Load the TOPOS API
+ */
+static inline int topos_load_api(topos_api_t *api)
+{
+	bind_topos_f bindtopos;
+
+	bindtopos = (bind_topos_f)find_export("bind_topos", 0, 0);
+	if(bindtopos == 0) {
+		LM_ERR("cannot find bind_topos\n");
+		return -1;
+	}
+	if (bindtopos(api)==-1) {
+		LM_ERR("cannot bind topos api\n");
+		return -1;
+	}
+	return 0;
+}
+
 #endif
 #endif

+ 25 - 1
src/modules/topos/topos_mod.c

@@ -58,6 +58,7 @@
 
 
 #include "tps_storage.h"
 #include "tps_storage.h"
 #include "tps_msg.h"
 #include "tps_msg.h"
+#include "api.h"
 
 
 MODULE_VERSION
 MODULE_VERSION
 
 
@@ -92,6 +93,15 @@ static int child_init(int rank);
 /* Module destroy function prototype */
 /* Module destroy function prototype */
 static void destroy(void);
 static void destroy(void);
 
 
+int bind_topos(topos_api_t *api);
+
+static cmd_export_t cmds[]={
+	{"bind_topos",  (cmd_function)bind_topos,  0,
+		0, 0, 0},
+
+	{0, 0, 0, 0, 0, 0}
+};
+
 static param_export_t params[]={
 static param_export_t params[]={
 	{"db_url",			PARAM_STR, &_tps_db_url},
 	{"db_url",			PARAM_STR, &_tps_db_url},
 	{"mask_callid",		PARAM_INT, &_tps_param_mask_callid},
 	{"mask_callid",		PARAM_INT, &_tps_param_mask_callid},
@@ -107,7 +117,7 @@ static param_export_t params[]={
 struct module_exports exports= {
 struct module_exports exports= {
 	"topos",
 	"topos",
 	DEFAULT_DLFLAGS, /* dlopen flags */
 	DEFAULT_DLFLAGS, /* dlopen flags */
-	0,
+	cmds,
 	params,
 	params,
 	0,          /* exported statistics */
 	0,          /* exported statistics */
 	0,          /* exported MI functions */
 	0,          /* exported MI functions */
@@ -356,3 +366,17 @@ done:
 	return 0;
 	return 0;
 }
 }
 
 
+/**
+ *
+ */
+int bind_topos(topos_api_t *api)
+{
+	if (!api) {
+		ERR("Invalid parameter value\n");
+		return -1;
+	}
+	memset(api, 0, sizeof(topos_api_t));
+	api->set_storage_api = tps_set_storage_api;
+
+	return 0;
+}

+ 12 - 0
src/modules/topos/tps_storage.c

@@ -82,6 +82,18 @@ static tps_storage_api_t _tps_storage_api = {
 	.end_dialog = tps_db_end_dialog
 	.end_dialog = tps_db_end_dialog
 };
 };
 
 
+/**
+ *
+ */
+int tps_set_storage_api(tps_storage_api_t *tsa)
+{
+	if(tsa==NULL)
+		return -1;
+	memcpy(&_tps_storage_api, tsa, sizeof(tps_storage_api_t));
+
+	return 0;
+}
+
 /**
 /**
  *
  *
  */
  */