Minor fixes including dbus interface fixe
authorIngo Huerner <ingo.huerner@xse.de>
Mon, 21 Oct 2013 11:26:52 +0000 (13:26 +0200)
committerIngo Huerner <ingo.huerner@xse.de>
Mon, 21 Oct 2013 11:26:52 +0000 (13:26 +0200)
20 files changed:
config/org.genivi.persistence.admin.conf [new file with mode: 0644]
config/pclCustomLibConfigFile.cfg
include/persistence_client_library.h
include/persistence_client_library_error_def.h
include/persistence_client_library_file.h
src/persistence_client_library.c
src/persistence_client_library_backup_filelist.c
src/persistence_client_library_db_access.c
src/persistence_client_library_dbus_service.c
src/persistence_client_library_file.c
src/persistence_client_library_handle.c
src/persistence_client_library_handle.h
src/persistence_client_library_key.c
src/persistence_client_library_lc_interface.c
src/persistence_client_library_pas_interface.c
test/data/Data.tar.gz
test/persistence_admin_service_mockup.c
test/persistence_client_library_dbus_test.c
test/persistence_client_library_test.c
test/persistence_lifeCycle_mockup.c

diff --git a/config/org.genivi.persistence.admin.conf b/config/org.genivi.persistence.admin.conf
new file mode 100644 (file)
index 0000000..4058199
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE busconfig PUBLIC
+ "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+
+       <!-- Only root can own the service -->
+       <policy user="root">
+               <allow own="org.genivi.persistence.admin"/>
+               <allow send_destination="org.genivi.persistence.admin"/>
+               <allow send_interface="org.genivi.persistence.admin"/>
+       </policy>
+       <policy context="default">
+       <allow send_destination="org.genivi.persistence.admin"/>
+       <allow send_interface="org.genivi.persistence.admin"/>
+  </policy>
+</busconfig>
index df7468c..e69de29 100644 (file)
@@ -1,5 +0,0 @@
-hwinfo /usr/local/lib/libhwinfoperscustom.so
-secure /usr/local/lib/libsecureperscustom.so
-custom3 /usr/local/lib/libcustom3perscustom.so
-emergency /usr/local/lib/libemergencyperscustom.so
-early /usr/local/lib/libearlyperscustom.so
index 6087842..8db005f 100644 (file)
@@ -63,7 +63,7 @@ extern "C" {
  *
  * @return positive value: success;
  *   On error a negative value will be returned with th follwoing error codes:
- *   ::EPERS_LOCKFS, ::EPERS_NOT_INITIALIZED
+ *   ::EPERS_LOCKFS, ::EPERS_NOT_INITIALIZED, ::EPERS_INIT_DBUS_MAINLOOP,
  */
 int pclInitLibrary(const char* appname, int shutdownMode);
 
index 87042ae..fd9f403 100644 (file)
@@ -95,6 +95,13 @@ extern "C" {
 #define EPERS_NOT_INITIALIZED  (-32)
 // max buffer size
 #define EPERS_MAX_BUFF_SIZE      (-33)
+// failed to setup dbus mainloop
+#define EPERS_DBUS_MAINLOOP     (-34)
+// failed register lifecycle dbus
+#define EPERS_REGISTER_LIFECYCLE (-35)
+// failed register admin service dbus
+#define EPERS_REGISTER_ADMIN     (-36)
+
 
 #ifdef __cplusplus
 }
index 1cdd8a3..b1aa70a 100644 (file)
@@ -45,7 +45,7 @@ extern "C" {
  * @param fd the file descriptor to close
  *
  * @return zero on success. On error a negative value will be returned with th follwoing error codes:
- *                          EPERS_LOCKFS
+ *                          ::EPERS_LOCKFS, ::EPERS_MAXHANDLE
  */
 int pclFileClose(int fd);
 
index 70fe20e..a841728 100644 (file)
@@ -36,8 +36,6 @@
 
 #include <dbus/dbus.h>
 
-#define USE_DBUS 1
-
 /// debug log and trace (DLT) setup
 DLT_DECLARE_CONTEXT(gDLTContext);
 
@@ -79,7 +77,7 @@ int pclInitLibrary(const char* appName, int shutdownMode)
          gMaxKeyValDataSize = atoi(pDataSize);
       }
 
-      if(pBlacklistPath != NULL)
+      if(pBlacklistPath == NULL)
       {
          pBlacklistPath = "/etc/pclBackupBlacklist.txt";   // default path
       }
@@ -94,23 +92,20 @@ int pclInitLibrary(const char* appName, int shutdownMode)
       if( setup_dbus_mainloop() == -1)
       {
          DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to setup main loop"));
-         return -1;
+         return EPERS_DBUS_MAINLOOP;
       }
 
-#if USE_DBUS
       // register for lifecycle and persistence admin service dbus messages
       if(register_lifecycle(shutdownMode) == -1)
       {
          DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to lifecycle dbus interface"));
-         return -1;
+         return EPERS_REGISTER_LIFECYCLE;
       }
-
-      rval = register_pers_admin_service();
+      if(register_pers_admin_service() == -1)
       {
          DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to pers admin dbus interface"));
-         return -1;
+         return EPERS_REGISTER_ADMIN;
       }
-#endif
 
       /// get custom library names to load
       status = get_custom_libraries();
@@ -190,10 +185,8 @@ int pclDeinitLibrary(void)
                                            DLT_STRING("- init counter: "), DLT_INT(gPclInitialized));
 
       // unregister for lifecycle and persistence admin service dbus messages
-   #if USE_DBUS
       rval = unregister_lifecycle(gShutdownMode);
-      rval = unregister_pers_admin_service();
-   #endif
+      //rval = unregister_pers_admin_service();
 
       // unload custom client libraries
       for(i=0; i<PersCustomLib_LastEntry; i++)
index 7ce72da..8061f85 100644 (file)
@@ -166,14 +166,14 @@ int readBlacklistConfigFile(const char* filename)
    fd = open(filename, O_RDONLY);
    if (fd == -1)
    {
-      DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("configReader::readConfigFile ==> Error file open"), DLT_STRING(filename), DLT_STRING(strerror(errno)) );
+      DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("configReader::readConfigFile ==> Error file open"), DLT_STRING(filename), DLT_STRING(strerror(errno)) );
       return -1;
    }
 
    // check for empty file
    if(gConfigFileSize == 0)
    {
-      DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("configReader::readConfigFile ==> Error file size is 0:"), DLT_STRING(filename));
+      DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("configReader::readConfigFile ==> Error file size is 0:"), DLT_STRING(filename));
       close(fd);
       return -1;
    }
index 4226076..4912a5a 100644 (file)
@@ -77,7 +77,7 @@ int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* conte
 
 
 
-int pers_db_open_default(itzam_btree* btree, PersistenceInfo_s* info, const char* dbPath, int configDefault)
+int pers_db_open_default(itzam_btree* btree, const char* dbPath, int configDefault)
 {
    itzam_state  state = ITZAM_FAILED;
    char path[DbPathMaxLen] = {0};
@@ -243,7 +243,7 @@ int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned
       // --------------------------------
       if(keyFound == 0)
       {
-         if(pers_db_open_default(&btreeConfDefault, info, dbPath, 1) != -1)
+         if(pers_db_open_default(&btreeConfDefault, dbPath, 1) != -1)
          {
             if(itzam_true == itzam_btree_find(&btreeConfDefault, key, &search)) // read db
             {
@@ -273,7 +273,7 @@ int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned
       // --------------------------------
       if(keyFound == 0)
       {
-         if(pers_db_open_default(&btreeDefault, info, dbPath, 0) != -1)
+         if(pers_db_open_default(&btreeDefault, dbPath, 0) != -1)
          {
             if(itzam_true == itzam_btree_find(&btreeDefault, key, &search)) // read db
             {
@@ -302,6 +302,8 @@ int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned
             read_size = EPERS_NOPRCTABLE;
          }
       }
+
+
    }
    else if(PersistenceStorage_custom == info->configKey.storage)   // custom storage implementation via custom library
    {
@@ -389,7 +391,7 @@ int pers_db_write_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned
 
                if(PersistenceStorage_shared == info->configKey.storage)
                {
-                  pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_deleted);
+                  pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed);
                }
             }
             else
@@ -537,7 +539,7 @@ int pers_db_delete_key(char* dbPath, char* key, PersistenceInfo_s* info)
 
             if(PersistenceStorage_shared == info->configKey.storage)
             {
-               pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_changed);
+               pers_send_Notification_Signal(key, &info->context, pclNotifyStatus_deleted);
             }
          }
          else
index b073b83..248096a 100644 (file)
@@ -264,7 +264,7 @@ int setup_dbus_mainloop(void)
    {
       DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("setup_dbus_mainloop -> Use specific dbus address:"), DLT_STRING(pAddress) );
 
