If a customID is available for a customer plugin, used this ID instead the key
authorIngo Huerner <ingo.huerner@xse.de>
Wed, 27 Mar 2013 15:34:20 +0000 (16:34 +0100)
committerIngo Huerner <ingo.huerner@xse.de>
Wed, 27 Mar 2013 15:34:20 +0000 (16:34 +0100)
include_protected/persistence_client_library_data_organization.h
src/persistence_client_library_db_access.c
src/persistence_client_library_handle.h
src/persistence_client_library_key.c
src/persistence_client_library_prct_access.c

index 6151aa4..74a1aeb 100644 (file)
@@ -66,6 +66,7 @@ enum _PersistenceConstantDef
 
    CustLibMaxLen = 128,             /// max length of the custom library name and path
    DbKeyMaxLen   = 128,             /// max database key length
+   DbResIDMaxLen = 128,             /// max database key length
    DbPathMaxLen  = 128,             /// max database path length
    MaxAppNameLen = 128,             /// max application name
    MaxPersHandle = 256,             /// max number of parallel open persistence handles
index 5fdb09b..ab0eac1 100644 (file)
@@ -206,7 +206,10 @@ int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned
 
       if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_get_data != NULL) )
       {
-         gPersCustomFuncs[idx].custom_plugin_get_data(key, (char*)buffer, buffer_size);
+         if(info->configKey.customID[0] == '\0')   // if we have not a customID we use the key
+            gPersCustomFuncs[idx].custom_plugin_get_data(key, (char*)buffer, buffer_size);
+         else
+            gPersCustomFuncs[idx].custom_plugin_get_data(info->configKey.customID, (char*)buffer, buffer_size);
       }
       else
       {
@@ -332,7 +335,10 @@ int pers_db_write_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned
       int idx = custom_client_name_to_id(dbPath, 1);
       if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data) )
       {
-         gPersCustomFuncs[idx].custom_plugin_set_data(key, (char*)buffer, buffer_size);
+         if(info->configKey.customID[0] == '\0')   // if we have not a customID we use the key
+            gPersCustomFuncs[idx].custom_plugin_set_data(key, (char*)buffer, buffer_size);
+         else
+            gPersCustomFuncs[idx].custom_plugin_set_data(info->configKey.customID, (char*)buffer, buffer_size);
       }
       else
       {
@@ -394,7 +400,10 @@ int pers_db_get_key_size(char* dbPath, char* key, PersistenceInfo_s* info)
       int idx = custom_client_name_to_id(dbPath, 1);
       if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data) )
       {
-         gPersCustomFuncs[idx].custom_plugin_get_size(key);
+         if(info->configKey.customID[0] == '\0')   // if we have not a customID we use the key
+            gPersCustomFuncs[idx].custom_plugin_get_size(key);
+         else
+            gPersCustomFuncs[idx].custom_plugin_get_size(info->configKey.customID);
       }
       else
       {
@@ -454,7 +463,10 @@ int pers_db_delete_key(char* dbPath, char* dbKey, PersistenceInfo_s* info)
       int idx = custom_client_name_to_id(dbPath, 1);
       if((idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_set_data) )
       {
-         gPersCustomFuncs[idx].custom_plugin_delete_data(dbKey);
+         if(info->configKey.customID[0] == '\0')   // if we have not a customID we use the key
+            gPersCustomFuncs[idx].custom_plugin_delete_data(dbKey);
+         else
+            gPersCustomFuncs[idx].custom_plugin_delete_data(info->configKey.customID);
       }
       else
       {
index 502db7d..12654c0 100644 (file)
 /// handle structure definition
 typedef struct _PersistenceHandle_s
 {
-   PersistenceInfo_s info;    /// persistence info
-   char dbPath[DbPathMaxLen]; /// path to the database
-   char dbKey[DbKeyMaxLen];   /// database key
+   PersistenceInfo_s info;          /// persistence info
+   char dbPath[DbPathMaxLen];       /// path to the database
+   char dbKey[DbKeyMaxLen];         /// database key
+   char resourceID[DbResIDMaxLen];  /// resourceID
 }
 PersistenceHandle_s;
 
index 291c6c8..172087b 100644 (file)
@@ -83,6 +83,7 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u
             // remember data in handle array
             strncpy(gHandleArray[handle].dbPath, dbPath, DbPathMaxLen);
             strncpy(gHandleArray[handle].dbKey,  dbKey,  DbKeyMaxLen);
+            strncpy(gHandleArray[handle].resourceID,  resource_id,  DbResIDMaxLen);
             gHandleArray[handle].dbPath[DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
             gHandleArray[handle].dbKey[ DbPathMaxLen-1] = '\0'; // Ensures 0-Termination
             gHandleArray[handle].info = dbContext;
@@ -208,6 +209,14 @@ int pclKeyHandleRegisterNotifyOnChange(int key_handle, changeNotifyCallback_t ca
 {
    int rval = -1;
 
+   if(key_handle < MaxPersHandle)
+   {
+      pclKeyRegisterNotifyOnChange(gHandleArray[key_handle].info.context.ldbid,
+                                   gHandleArray[key_handle].resourceID,
+                                   gHandleArray[key_handle].info.context.user_no,
+                                   gHandleArray[key_handle].info.context.seat_no, callback);
+   }
+
    return rval;
 }
 
@@ -468,8 +477,6 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us
 }
 
 
-
-// status: TODO implement register on change
 int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, changeNotifyCallback_t callback)
 {
    int rval = 0;
index c2e4d21..a1ba5bf 100644 (file)
@@ -144,6 +144,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign
          //printf("get_db_context ==> data: %s\n", search.data);
          memset(dbContext->configKey.reponsible,  0, MaxConfKeyLengthResp);
          memset(dbContext->configKey.custom_name, 0, MaxConfKeyLengthCusName);
+         memset(dbContext->configKey.customID,    0,  MaxRctLengthCustom_ID);
 
          dbContext->configKey.policy      = search.data.policy;
          dbContext->configKey.storage     = search.data.storage;
@@ -152,6 +153,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign
          dbContext->configKey.type        = search.data.type;
          memcpy(dbContext->configKey.reponsible, search.data.reponsible, MaxConfKeyLengthResp);
          memcpy(dbContext->configKey.custom_name, search.data.custom_name, MaxConfKeyLengthCusName);
+         memcpy(dbContext->configKey.customID, search.data.customID, MaxRctLengthCustom_ID);
 
          if(dbContext->configKey.storage != PersistenceStorage_custom )
          {