summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo.huerner@xse.de>2014-04-16 15:31:59 +0200
committerIngo Huerner <ingo.huerner@xse.de>2014-04-16 15:31:59 +0200
commit7a40679af6e3c6e1093f49139d92081f619228a9 (patch)
tree80b7c1ab36889c0a98f11edf84e1855a322773af
parentec56747849e789c554e3707fc5b8b27bb780ca89 (diff)
downloadpersistence-client-library-7a40679af6e3c6e1093f49139d92081f619228a9.tar.gz
Added pclLifecycleSet function
-rw-r--r--include/persistence_client_library.h32
-rw-r--r--include/persistence_client_library_error_def.h34
-rw-r--r--src/persistence_client_library.c47
-rw-r--r--src/persistence_client_library_data_organization.h4
-rw-r--r--src/persistence_client_library_dbus_cmd.c53
-rw-r--r--src/persistence_client_library_dbus_cmd.h5
-rw-r--r--src/persistence_client_library_dbus_service.c2
7 files changed, 128 insertions, 49 deletions
diff --git a/include/persistence_client_library.h b/include/persistence_client_library.h
index 4370158..29bbcb1 100644
--- a/include/persistence_client_library.h
+++ b/include/persistence_client_library.h
@@ -49,10 +49,12 @@ extern "C" {
* \{
*/
+#define PCL_SHUTDOWN 1 /// trigger shutdown
+#define PCL_SHUTDOWN_CANEL 0 // cancel shutdown
-#define PCL_SHUTDOWN_TYPE_FAST 2 /// Client registered for fast lifecycle shutdown
-#define PCL_SHUTDOWN_TYPE_NORMAL 1 /// Client registered for normal lifecycle shutdown
-#define PCL_SHUTDOWN_TYPE_NONE 0 /// Client does not register to lifecycle shutdown
+#define PCL_SHUTDOWN_TYPE_FAST 2 /// Client registered for fast lifecycle shutdown
+#define PCL_SHUTDOWN_TYPE_NORMAL 1 /// Client registered for normal lifecycle shutdown
+#define PCL_SHUTDOWN_TYPE_NONE 0 /// Client does not register to lifecycle shutdown
/**
@@ -65,7 +67,7 @@ extern "C" {
* @param shutdownMode shutdown mode ::PCL_SHUTDOWN_TYPE_FAST or ::PCL_SHUTDOWN_TYPE_NORMAL
*
* @return positive value: success;
- * On error a negative value will be returned with th following error codes:
+ * On error a negative value will be returned with the following error codes:
* ::EPERS_NOT_INITIALIZED, ::EPERS_INIT_DBUS_MAINLOOP,
* ::EPERS_REGISTER_LIFECYCLE, ::EPERS_REGISTER_ADMIN
*/
@@ -83,6 +85,28 @@ int pclInitLibrary(const char* appname, int shutdownMode);
*/
int pclDeinitLibrary(void);
+
+
+
+/**
+ * @brief pclLifecycleSet client library
+ * This function can be called if to flush and write back the data form cache to memory device.
+ * The function is only available if PCL_SHUTDOWN_TYPE_NONE has been used in pclInitLibrary.
+ *
+ * @attention This function is currently N O T part of the GENIVI compliance specification
+ * @attention In order to prevent misuse of this function the cancel shutdown request
+ * can only be called 3 times per lifecycle.
+ *
+ * @parm PCL_SHUTDOWN for write back data when shutdown is requested,
+ * and PCL_SHUTDOWN_CANEL when shutdown cancel request has been received.
+ *
+ * @return positive value: success;
+ * On error a negative value will be returned with the following error codes:
+ * ::EPERS_COMMON, :.EPERS_MAX_CANCEL_SHUTDOWN, ::EPERS_SHTDWN_NO_PERMIT
+ */
+int pclLifecycleSet(int shutdown);
+
+
/** \} */
#ifdef __cplusplus
diff --git a/include/persistence_client_library_error_def.h b/include/persistence_client_library_error_def.h
index 04bbf0f..d8de109 100644
--- a/include/persistence_client_library_error_def.h
+++ b/include/persistence_client_library_error_def.h
@@ -51,17 +51,17 @@ extern "C" {
#define EPERS_OPENFILE (-10)
/// invalid buffer or key
#define EPERS_DESER_BUFORKEY (-11)
-/// can't allocat memory for deserialization of keyvalue
+/// can't allocate memory for deserialization of key/value
#define EPERS_DESER_ALLOCMEM (-12)
-/// no ploicy avaliable in data to serialize
+/// no ploicy available in data to serialize
#define EPERS_DESER_POLICY (-13)
-/// no store type avaliable in data to serialize
+/// no store type available in data to serialize
#define EPERS_DESER_STORE (-14)
-/// no permission avaliable in data to serialize
+/// no permission available in data to serialize
#define EPERS_DESER_PERM (-15)
-/// no max size avaliable in data to serialize
+/// no max size available in data to serialize
#define EPERS_DESER_MAXSIZE (-16)
-/// no responsibility avaliable in data to serialize
+/// no responsibility available in data to serialize
#define EPERS_DESER_RESP (-17)
/// out of array bounds
#define EPERS_OUTOFBOUNDS (-18)
@@ -71,7 +71,7 @@ extern "C" {
#define EPERS_CONFIGNOTAVAILABLE (-20)
/// can't stat config file
#define EPERS_CONFIGNOSTAT (-21)
-/// plugin functin not found
+/// plugin function not found
#define EPERS_NOPLUGINFCNT (-22)
/// dlopen error
#define EPERS_DLOPENERROR (-23)
@@ -79,7 +79,7 @@ extern "C" {
#define EPERS_NOPLUGINFUNCT (-24)
/// file remove error
#define EPERS_FILEREMOVE (-25)
-/// err code to signalize last entry in DB
+/// err code to signalizes last entry in DB
#define EPERS_LAST_ENTRY_IN_DB (-26)
/// internal database error
#define EPERS_DB_ERROR_INTERNAL (-27)
@@ -93,20 +93,24 @@ extern "C" {
#define EPERS_NOTIFY_SIG (-31)
/// client library has not been initialized
#define EPERS_NOT_INITIALIZED (-32)
-// max buffer size
+/// max buffer size
#define EPERS_MAX_BUFF_SIZE (-33)
-// failed to setup dbus mainloop
+/// failed to setup dbus mainloop
#define EPERS_DBUS_MAINLOOP (-34)
-// failed register lifecycle dbus
+/// failed register lifecycle dbus
#define EPERS_REGISTER_LIFECYCLE (-35)
-// failed register admin service dbus
+/// failed register admin service dbus
#define EPERS_REGISTER_ADMIN (-36)
-// registration on this key is not allowed
+/// registration on this key is not allowed
#define EPERS_NOTIFY_NOT_ALLOWED (-37)
-// the requested resource is not a file
+/// the requested resource is not a file
#define EPERS_RESOURCE_NO_FILE (-38)
-// write to requested resource failed, read onyl resource
+/// write to requested resource failed, read only resource
#define EPERS_RESOURCE_READ_ONLY (-39)
+/// max numbers of cancel shutdown exceeded
+#define EPERS_SHTDWN_MAX_CANCEL (-40)
+/// not permitted to use this function
+#define EPERS_SHTDWN_NO_PERMIT (-42)
#ifdef __cplusplus
}
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index 9c22464..dead553 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -42,6 +42,8 @@ DLT_DECLARE_CONTEXT(gPclDLTContext);
static int gShutdownMode = 0;
+static int gCancelCounter = 0;
+
int pclInitLibrary(const char* appName, int shutdownMode)
{
@@ -172,6 +174,8 @@ int pclInitLibrary(const char* appName, int shutdownMode)
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclInit => Failed to load custom library config table => error number:"), DLT_INT(status));
}
+ pers_unlock_access();
+
// assign application name
strncpy(gAppId, appName, MaxAppNameLen);
gAppId[MaxAppNameLen-1] = '\0';
@@ -221,14 +225,7 @@ int pclDeinitLibrary(void)
}
}
- // close all apend rct
- pers_rct_close_all();
-
- // close opend database
- database_close_all();
-
- // close persistence handles
- close_all_persistence_handle();
+ process_prepare_shutdown(Shutdown_Full); // close all db and fd's and block access
// end dbus library
bContinue = 0;
@@ -261,6 +258,40 @@ int pclDeinitLibrary(void)
+int pclLifecycleSet(int shutdown)
+{
+ int rval = 0;
+
+ if(gShutdownMode == PCL_SHUTDOWN_TYPE_NONE)
+ {
+ if(PCL_SHUTDOWN)
+ {
+ process_prepare_shutdown(Shutdown_Partial); // close all db and fd's and block access
+ }
+ else if(PCL_SHUTDOWN_CANEL)
+ {
+ if(gCancelCounter < Shutdown_MaxCount)
+ {
+ pers_unlock_access();
+ }
+ else
+ {
+ rval = EPERS_SHTDWN_MAX_CANCEL;
+ }
+ }
+ else
+ {
+ rval = EPERS_COMMON;
+ }
+ }
+ else
+ {
+ rval = EPERS_SHTDWN_NO_PERMIT;
+ }
+
+return rval;
+}
+
diff --git a/src/persistence_client_library_data_organization.h b/src/persistence_client_library_data_organization.h
index 21075b4..22852b5 100644
--- a/src/persistence_client_library_data_organization.h
+++ b/src/persistence_client_library_data_organization.h
@@ -100,6 +100,10 @@ enum _PersistenceConstantDef
FileClosed = 0, /// flag to identify if file will be closed
FileOpen = 1, /// flag to identify if file has been opend
+ Shutdown_Partial = 0, /// make partial Shutdown (close but not free everything)
+ Shutdown_Full = 1, /// make complete Shutdown (close and free everything)
+ Shutdown_MaxCount = 3, /// max number of shutdown cancel calls
+
NsmShutdownNormal = 1, /// lifecycle shutdown normal
NsmErrorStatus_OK = 1, /// lifecycle return OK idicator
NsmErrorStatus_Fail = -1, /// lifecycle return failed indicator
diff --git a/src/persistence_client_library_dbus_cmd.c b/src/persistence_client_library_dbus_cmd.c
index e64dfe8..56ca999 100644
--- a/src/persistence_client_library_dbus_cmd.c
+++ b/src/persistence_client_library_dbus_cmd.c
@@ -26,6 +26,7 @@
#include "persistence_client_library_db_access.h"
#include <dlfcn.h>
+#include <errno.h>
// function prototype
@@ -168,12 +169,9 @@ void process_block_and_write_data_back(unsigned int requestID, unsigned int stat
-void process_prepare_shutdown(unsigned char requestId, unsigned int status)
+void process_prepare_shutdown(int complete)
{
- int i = 0;
-
- (void)requestId;
- (void)status;
+ int i = 0, rval = 0;
// block write
pers_lock_access();
@@ -185,7 +183,20 @@ void process_prepare_shutdown(unsigned char requestId, unsigned int status)
if(gOpenFdArray[tmp] == FileOpen)
{
fsync(tmp);
- close(tmp);
+
+#if USE_FILECACHE
+ rval = pfcCloseFile(tmp);
+#else
+ if(complete > 0)
+ {
+ rval = close(tmp);
+ }
+#endif
+ if(rval == -1)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("process_prepare_shutdown => failed to close file: "), DLT_STRING(strerror(errno)) );
+ }
+
}
}
@@ -195,19 +206,27 @@ void process_prepare_shutdown(unsigned char requestId, unsigned int status)
// close opend database
database_close_all();
-
- // unload custom client libraries
- for(i=0; i<PersCustomLib_LastEntry; i++)
+ if(complete > 0)
{
- if(gPersCustomFuncs[i].custom_plugin_deinit != NULL)
- {
- // deinitialize plugin
- gPersCustomFuncs[i].custom_plugin_deinit();
- // close library handle
- dlclose(gPersCustomFuncs[i].handle);
+ close_all_persistence_handle();
+ }
- invalidate_custom_plugin(i);
- }
+
+ if(complete > 0)
+ {
+ // unload custom client libraries
+ for(i=0; i<PersCustomLib_LastEntry; i++)
+ {
+ if(gPersCustomFuncs[i].custom_plugin_deinit != NULL)
+ {
+ // deinitialize plugin
+ gPersCustomFuncs[i].custom_plugin_deinit();
+ // close library handle
+ dlclose(gPersCustomFuncs[i].handle);
+
+ invalidate_custom_plugin(i);
+ }
+ }
}
}
diff --git a/src/persistence_client_library_dbus_cmd.h b/src/persistence_client_library_dbus_cmd.h
index d227e86..99d2be6 100644
--- a/src/persistence_client_library_dbus_cmd.h
+++ b/src/persistence_client_library_dbus_cmd.h
@@ -25,11 +25,8 @@
/**
* @brief process a shutdown message (close all open files, open databases, ...
- *
- * @param requestId the requestID
- * @param status the status
*/
-void process_prepare_shutdown(unsigned char requestId, unsigned int status);
+void process_prepare_shutdown(int complete);
/**
diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c
index 694cd6a..f7a0538 100644
--- a/src/persistence_client_library_dbus_service.c
+++ b/src/persistence_client_library_dbus_service.c
@@ -600,7 +600,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
process_send_pas_request(conn, (buf[2]), buf[1]);
break;
case CMD_LC_PREPARE_SHUTDOWN:
- process_prepare_shutdown((buf[2]), buf[1]);
+ process_prepare_shutdown(Shutdown_Full);
process_send_lifecycle_request(conn, (buf[2]), buf[1]);
break;
case CMD_SEND_NOTIFY_SIGNAL: