#include "persistence_client_library_handle.h"
+#include "persistence_client_library_custom_loader.h"
#include <pthread.h>
#include <stdlib.h>
/// get persistence handle
-int get_persistence_handle_idx()
+int get_persistence_handle_idx(char* dbPath, char* key, PersistenceInfo_s* info)
{
int handle = 0;
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);
}
}
#include "persistence_client_library_handle.h"
#include "persistence_client_library_pas_interface.h"
#include "persistence_client_library_prct_access.h"
-#include "persistence_client_library_custom_loader.h"
+
// ----------------------------------------------------------------------------
if( (handle >= 0)
&& (dbContext.configKey.type == PersistenceResourceType_key) ) // check if type matches
{
- if(dbContext.configKey.storage < PersistenceStorage_LastEntry) // check if store policy is valid
- {
- if(PersistenceStorage_custom == dbContext.configKey.storage)
- {
- 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 );
+ handle = get_persistence_handle_idx(dbPath, dbKey, &dbContext);
- if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_open != NULL) )
- {
- int flag = 0, mode = 0;
- handle = gPersCustomFuncs[idx].custom_plugin_handle_open(workaroundPath, flag, mode);
- }
- else
- {
- handle = EPERS_NOPLUGINFUNCT;
- }
- }
- else
- {
- handle = get_persistence_handle_idx();
- }
-
- if((handle < MaxPersHandle) && (0 <= handle))
- {
- // remember data in handle array
- strncpy(gKeyHandleArray[handle].dbPath, dbPath, DbPathMaxLen);
- strncpy(gKeyHandleArray[handle].dbKey, dbKey, DbKeyMaxLen);
- strncpy(gKeyHandleArray[handle].resourceID, resource_id, DbResIDMaxLen);
- gKeyHandleArray[handle].dbPath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
- gKeyHandleArray[handle].dbKey[ DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
- gKeyHandleArray[handle].info = dbContext;
- }
- else
- {
- DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - handleId out of bounds:"), DLT_INT(handle));
- }
+ if((handle < MaxPersHandle) && (0 <= handle))
+ {
+ // remember data in handle array
+ strncpy(gKeyHandleArray[handle].dbPath, dbPath, DbPathMaxLen);
+ strncpy(gKeyHandleArray[handle].dbKey, dbKey, DbKeyMaxLen);
+ strncpy(gKeyHandleArray[handle].resourceID, resource_id, DbResIDMaxLen);
+ gKeyHandleArray[handle].dbPath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
+ gKeyHandleArray[handle].dbKey[ DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
+ gKeyHandleArray[handle].info = dbContext;
+ }
+ else
+ {
+ DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - handleId out of bounds:"), DLT_INT(handle));
}
}
else
{
if(key_handle < MaxPersHandle)
{
- if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage )
- {
- int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1);
-
- if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_close != NULL) )
- {
- rval = gPersCustomFuncs[idx].custom_plugin_handle_close(key_handle);
- }
- else
- {
- rval = EPERS_NOPLUGINFUNCT;
- }
- }
- else
- {
- set_persistence_handle_close_idx(key_handle);
- }
+ rval= set_persistence_handle_close_idx(key_handle, gKeyHandleArray[key_handle].dbPath,
+ gKeyHandleArray[key_handle].dbKey,
+ &gKeyHandleArray[key_handle].info);
// invalidate entries
memset(gKeyHandleArray[key_handle].dbPath, 0, DbPathMaxLen);
{
if(key_handle < MaxPersHandle)
{
- if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage)
- {
- int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1);
-
- if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_get_size != NULL) )
- {
- size = gPersCustomFuncs[idx].custom_plugin_get_size(gKeyHandleArray[key_handle].dbPath);
- }
- else
- {
- size = EPERS_NOPLUGINFUNCT;
- }
- }
- else
- {
- size = pers_db_get_key_size(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey,
- &gKeyHandleArray[key_handle].info);
- }
+ size = pers_db_get_key_size(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey,
+ &gKeyHandleArray[key_handle].info);
+ }
+ else
+ {
+ size = EPERS_MAXHANDLE;
}
}
{
int size = EPERS_NOT_INITIALIZED;
- //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleReadData: "),
- // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) );
+ //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleReadData: "),
+ // DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) );
- if(gPclInitialized >= PCLinitialized)
- {
- if(key_handle < MaxPersHandle)
+ if(gPclInitialized >= PCLinitialized)
{
- if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage)
+ if(key_handle < MaxPersHandle)
{
- int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1);
-
- if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_get_data != NULL) )
- {
- size = gPersCustomFuncs[idx].custom_plugin_handle_get_data(key_handle, (char*)buffer, buffer_size-1);
- }
- else
- {
- size = EPERS_NOPLUGINFUNCT;
- }
+ size = pers_db_read_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey,
+ &gKeyHandleArray[key_handle].info, buffer, buffer_size);
}
else
{
- size = pers_db_read_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey,
- &gKeyHandleArray[key_handle].info, buffer, buffer_size);
+ size = EPERS_MAXHANDLE;
}
}
- }
- return size;
+ return size;
}
gKeyHandleArray[key_handle].info.context.user_no,
gKeyHandleArray[key_handle].info.context.seat_no, callback);
}
+ else
+ {
+ rval = EPERS_MAXHANDLE;
+ }
}
return rval;
{
if(key_handle < MaxPersHandle)
{
- if(PersistenceStorage_custom == gKeyHandleArray[key_handle].info.configKey.storage)
- {
- int idx = custom_client_name_to_id(gKeyHandleArray[key_handle].dbPath, 1);
-
- if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL) )
- {
- size = gPersCustomFuncs[idx].custom_plugin_handle_set_data(key_handle, (char*)buffer, buffer_size-1);
- }
- else
- {
- size = EPERS_NOPLUGINFUNCT;
- }
- }
- else
- {
- size = pers_db_write_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey,
- &gKeyHandleArray[key_handle].info, buffer, buffer_size);
- }
+
+ size = pers_db_write_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey,
+ &gKeyHandleArray[key_handle].info, buffer, buffer_size);
}
else
{
}
else
{
+ size = EPERS_MAX_BUFF_SIZE;
DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleWriteData: error - buffer_size to big, limit is [bytes]:"), DLT_INT(gMaxKeyValDataSize));
}
}