summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2013-04-10 10:14:54 +0200
committerIngo Huerner <ingo.huerner@xse.de>2013-04-10 10:14:54 +0200
commit515004b1f75c8e2be7101732110c5b50ce9920f6 (patch)
tree2282dc831c8d2ee32b22769b3c42b054e8c844d1
parent80531736f0a50f65ef6af8a12d2be448bd542035 (diff)
downloadpersistence-client-library-515004b1f75c8e2be7101732110c5b50ce9920f6.tar.gz
Corrected register dbus messages
-rw-r--r--include_protected/persistence_client_library_data_organization.h5
-rw-r--r--src/persistence_client_library.c8
-rw-r--r--src/persistence_client_library_file.c31
-rw-r--r--src/persistence_client_library_key.c8
-rw-r--r--src/persistence_client_library_lc_interface.c35
-rw-r--r--src/persistence_client_library_lc_interface.h8
-rw-r--r--test/persistence_client_library_test.c22
-rw-r--r--test/persistence_lifeCycle_mockup.c71
8 files changed, 118 insertions, 70 deletions
diff --git a/include_protected/persistence_client_library_data_organization.h b/include_protected/persistence_client_library_data_organization.h
index 3ed3a11..f6fd120 100644
--- a/include_protected/persistence_client_library_data_organization.h
+++ b/include_protected/persistence_client_library_data_organization.h
@@ -24,7 +24,7 @@
extern "C" {
#endif
-#define PERSIST_CLIENT_LIBRARY_DATA_ORGANIZATION_INTERFACE_VERSION (0x01000000U)
+#define PERSIST_CLIENT_LIBRARY_DATA_ORGANIZATION_INTERFACE_VERSION (0x01100000U)
#include "../include/persistence_client_library_error_def.h"
#include "../include/persistence_client_library_key.h"
@@ -77,6 +77,9 @@ enum _PersistenceConstantDef
MaxConfKeyLengthCusName = 32, /// length of the config key custom name
MaxRctLengthCustom_ID = 64, /// length of the customer ID
+ NSM_SHUTDOWN_TYPE_FAST = 2, /// Client registered for fast shutdown
+ NSM_SHUTDOWN_TYPE_NORMAL = 1, /// Client registered for normal shutdown
+
defaultMaxKeyValDataSize = 16384 /// default limit the key-value data size to 16kB
};
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index 270d126..a720692 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -55,6 +55,7 @@ void pers_library_init(void)
{
int status = 0;
int i = 0;
+ int shutdownMode = NSM_SHUTDOWN_TYPE_NORMAL;
DLT_REGISTER_APP("Persistence Client Library","persClientLib");
DLT_REGISTER_CONTEXT(persClientLibCtx,"persClientLib","Context for Logging");
@@ -76,7 +77,7 @@ void pers_library_init(void)
setup_dbus_mainloop();
// register for lifecycle and persistence admin service dbus messages
- register_lifecycle();
+ register_lifecycle(shutdownMode);
register_pers_admin_service();
#endif
@@ -124,7 +125,7 @@ void pers_library_init(void)
}
}
- //printf("A p p l i c a t i o n n a m e => %s \n", __progname /*program_invocation_short_name*/); // TODO: only temp solution for application name
+ printf("A p p l i c a t i o n n a m e => %s \n", __progname /*program_invocation_short_name*/); // TODO: only temp solution for application name
strncpy(gAppId, __progname, MaxAppNameLen);
gAppId[MaxAppNameLen-1] = '\0';
@@ -137,10 +138,11 @@ void pers_library_init(void)
void pers_library_destroy(void)
{
+ int shutdownMode = NSM_SHUTDOWN_TYPE_NORMAL;
#if ENABLE_DBUS_INTERFACE == 1
// unregister for lifecycle and persistence admin service dbus messages
- unregister_lifecycle();
+ unregister_lifecycle(shutdownMode);
unregister_pers_admin_service();
#endif
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index e72b0c9..6c65d00 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -138,7 +138,7 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
if(dbContext.configKey.permission != PersistencePermission_ReadOnly)
{
snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~");
- snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, ".cs");
+ snprintf(csumPath, DbPathMaxLen, "%s%s", dbPath, "~.crc");
if((handle = pcl_verify_consistency(dbPath, backupPath, csumPath, flags)) == -1)
{
@@ -423,15 +423,13 @@ int pcl_verify_consistency(const char* origPath, const char* backupPath, const c
if(handle != -1)
{
pcl_calc_crc32_checksum(handle, origCsumBuf);
- if(strcmp(csumBuf, origCsumBuf) == 0)
- {
- // checksum matches ==> keep original file
- }
- else
+ if(strcmp(csumBuf, origCsumBuf) != 0)
{
close(handle);
handle = -1; // error: file corrupt
}
+ // else case: checksum matches ==> keep original file ==> nothing to do
+
}
else
{
@@ -442,7 +440,7 @@ int pcl_verify_consistency(const char* origPath, const char* backupPath, const c
}
else
{
- printf("verifyConsistency ==> checksum invalid size\n");
+ printf("verifyConsistency ==> checksum has invalid size\n");
}
close(fdCsum);
}
@@ -475,19 +473,18 @@ int pcl_verify_consistency(const char* origPath, const char* backupPath, const c
}
close(fdCsum);
- // calculate the checksum form the original file
+ // calculate the checksum form the original file to see if it matches
handle = open(origPath, flags);
if(handle != -1)
{
pcl_calc_crc32_checksum(handle, origCsumBuf);
- // checksum does NOT match ==> error: file corrupt
- // checksum matches ==> keep original file
if(strcmp(csumBuf, origCsumBuf) != 0)
{
close(handle);
- handle = -1; // error: file corrupt
+ handle = -1; // checksum does NOT match ==> error: file corrupt
}
+ // else case: checksum matches ==> keep original file ==> nothing to do
}
else
{
@@ -514,23 +511,19 @@ int pcl_verify_consistency(const char* origPath, const char* backupPath, const c
pcl_calc_crc32_checksum(fdBackup, backCsumBuf);
close(fdBackup);
- // calculate the checksum form the original file
+ // calculate the checksum form the original file to see if it matches
handle = open(origPath, flags);
if(handle != -1)
{
pcl_calc_crc32_checksum(handle, origCsumBuf);
- // checksum does NOT match ==> error: file corrupt
- // if checksum matches ==> keep original file
if(strcmp(backCsumBuf, origCsumBuf) != 0)
{
close(handle);
- handle = -1; // error: file corrupt
+ handle = -1; // checksum does NOT match ==> error: file corrupt
}
- /*else
- {
- printf(" original file is OK, keep it\n");
- }*/
+ // else case: checksum matches ==> keep original file ==> nothing to do
+
}
else
{
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index 4f58c68..1469d72 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -117,7 +117,7 @@ int pclKeyHandleClose(int key_handle)
if( (idx < PersCustomLib_LastEntry) && (gPersCustomFuncs[idx].custom_plugin_handle_close) )
{
- gPersCustomFuncs[idx].custom_plugin_handle_close(key_handle);
+ rval = gPersCustomFuncs[idx].custom_plugin_handle_close(key_handle);
}
else
{
@@ -156,7 +156,7 @@ int pclKeyHandleGetSize(int key_handle)
if(idx < PersCustomLib_LastEntry && &(gPersCustomFuncs[idx].custom_plugin_get_size) != NULL)
{
- gPersCustomFuncs[idx].custom_plugin_get_size(gKeyHandleArray[key_handle].dbPath);
+ size = gPersCustomFuncs[idx].custom_plugin_get_size(gKeyHandleArray[key_handle].dbPath);
}
else
{
@@ -186,7 +186,7 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size)
if(idx < PersCustomLib_LastEntry && &(gPersCustomFuncs[idx].custom_plugin_handle_get_data) != NULL)
{
- gPersCustomFuncs[idx].custom_plugin_handle_get_data(key_handle, (char*)buffer, buffer_size-1);
+ size = gPersCustomFuncs[idx].custom_plugin_handle_get_data(key_handle, (char*)buffer, buffer_size-1);
}
else
{
@@ -238,7 +238,7 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size
if(idx < PersCustomLib_LastEntry && *gPersCustomFuncs[idx].custom_plugin_handle_set_data != NULL)
{
- gPersCustomFuncs[idx].custom_plugin_handle_set_data(key_handle, (char*)buffer, buffer_size-1);
+ size = gPersCustomFuncs[idx].custom_plugin_handle_set_data(key_handle, (char*)buffer, buffer_size-1);
}
else
{
diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c
index 3783a5a..0a6cc50 100644
--- a/src/persistence_client_library_lc_interface.c
+++ b/src/persistence_client_library_lc_interface.c
@@ -156,7 +156,7 @@ DBusHandlerResult checkLifecycleMsg(DBusConnection * connection, DBusMessage * m
-int send_lifecycle_register(const char* method, int shutdownMode)
+int send_lifecycle_register(const char* method, int shutdownMode, int reg)
{
int rval = 0;
@@ -168,16 +168,25 @@ int send_lifecycle_register(const char* method, int shutdownMode)
const char* busName = dbus_bus_get_unique_name(conn);
DBusMessage* message = dbus_message_new_method_call("org.genivi.NodeStateManager", // destination
- "/org/genivi/NodeStateManager", // path
+ "/org/genivi/NodeStateManager/Consumer", // path
"org.genivi.NodeStateManager.Consumer", // interface
method); // method
if(message != NULL)
{
- dbus_message_append_args(message, DBUS_TYPE_STRING, &busName,
- DBUS_TYPE_STRING, &objName,
- DBUS_TYPE_INT32, &shutdownMode,
- DBUS_TYPE_INT32, &gTimeoutMs,
- DBUS_TYPE_INVALID);
+ if(reg == 1) // register
+ {
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &busName,
+ DBUS_TYPE_STRING, &objName,
+ DBUS_TYPE_INT32, &shutdownMode,
+ DBUS_TYPE_UINT32, &gTimeoutMs, DBUS_TYPE_INVALID);
+ }
+ else // unregister
+ {
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &busName,
+ DBUS_TYPE_STRING, &objName,
+ DBUS_TYPE_INT32, &shutdownMode, DBUS_TYPE_INVALID);
+
+ }
if(conn != NULL)
{
@@ -248,20 +257,16 @@ int send_lifecycle_request(const char* method, int requestId, int status)
-int register_lifecycle()
+int register_lifecycle(int shutdownMode)
{
- int shutdownMode = 1; // TODO send correct mode
-
- return send_lifecycle_register("RegisterShutdownClient", shutdownMode);
+ return send_lifecycle_register("RegisterShutdownClient", shutdownMode, 1);
}
-int unregister_lifecycle()
+int unregister_lifecycle(int shutdownMode)
{
- int shutdownMode = 1; // TODO send correct mode
-
- return send_lifecycle_register("UnRegisterShutdownClient", shutdownMode);
+ return send_lifecycle_register("UnRegisterShutdownClient", shutdownMode, 0);
}
diff --git a/src/persistence_client_library_lc_interface.h b/src/persistence_client_library_lc_interface.h
index 64332f4..e0ae5ee 100644
--- a/src/persistence_client_library_lc_interface.h
+++ b/src/persistence_client_library_lc_interface.h
@@ -37,17 +37,21 @@ DBusHandlerResult checkLifecycleMsg(DBusConnection * connection, DBusMessage * m
/**
* @brief send register message 'RegisterShutdownClient' to com.contiautomotive.NodeStateManager.Consumer
*
+ * @param the shutdown mode: NSM_SHUTDOWN_TYPE_NORMAL or NSM_SHUTDOWN_TYPE_FAST;
+ *
* @return 0 on success or -1 on error
*/
-int register_lifecycle();
+int register_lifecycle(int shutdownMode);
/**
* @brief send register message 'UnRegisterShutdownClient' to com.contiautomotive.NodeStateManager.Consumer
*
+ * @param the shutdown mode: NSM_SHUTDOWN_TYPE_NORMAL or NSM_SHUTDOWN_TYPE_FAST;
+ *
* @return 0 on success or -1 on error
*/
-int unregister_lifecycle();
+int unregister_lifecycle(int shutdownMode);
/**
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index 83c0213..56fd931 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -459,13 +459,12 @@ END_TEST
*/
START_TEST(test_DataFile)
{
- int fd = 0, i = 0, idx = 0, fd_RW = 0, fd_RO = 0;
+ int fd = 0, i = 0, idx = 0;
int size = 0, ret = 0;
int writeSize = 16*1024;
unsigned char buffer[READ_SIZE];
const char* refBuffer = "/Data/mnt-wt/lt-persistence_client_library_test/user/1/seat/1/media";
char* writeBuffer;
- char* wBuffer = "This is a buffer to write";
char* fileMap = NULL;
writeBuffer = malloc(writeSize);
@@ -541,6 +540,18 @@ START_TEST(test_DataFile)
ret = pclFileClose(fd);
fail_unless(ret == 0, "Failed to close file");
+ free(writeBuffer);
+}
+END_TEST
+
+
+
+
+START_TEST(test_DataFileRecovery)
+{
+ int fd_RW = 0, fd_RO = 0;
+ int ret = 0;
+ char* wBuffer = "This is a buffer to write";
// test backup creation --------------------------------------------
fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
@@ -553,12 +564,9 @@ START_TEST(test_DataFile)
ret = pclFileClose(fd_RW);
ret = pclFileClose(fd_RO);
- free(writeBuffer);
}
END_TEST
-
-
/*
* The the handle function of the key and file interface.
*/
@@ -767,6 +775,9 @@ static Suite * persistencyClientLib_suite()
TCase * tc_persDataFile = tcase_create("DataFile");
tcase_add_test(tc_persDataFile, test_DataFile);
+ TCase * tc_persDataFileRecovery = tcase_create("DataFileRecovery");
+ tcase_add_test(tc_persDataFileRecovery, test_DataFileRecovery);
+
TCase * tc_Cursor = tcase_create("Cursor");
tcase_add_test(tc_Cursor, test_Cursor);
@@ -779,6 +790,7 @@ static Suite * persistencyClientLib_suite()
suite_add_tcase(s, tc_persDataHandle);
suite_add_tcase(s, tc_persDataHandleOpen);
suite_add_tcase(s, tc_persDataFile);
+ suite_add_tcase(s, tc_persDataFileRecovery);
suite_add_tcase(s, tc_Cursor);
return s;
diff --git a/test/persistence_lifeCycle_mockup.c b/test/persistence_lifeCycle_mockup.c
index f6a1458..1438837 100644
--- a/test/persistence_lifeCycle_mockup.c
+++ b/test/persistence_lifeCycle_mockup.c
@@ -90,7 +90,7 @@ void sigHandler(int signo)
-int checkAdminMsg(DBusConnection *connection, DBusMessage *message)
+int checkAdminMsg(DBusConnection *connection, DBusMessage *message, int reg)
{
char* busName = NULL;
char* objName = NULL;
@@ -102,29 +102,58 @@ int checkAdminMsg(DBusConnection *connection, DBusMessage *message)
DBusError error;
dbus_error_init (&error);
- if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &busName, // bus name
- DBUS_TYPE_STRING, &objName,
- DBUS_TYPE_INT32, &notificationFlag,
- DBUS_TYPE_UINT32, &gTimeoutMs,
- DBUS_TYPE_INVALID))
+ if(reg == 1)
{
- reply = dbus_message_new_error(message, error.name, error.message);
-
- if (reply == 0)
+ if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &busName, // bus name
+ DBUS_TYPE_STRING, &objName,
+ DBUS_TYPE_INT32, &notificationFlag,
+ DBUS_TYPE_UINT32, &gTimeoutMs,
+ DBUS_TYPE_INVALID))
{
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
- }
+ reply = dbus_message_new_error(message, error.name, error.message);
- if (!dbus_connection_send(connection, reply, 0))
- {
- //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
- printf("DBus No memory\n");
+ if (reply == 0)
+ {
+ //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
+ printf("DBus No memory\n");
+ }
+
+ if (!dbus_connection_send(connection, reply, 0))
+ {
+ //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
+ printf("DBus No memory\n");
+ }
+
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
+ }
+ else if(reg == 0)
+ {
+ if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &busName, // bus name
+ DBUS_TYPE_STRING, &objName,
+ DBUS_TYPE_INT32, &notificationFlag,
+ DBUS_TYPE_INVALID))
+ {
+ reply = dbus_message_new_error(message, error.name, error.message);
+
+ if (reply == 0)
+ {
+ //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
+ printf("DBus No memory\n");
+ }
- dbus_message_unref(reply);
+ if (!dbus_connection_send(connection, reply, 0))
+ {
+ //DLT_LOG(mgrContext, DLT_LOG_ERROR, DLT_STRING("DBus No memory"));
+ printf("DBus No memory\n");
+ }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
}
@@ -168,19 +197,19 @@ DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * m
{
printf(" ==> org.genivi.NodeStateManager.Consumer - received - ==> RegisterShutdownClient \n");
- result = checkAdminMsg(connection, message);
+ result = checkAdminMsg(connection, message, 1);
}
else if((0==strcmp("UnRegisterShutdownClient", dbus_message_get_member(message))))
{
printf(" ==> org.genivi.NodeStateManager.Consumer - received - ==> UnRegisterShutdownClient \n");
- result = checkAdminMsg(connection, message);
+ result = checkAdminMsg(connection, message, 0);
}
else if((0==strcmp("LifecycleRequestComplete", dbus_message_get_member(message))))
{
printf(" ==> org.genivi.NodeStateManager.Consumer - received - ==> LifecycleRequestComplete \n");
- result = checkAdminMsg(connection, message);
+ result = checkAdminMsg(connection, message, 0);
}
else