-      gDbusConn = dbus_connection_open(pAddress, &err);
+      gDbusConn = dbus_connection_open_private(pAddress, &err);
 
       if(gDbusConn != NULL)
       {
@@ -604,6 +604,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
          }
          close(gEfds);
       }
+      //dbus_connection_close(conn);
       dbus_connection_unref(conn);
       dbus_shutdown();
    }
index c8080ba..0809488 100644 (file)
@@ -80,7 +80,7 @@ int pclFileClose(int fd)
       }
       else
       {
-         rval = -1;
+         rval = EPERS_MAXHANDLE;
       }
    }
 
@@ -313,7 +313,7 @@ int pclFileSeek(int fd, long int offset, int whence)
 
    if(gPclInitialized >= PCLinitialized)
    {
-      if(AccessNoLock == isAccessLocked() ) // check if access to persistent data is locked
+      if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked
       {
          rval = lseek(fd, offset, whence);
       }
index 2550b41..a6a952d 100644 (file)
@@ -19,7 +19,6 @@
 
 
 #include "persistence_client_library_handle.h"
-#include "persistence_client_library_custom_loader.h"
 
 #include <pthread.h>
 #include <stdlib.h>
@@ -49,7 +48,7 @@ pthread_mutex_t gMtx;
 
 
 /// get persistence handle
-int get_persistence_handle_idx(char* dbPath, char* key, PersistenceInfo_s* info)
+int get_persistence_handle_idx()
 {
    int handle = 0;
 
@@ -61,77 +60,38 @@ int get_persistence_handle_idx(char* dbPath, char* key, PersistenceInfo_s* info)
 
    if(pthread_mutex_lock(&gMtx) == 0)
    {
-      if(   PersistenceStorage_shared == info->configKey.storage
-         || PersistenceStorage_local == info->configKey.storage)
+      if(gFreeHandleIdxHead > 0)   // check if we have a free spot in the array before the current max
       {
-         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));
-            }
-         }
+         handle = gFreeHandleArray[--gFreeHandleIdxHead];
       }
-      else if(PersistenceStorage_custom ==  info->configKey.storage)
+      else
       {
-         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) )
+         if(gHandleIdx < MaxPersHandle-1)
          {
-            int flag = 0, mode = 0;
-            handle = gPersCustomFuncs[idx].custom_plugin_handle_open(workaroundPath, flag, mode);
+            handle = gHandleIdx++;  // no free spot before current max, increment handle index
          }
          else
          {
-            handle = EPERS_NOPLUGINFUNCT;
+            handle = -1;
+            DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("get_persistence_handle_idx => Reached maximum of open handles: "), DLT_INT(MaxPersHandle));
          }
       }
       pthread_mutex_unlock(&gMtx);
    }
+
    return handle;
 }
 
 
 /// close persistence handle
-int set_persistence_handle_close_idx(int handle, char* dbPath, char* key, PersistenceInfo_s* info)
+void set_persistence_handle_close_idx(int handle)
 {
-   int rval = 0;
-
    if(pthread_mutex_lock(&gMtx) == 0)
    {
-      if(   PersistenceStorage_shared == info->configKey.storage
-         || PersistenceStorage_local == info->configKey.storage)
+      if(gFreeHandleIdxHead < MaxPersHandle)
       {
-         if(gFreeHandleIdxHead < MaxPersHandle)
-         {
-            gFreeHandleArray[gFreeHandleIdxHead++] = handle;
-         }
+         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);
    }
 }
index e1c23a6..6d56c46 100644 (file)
@@ -63,17 +63,15 @@ extern int gOpenFdArray[MaxPersHandle];
  *
  * @return a new handle or 0 if an error occured
  */
-int get_persistence_handle_idx(char* dbPath, char* key, PersistenceInfo_s* info);
+int get_persistence_handle_idx();
 
 
 /**
  * @brief close persistence handle
  *
  * @param the handle to close
- *
- * @return error code
  */
-int set_persistence_handle_close_idx(int handle, char* dbPath, char* key, PersistenceInfo_s* info);
+void set_persistence_handle_close_idx(int handle);
 
 
 
index 8afc6c5..0185f28 100644 (file)
@@ -26,7 +26,7 @@
 #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"
 
 
 // ----------------------------------------------------------------------------
