[sr-dev] git:master:9e6f94e0: topos: export intermodule api to set storage functions

Daniel-Constantin Mierla miconda at gmail.com
Thu Feb 23 07:53:23 CET 2017


Module: kamailio
Branch: master
Commit: 9e6f94e0ed3845f5da0c548e04f549906f58456e
URL: https://github.com/kamailio/kamailio/commit/9e6f94e0ed3845f5da0c548e04f549906f58456e

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-02-23T07:52:38+01:00

topos: export intermodule api to set storage functions

---

Modified: src/modules/topos/api.h
Modified: src/modules/topos/topos_mod.c
Modified: src/modules/topos/tps_storage.c

---

Diff:  https://github.com/kamailio/kamailio/commit/9e6f94e0ed3845f5da0c548e04f549906f58456e.diff
Patch: https://github.com/kamailio/kamailio/commit/9e6f94e0ed3845f5da0c548e04f549906f58456e.patch

---

diff --git a/src/modules/topos/api.h b/src/modules/topos/api.h
index 9002d90..1e27416 100644
--- a/src/modules/topos/api.h
+++ b/src/modules/topos/api.h
@@ -29,6 +29,7 @@
 #ifndef _TOPOS_API_H_
 #define _TOPOS_API_H_
 
+#include "../../core/sr_module.h"
 #include "tps_storage.h"
 
 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_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
diff --git a/src/modules/topos/topos_mod.c b/src/modules/topos/topos_mod.c
index 29a31c1..00f75a6 100644
--- a/src/modules/topos/topos_mod.c
+++ b/src/modules/topos/topos_mod.c
@@ -58,6 +58,7 @@
 
 #include "tps_storage.h"
 #include "tps_msg.h"
+#include "api.h"
 
 MODULE_VERSION
 
@@ -92,6 +93,15 @@ static int child_init(int rank);
 /* Module destroy function prototype */
 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[]={
 	{"db_url",			PARAM_STR, &_tps_db_url},
 	{"mask_callid",		PARAM_INT, &_tps_param_mask_callid},
@@ -107,7 +117,7 @@ static param_export_t params[]={
 struct module_exports exports= {
 	"topos",
 	DEFAULT_DLFLAGS, /* dlopen flags */
-	0,
+	cmds,
 	params,
 	0,          /* exported statistics */
 	0,          /* exported MI functions */
@@ -356,3 +366,17 @@ int tps_msg_sent(void *data)
 	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;
+}
diff --git a/src/modules/topos/tps_storage.c b/src/modules/topos/tps_storage.c
index 23f0da0..9bb416f 100644
--- a/src/modules/topos/tps_storage.c
+++ b/src/modules/topos/tps_storage.c
@@ -85,6 +85,18 @@ static tps_storage_api_t _tps_storage_api = {
 /**
  *
  */
+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;
+}
+
+/**
+ *
+ */
 int tps_storage_lock_set_init(void)
 {
 	_tps_storage_lock_set = lock_set_alloc(TPS_STORAGE_LOCK_SIZE);




More information about the sr-dev mailing list