summaryrefslogtreecommitdiff
path: root/src/persistence_client_library_handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/persistence_client_library_handle.c')
-rw-r--r--src/persistence_client_library_handle.c64
1 files changed, 52 insertions, 12 deletions
diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c
index a6a952d..2550b41 100644
--- a/src/persistence_client_library_handle.c
+++ b/src/persistence_client_library_handle.c
@@ -19,6 +19,7 @@
#include "persistence_client_library_handle.h"
+#include "persistence_client_library_custom_loader.h"
#include <pthread.h>
#include <stdlib.h>
@@ -48,7 +49,7 @@ pthread_mutex_t gMtx;
/// get persistence handle
-int get_persistence_handle_idx()
+int get_persistence_handle_idx(char* dbPath, char* key, PersistenceInfo_s* info)
{
int handle = 0;
@@ -60,38 +61,77 @@ int get_persistence_handle_idx()
if(pthread_mutex_lock(&gMtx) == 0)
{
- if(gFreeHandleIdxHead > 0) // check if we have a free spot in the array before the current max
+ if( PersistenceStorage_shared == info->configKey.storage
+ || PersistenceStorage_local == info->configKey.storage)
{
- handle = gFreeHandleArray[--gFreeHandleIdxHead];
+ if(gFreeHandleIdxHead > 0) // check if we have a free spot in the array before the current max
+ {
+ handle = gFreeHandleArray[--gFreeHandleIdxHead];
+ }
+ else
+ {
+ if(gHandleIdx < MaxPersHandle-1)
+ {
+ handle = gHandleIdx++; // no free spot before current max, increment handle index
+ }
+ else
+ {
+ handle = -1;
+ DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("get_persistence_handle_idx => Reached maximum of open handles: "), DLT_INT(MaxPersHandle));
+ }
+ }
}
- else
+ else if(PersistenceStorage_custom == info->configKey.storage)
{
- if(gHandleIdx < MaxPersHandle-1)
+ int idx = custom_client_name_to_id(dbPath, 1);
+ char workaroundPath[128]; // workaround, because /sys/ can not be accessed on host!!!!
+ snprintf(workaroundPath, 128, "%s%s", "/Data", dbPath );
+
+ if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_open != NULL) )
{
- handle = gHandleIdx++; // no free spot before current max, increment handle index
+ int flag = 0, mode = 0;
+ handle = gPersCustomFuncs[idx].custom_plugin_handle_open(workaroundPath, flag, mode);
}
else
{
- handle = -1;
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("get_persistence_handle_idx => Reached maximum of open handles: "), DLT_INT(MaxPersHandle));
+ handle = EPERS_NOPLUGINFUNCT;
}
}
pthread_mutex_unlock(&gMtx);
}
-
return handle;
}
/// close persistence handle
-void set_persistence_handle_close_idx(int handle)
+int set_persistence_handle_close_idx(int handle, char* dbPath, char* key, PersistenceInfo_s* info)
{
+ int rval = 0;
+
if(pthread_mutex_lock(&gMtx) == 0)
{
- if(gFreeHandleIdxHead < MaxPersHandle)
+ if( PersistenceStorage_shared == info->configKey.storage
+ || PersistenceStorage_local == info->configKey.storage)
{
- gFreeHandleArray[gFreeHandleIdxHead++] = handle;
+ if(gFreeHandleIdxHead < MaxPersHandle)
+ {
+ gFreeHandleArray[gFreeHandleIdxHead++] = handle;
+ }
}
+ else if(PersistenceStorage_custom == gKeyHandleArray[handle].info.configKey.storage )
+ {
+ int idx = custom_client_name_to_id(gKeyHandleArray[handle].dbPath, 1);
+
+ if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_close != NULL) )
+ {
+ rval = gPersCustomFuncs[idx].custom_plugin_handle_close(handle);
+ }
+ else
+ {
+ rval = EPERS_NOPLUGINFUNCT;
+ }
+ }
+
pthread_mutex_unlock(&gMtx);
}
}