@@ -56,21 +56,43 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u
       if(   (handle >= 0)
          && (dbContext.configKey.type == PersistenceResourceType_key) )          // check if type matches
       {
-         handle = get_persistence_handle_idx(dbPath, dbKey, &dbContext);
-
-         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
+         if(dbContext.configKey.storage < PersistenceStorage_LastEntry)    // check if store policy is valid
          {
-            DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleOpen: error - handleId out of bounds:"), DLT_INT(handle));
+            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  );
+
+               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));
+            }
          }
       }
       else
@@ -96,9 +118,23 @@ int pclKeyHandleClose(int key_handle)
    {
       if(key_handle < MaxPersHandle)
       {
-         rval= set_persistence_handle_close_idx(key_handle, gKeyHandleArray[key_handle].dbPath,
-                                                            gKeyHandleArray[key_handle].dbKey,
-                                                            &gKeyHandleArray[key_handle].info);
+         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);
+         }
 
          // invalidate entries
          memset(gKeyHandleArray[key_handle].dbPath, 0, DbPathMaxLen);
@@ -131,8 +167,24 @@ int pclKeyHandleGetSize(int key_handle)
    {
       if(key_handle < MaxPersHandle)
       {
-         size = pers_db_get_key_size(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey,
-                                      &gKeyHandleArray[key_handle].info);
+         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);
+         }
       }
       else
       {
@@ -149,23 +201,39 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size)
 {
    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(gPclInitialized >= PCLinitialized)
+   {
+      if(key_handle < MaxPersHandle)
       {
-         if(key_handle < MaxPersHandle)
+         if(PersistenceStorage_custom ==  gKeyHandleArray[key_handle].info.configKey.storage)
          {
-            size = pers_db_read_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey,
-                                    &gKeyHandleArray[key_handle].info, buffer, buffer_size);
+            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;
+            }
          }
          else
          {
-            size = EPERS_MAXHANDLE;
+            size = pers_db_read_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey,
+                                        &gKeyHandleArray[key_handle].info, buffer, buffer_size);
          }
       }
+      else
+      {
+         size = EPERS_MAXHANDLE;
+      }
+   }
 
-      return size;
+   return size;
 }
 
 
@@ -212,9 +280,24 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size
          {
             if(key_handle < MaxPersHandle)
             {
-
-               size = pers_db_write_key(gKeyHandleArray[key_handle].dbPath, gKeyHandleArray[key_handle].dbKey,
-                                        &gKeyHandleArray[key_handle].info, buffer, buffer_size);
+               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);
+               }
             }
             else
             {
@@ -223,8 +306,8 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size
          }
          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));
+            size = EPERS_MAX_BUFF_SIZE;
          }
       }
       else
index 4e528e3..4302165 100644 (file)
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <dlfcn.h>
 
-static int gTimeoutMs = 5000; // 5 seconds
+static int gTimeoutMs = 50000;
 
 int check_lc_request(int request, int requestID)
 {
index ce7b37c..2e0303d 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 
 
-static int gTimeoutMs = 5000; // 5 seconds
+static int gTimeoutMs = 50000;
 
 /// flag if access is locked
 static int gLockAccess = 0;
@@ -34,7 +34,8 @@ static int gLockAccess = 0;
 
 int pers_data_sync(void)
 {
-   return 1;   // TODO  implement sync data back
+   sync();
+   return 1;
 }
 
 void pers_lock_access(void)
index 25beebc..05f3398 100644 (file)
Binary files a/test/data/Data.tar.gz and b/test/data/Data.tar.gz differ
index b5ebc8f..607cbf6 100644 (file)
@@ -411,6 +411,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtableFallback, v
          }
          close(gEfds);
       }
+      //dbus_connection_close(conn);
       dbus_connection_unref(conn);
       dbus_shutdown();
    }
@@ -455,7 +456,7 @@ int setup_dbus_mainloop(void)
    if(pAddress != NULL)
    {
       printf("Use specific dbus address: %s\n !", pAddress);
-      gDbusConn = dbus_connection_open(pAddress, &err);
+      gDbusConn = dbus_connection_open_private(pAddress, &err);
 
       if(gDbusConn != NULL)
       {
index bd8957c..7b2612e 100644 (file)
@@ -49,9 +49,10 @@ int main(int argc, char *argv[])
 
    /// debug log and trace (DLT) setup
    DLT_REGISTER_APP("noty","tests the persistence client library");
-   pclInitLibrary("lt-persistence_client_library_dbus_test", shutdownReg);
-
+   ret = pclInitLibrary("lt-persistence_client_library_dbus_test", shutdownReg);
+   printf("pclInitLibrary: %d\n", ret);
 
+#if 0
    printf("Press a key to end application\n");
    ret = pclKeyHandleOpen(0xFF, "posHandle/last_position", 0, 0);
 
@@ -61,7 +62,8 @@ int main(int argc, char *argv[])
    ret = pclKeyRegisterNotifyOnChange(0x84, "links/last_link4", 4/*user_no*/, 1/*seat_no*/, &myChangeCallback);
 
    getchar();
-
+#endif
+   sleep(2);
    pclDeinitLibrary();
 
 
index cdcb93f..6b378ed 100644 (file)
@@ -63,7 +63,8 @@ START_TEST (test_GetData)
 
    unsigned char buffer[READ_SIZE] = {0};
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
    /**
     * Logical DB ID: 0xFF with user 0 and seat 0
@@ -161,7 +162,8 @@ START_TEST (test_GetDataHandle)
 
    char sysTimeBuffer[128];
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
    time_t t = time(0);
 
@@ -264,7 +266,8 @@ START_TEST(test_SetData)
 
    struct tm *locTime;
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
    time_t t = time(0);
 
@@ -374,7 +377,9 @@ START_TEST(test_SetDataNoPRCT)
    unsigned char buffer[READ_SIZE] = {0};
    struct tm *locTime;
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
+
    time_t t = time(0);
 
    char sysTimeBuffer[128];
@@ -412,11 +417,12 @@ END_TEST
  */
 START_TEST(test_GetDataSize)
 {
-   int size = 0;
+   int size = 0, ret = 0;
 
    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
    /**
     * Logical DB ID: 0xFF with user 3 and seat 2
@@ -449,7 +455,8 @@ START_TEST(test_DeleteData)
    unsigned char buffer[READ_SIZE];
    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   rval = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(rval < 0, "Failed to init PCL");
 
    // read data from key
    rval = pclKeyReadData(0xFF, "key_70", 1, 2, buffer, READ_SIZE);
@@ -503,7 +510,8 @@ START_TEST(test_DataFile)
    char* writeBuffer;
    char* fileMap = NULL;
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
    writeBuffer = malloc(writeSize);
 
@@ -594,7 +602,8 @@ START_TEST(test_DataFileRecovery)
    char* wBuffer = "This is a buffer to write";
    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
    // test backup creation --------------------------------------------
    fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
@@ -624,7 +633,8 @@ START_TEST(test_DataHandle)
    int ret = 0;
    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
    // test file handles
    handle1 = pclFileOpen(0xFF, "media/mediaDB.db", 1, 1);
@@ -634,7 +644,8 @@ START_TEST(test_DataHandle)
    fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
 
    ret = pclFileClose(1024);
-   fail_unless(ret == -1, "Could close file, but should not!!");
+   fail_unless(ret == EPERS_MAXHANDLE, "Could close file, but should not!!");
+
 
    ret = pclFileClose(17);
    fail_unless(ret == -1, "Could close file, but should not!!");
@@ -649,7 +660,7 @@ START_TEST(test_DataHandle)
    fail_unless(ret != -1, "Failed to close handle!!");
 
    ret = pclKeyHandleClose(1024);
-   fail_unless(ret == -4, "Max handle!!");
+   fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!");
 
    pclDeinitLibrary();
 }
@@ -666,7 +677,8 @@ START_TEST(test_DataHandleOpen)
    int hd1 = -2, hd2 = -2, hd3 = -2, hd4 = -2, hd5 = -2, hd6 = -2, hd7 = -2, hd8 = -2, hd9 = -2, ret = 0;
    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
    // open handles ----------------------------------------------------
    hd1 = pclKeyHandleOpen(0xFF, "posHandle/last_position1", 0, 0);
@@ -745,7 +757,8 @@ START_TEST(test_Cursor)
    char bufferDataDst[READ_SIZE] = {0};
    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
 
-   pclInitLibrary(gTheAppId, shutdownReg);
+   rval = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(rval < 0, "Failed to init PCL");
 
    // create cursor
    handle = pers_db_cursor_create("/Data/mnt-c/lt-persistence_client_library_test/cached.itz");
@@ -805,7 +818,9 @@ START_TEST(test_Plugin)
        unsigned char buffer[READ_SIZE]  = {0};
 
        unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
-       pclInitLibrary(gTheAppId, shutdownReg);
+
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
        ret = pclKeyReadData(0xFF, "language/country_code",           0, 0, buffer, READ_SIZE);
        fail_unless(ret != EPERS_NOT_INITIALIZED);
@@ -851,16 +866,18 @@ START_TEST(test_ReadDefault)
    unsigned char buffer[READ_SIZE]  = {0};
 
    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
-   pclInitLibrary(gTheAppId, shutdownReg);
+
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
    ret = pclKeyReadData(0xFF, "statusHandle/default01", 3, 2, buffer, READ_SIZE);
    fail_unless(ret != EPERS_NOT_INITIALIZED);
-   printf("B U F F E R: %s\n", buffer);
+   //printf("B U F F E R: %s\n", buffer);
    fail_unless(strncmp((char*)buffer,"DEFAULT_01!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
 
    ret = pclKeyReadData(0xFF, "statusHandle/default02", 3, 2, buffer, READ_SIZE);
    fail_unless(ret != EPERS_NOT_INITIALIZED);
-   printf("B U F F E R: %s\n", buffer);
+   //printf("B U F F E R: %s\n", buffer);
    fail_unless(strncmp((char*)buffer,"DEFAULT_02!", strlen((char*)buffer)) == 0, "Buffer not correctly read");
 
    pclDeinitLibrary();
@@ -875,7 +892,9 @@ START_TEST(test_ReadConfDefault)
    unsigned char buffer[READ_SIZE]  = {0};
 
    unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
-   pclInitLibrary(gTheAppId, shutdownReg);
+
+   ret = pclInitLibrary(gTheAppId, shutdownReg);
+   fail_unless(ret < 0, "Failed to init PCL");
 
    ret = pclKeyReadData(0xFF, "statusHandle/confdefault01",     3, 2, buffer, READ_SIZE);
    fail_unless(ret != EPERS_NOT_INITIALIZED);
@@ -951,7 +970,7 @@ static Suite * persistencyClientLib_suite()
    suite_add_tcase(s, tc_ReadDefault);
    suite_add_tcase(s, tc_ReadConfDefault);
 
-   suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
+   //suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
    return s;
 }
 
index d26cfa0..de55ead 100644 (file)
@@ -346,7 +346,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtableFallback, v
          gPollInfo.fds[0].events = POLLIN;
 
          // register for messages
-         if (   (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/NodeStateManager/LifecycleConsumer", &vtable, userData))
+         if (   (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/NodeStateManager", &vtable, userData))
              && (TRUE==dbus_connection_register_fallback(conn, "/", &vtableFallback, userData)) )
          {
             if (TRUE!=dbus_connection_set_watch_functions(conn, addWatch, removeWatch, watchToggled, NULL, NULL))
@@ -395,9 +395,9 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtableFallback, v
                                     switch (buf[0])
                                     {
                                     case CMD_REQUEST_NAME:
-                                       if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER !=dbus_bus_request_name(conn, "org.genivi.NodeStateManager.LifecycleConsumer", DBUS_NAME_FLAG_DO_NOT_QUEUE, &err))
+                                       if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER !=dbus_bus_request_name(conn, "org.genivi.NodeStateManager", DBUS_NAME_FLAG_DO_NOT_QUEUE, &err))
                                        {
-                                          fprintf(stderr, "Cannot acquire name 'org.genivi.NodeStateManager.LifeCycleConsumer': \n    \"(%s)\". Bailing out!\n", err.message);
+                                          fprintf(stderr, "Cannot acquire name 'org.genivi.NodeStateManager': \n    \"(%s)\". Bailing out!\n", err.message);
                                           dbus_error_free(&err);
                                           bContinue = FALSE;
                                        }
@@ -442,11 +442,12 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtableFallback, v
                }
                while (0!=bContinue);
             }
-            dbus_connection_unregister_object_path(conn, "/org/genivi/NodeStateManager/LifeCycleConsumer");
+            dbus_connection_unregister_object_path(conn, "/org/genivi/NodeStateManager");
             dbus_connection_unregister_object_path(conn, "/");
          }
          close(gEfds);
       }
+      //dbus_connection_close(conn);
       dbus_connection_unref(conn);
       dbus_shutdown();
    }
@@ -491,7 +492,7 @@ int setup_dbus_mainloop(void)
    if(pAddress != NULL)
    {
       printf("Use specific dbus address: %s\n !", pAddress);
-      gDbusConn = dbus_connection_open(pAddress, &err);
+      gDbusConn = dbus_connection_open_private(pAddress, &err);
 
       if(gDbusConn != NULL)
       {