Fix deadlock part II
authorIngo Huerner <ingo.huerner@xse.de>
Thu, 28 Nov 2013 11:59:59 +0000 (12:59 +0100)
committerIngo Huerner <ingo.huerner@xse.de>
Thu, 28 Nov 2013 11:59:59 +0000 (12:59 +0100)
src/persistence_client_library.c
src/persistence_client_library_custom_loader.c
src/persistence_client_library_custom_loader.h
src/persistence_client_library_dbus_cmd.c
src/persistence_client_library_dbus_service.c
src/persistence_client_library_dbus_service.h
src/persistence_client_library_lc_interface.c
src/persistence_client_library_pas_interface.c
test/persistence_admin_service_mockup.c
test/persistence_lifeCycle_mockup.c

index 3c70f02..ac1c830 100644 (file)
@@ -45,9 +45,6 @@ extern int bContinue;
 
 static int gShutdownMode = 0;
 
-/// loical function declaration
-void invalidateCustomPlugin(int idx);
-
 
 int pclInitLibrary(const char* appName, int shutdownMode)
 {
@@ -118,7 +115,7 @@ int pclInitLibrary(const char* appName, int shutdownMode)
          // initialize custom library structure
          for(i = 0; i < PersCustomLib_LastEntry; i++)
          {
-            invalidateCustomPlugin(i);
+            invalidate_custom_plugin(i);
          }
 
          if(pOnDemandLoad == NULL)  // load all available libraries now
@@ -206,7 +203,7 @@ int pclDeinitLibrary(void)
             // close library handle
             dlclose(gPersCustomFuncs[i].handle);
 
-            invalidateCustomPlugin(i);
+            invalidate_custom_plugin(i);
          }
       }
 
@@ -230,27 +227,6 @@ int pclDeinitLibrary(void)
 
 
 
-void invalidateCustomPlugin(int idx)
-{
-   gPersCustomFuncs[idx].handle  = NULL;
-   gPersCustomFuncs[idx].custom_plugin_init = NULL;
-   gPersCustomFuncs[idx].custom_plugin_deinit = NULL;
-   gPersCustomFuncs[idx].custom_plugin_handle_open = NULL;
-   gPersCustomFuncs[idx].custom_plugin_handle_close = NULL;
-   gPersCustomFuncs[idx].custom_plugin_handle_get_data = NULL;
-   gPersCustomFuncs[idx].custom_plugin_handle_set_data  = NULL;
-   gPersCustomFuncs[idx].custom_plugin_get_data = NULL;
-   gPersCustomFuncs[idx].custom_plugin_set_data = NULL;
-   gPersCustomFuncs[idx].custom_plugin_delete_data = NULL;
-   gPersCustomFuncs[idx].custom_plugin_get_status_notification_clbk = NULL;
-   gPersCustomFuncs[idx].custom_plugin_handle_get_size = NULL;
-   gPersCustomFuncs[idx].custom_plugin_get_size = NULL;
-   gPersCustomFuncs[idx].custom_plugin_create_backup = NULL;
-   gPersCustomFuncs[idx].custom_plugin_get_backup = NULL;
-   gPersCustomFuncs[idx].custom_plugin_restore_backup = NULL;
-}
-
-
 
 
 
index ae8ad36..14c48ca 100644 (file)
@@ -415,3 +415,25 @@ int check_valid_idx(int idx)
 
    return rval;
 }
+
+
+
+void invalidate_custom_plugin(int idx)
+{
+   gPersCustomFuncs[idx].handle  = NULL;
+   gPersCustomFuncs[idx].custom_plugin_init = NULL;
+   gPersCustomFuncs[idx].custom_plugin_deinit = NULL;
+   gPersCustomFuncs[idx].custom_plugin_handle_open = NULL;
+   gPersCustomFuncs[idx].custom_plugin_handle_close = NULL;
+   gPersCustomFuncs[idx].custom_plugin_handle_get_data = NULL;
+   gPersCustomFuncs[idx].custom_plugin_handle_set_data  = NULL;
+   gPersCustomFuncs[idx].custom_plugin_get_data = NULL;
+   gPersCustomFuncs[idx].custom_plugin_set_data = NULL;
+   gPersCustomFuncs[idx].custom_plugin_delete_data = NULL;
+   gPersCustomFuncs[idx].custom_plugin_get_status_notification_clbk = NULL;
+   gPersCustomFuncs[idx].custom_plugin_handle_get_size = NULL;
+   gPersCustomFuncs[idx].custom_plugin_get_size = NULL;
+   gPersCustomFuncs[idx].custom_plugin_create_backup = NULL;
+   gPersCustomFuncs[idx].custom_plugin_get_backup = NULL;
+   gPersCustomFuncs[idx].custom_plugin_restore_backup = NULL;
+}
index 3bd0c12..b1b90fe 100644 (file)
@@ -170,4 +170,10 @@ int check_valid_idx(int idx);
 char* get_custom_client_lib_name(int idx);
 
 
+/**
+ * @brief invalidate customer plugin function
+ */
+void invalidate_custom_plugin(int idx);
+
+
 #endif /* PERSISTENCE_CLIENT_LIBRARY_CUSTOM_LOADER_H */
index dc1e5ff..c95a20d 100644 (file)
@@ -162,7 +162,7 @@ void process_block_and_write_data_back(unsigned int requestID, unsigned int stat
    // sync data back to memory device
    pers_data_sync();
    // send complete notification
-   pers_admin_service_data_sync_complete(requestID, status);
+   //pers_admin_service_data_sync_complete(requestID, status);
 }
 
 
@@ -217,12 +217,12 @@ void process_prepare_shutdown(unsigned char requestId, unsigned int status)
          // close library handle
          dlclose(gPersCustomFuncs[i].handle);
 
-         gPersCustomFuncs[i].custom_plugin_deinit = NULL;
+         invalidate_custom_plugin(i);
       }
    }
 
    // notify lifecycle shutdown OK
-   send_prepare_shutdown_complete((int)requestId, (int)status);
+   //send_prepare_shutdown_complete((int)requestId, (int)status);
 }
 
 
index 81963bd..692e98b 100644 (file)
@@ -36,7 +36,7 @@ pthread_mutex_t gDbusPendingRegMtx   = PTHREAD_MUTEX_INITIALIZER;
 pthread_mutex_t gMainLoopMtx         = PTHREAD_MUTEX_INITIALIZER;
 pthread_cond_t  gMainLoopCond = PTHREAD_COND_INITIALIZER;
 
-int gEfds;
+int gEfds;  // communication channel int dbus mainloop
 
 
 typedef enum EDBusObjectType
@@ -574,11 +574,11 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
                                     {
                                        case CMD_PAS_BLOCK_AND_WRITE_BACK:
                                           process_block_and_write_data_back((buf[2]), buf[1]);
+                                          process_send_pas_request(conn, (buf[2]), buf[1]);
+                                          pthread_mutex_lock(&gDbusPendingRegMtx);   // block until pending received
                                           break;
                                        case CMD_LC_PREPARE_SHUTDOWN:
                                           process_prepare_shutdown((buf[2]), buf[1]);
-                                          break;
-                                       case CMD_SEND_LC_REQUEST:
                                           process_send_lifecycle_request(conn, (buf[2]), buf[1]);
                                           break;
                                        case CMD_SEND_NOTIFY_SIGNAL:
@@ -587,9 +587,6 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
                                        case CMD_REG_NOTIFY_SIGNAL:
                                           process_reg_notification_signal(conn);
                                           break;
-                                       case CMD_SEND_PAS_REQUEST:
-                                          process_send_pas_request(conn, (buf[2]), buf[1]);
-                                          break;
                                        case CMD_SEND_PAS_REGISTER:
                                           process_send_pas_register(conn, (buf[1]), buf[2]);
                                           break;
@@ -599,6 +596,17 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
                                        case CMD_QUIT:
                                           bContinue = FALSE;
                                           break;
+
+                                       // ******************************************************
+                                       /*
+                                       case CMD_SEND_LC_REQUEST:  // remove
+                                         process_send_lifecycle_request(conn, (buf[2]), buf[1]);
+                                         break;
+                                      case CMD_SEND_PAS_REQUEST: /// remove
+                                         process_send_pas_request(conn, (buf[2]), buf[1]);
+                                         break;
+                                       */
+                                       // ******************************************************
                                        default:
                                           DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop => command not handled"), DLT_INT(buf[0]) );
                                           break;
index e5eff44..6bce02c 100644 (file)
@@ -38,9 +38,9 @@ typedef enum ECmd
    CMD_LC_PREPARE_SHUTDOWN,         /// command to prepare shutdown
    CMD_SEND_NOTIFY_SIGNAL,          /// command send changed notification signal
    CMD_REG_NOTIFY_SIGNAL,           /// command send register/unregister command
-   CMD_SEND_PAS_REQUEST,            /// command send admin request
+   //CMD_SEND_PAS_REQUEST,            /// command send admin request
    CMD_SEND_PAS_REGISTER,           /// command send admin register/unregister
-   CMD_SEND_LC_REQUEST,             /// command send lifecycle request
+   //CMD_SEND_LC_REQUEST,             /// command send lifecycle request
    CMD_SEND_LC_REGISTER,            /// command send lifecycle register/unregister
    CMD_QUIT                         /// quit command
 } tCmd;
@@ -77,4 +77,5 @@ int deliverToMainloop(tCmd mainloopCmd, unsigned int param1, unsigned int param2
 
 
 int deliverToMainloop_NM(tCmd mainloopCmd, unsigned int param1, unsigned int param2);
+
 #endif /* PERSISTENCE_CLIENT_LIBRARY_DBUS_SERVICE_H_ */
index 0c19936..83deac6 100644 (file)
@@ -156,10 +156,9 @@ int unregister_lifecycle(int shutdownMode)
    return deliverToMainloop(CMD_SEND_LC_REGISTER, 0, shutdownMode);
 }
 
-
-
+/*
 int send_prepare_shutdown_complete(int requestId, int status)
 {
    return deliverToMainloop_NM(CMD_SEND_LC_REQUEST, status, requestId);
 }
-
+*/
index 3fb8ff1..28ac34f 100644 (file)
@@ -169,7 +169,7 @@ int signal_persModeChange(DBusConnection *connection, DBusMessage *message)
          DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("signal_persModeChange => DBus No memory"));
       }
 
-      dbus_message_unref (reply);
+      dbus_message_unref(reply);
 
       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    }
@@ -260,7 +260,7 @@ int unregister_pers_admin_service(void)
 }
 
 
-
+/*
 int pers_admin_service_data_sync_complete(unsigned int requestID, unsigned int status)
 {
    int rval =  0;
@@ -277,4 +277,4 @@ int pers_admin_service_data_sync_complete(unsigned int requestID, unsigned int s
    }
    return rval;
 }
-
+*/
index 21dc297..ea7c644 100644 (file)
 #include <pthread.h>
 #include <sys/eventfd.h>
 
+/*
+ * N O T E
+ *
+ * To test the PAS notifications the "./persistence_client_library_dbus_test" can be used.
+ * Use the dbus-send command to send shutdown notification to registered client if the lifecycle mockup will be used.
+ * To get the correct destionation (example is :1.11) see console when this application has been started.
+ * You sould find something like:
+ *   " checkAdminMsg ==> busName: :1.79 | objName: /org/genivi/persistence/adminconsumer | notificationFlag: 19 | gTimeoutMs: 5000"
+ * when a client registeres itself to the lifecycle mockup.
+ * Now use the the destination ":1.79" to communicate with the client library for dest in dbus-send command.
+ *
+
+  dbus-send --system --dest=:1.11 --type=method_call --print-reply /org/genivi/persistence/adminconsumer org.genivi.persistence.adminconsumer.PersistenceAdminRequest int32:17 int32:22
+
+  parameter 1:
+  int32:17 => PAS message block and write back
+  int32:2 => PAS message unblock
+
+  dbus-send return message value 32768 ==> invalid message:
+   method return sender=:1.72 -> dest=:1.74 reply_serial=2
+   int32 32768
+
+  dbus-send return message value 1 ==> OK:
+   method return sender=:1.72 -> dest=:1.76 reply_serial=2
+   int32 1
+
+*/
+
+
 
 /// command definitions for main loop
 typedef enum ECmd
@@ -176,6 +205,10 @@ DBusHandlerResult checkPersAdminMsg(DBusConnection * connection, DBusMessage * m
 
          result = checkAdminMsg(connection, message);
       }
+      else if((0==strcmp("PersistenceAdminRequestCompleted", dbus_message_get_member(message))))
+      {
+         printf(" ==> org.genivi.persistence.admin - received - ==> PersistenceAdminRequestCompleted \n");
+      }
       else
       {
          printf(" ==> org.genivi.persistence.admin - received U N KN O W N-'%s'\n", dbus_message_get_interface(message));
index 13b6a7e..115d1eb 100644 (file)
  * @see            
  */
 
+
+/*
+ * N O T E
+ *
+ * To test the shutdown sequence the "./persistence_client_library_dbus_test" can be used.
+ * Use the dbus-send command to send shutdown notification to registered client if the lifecycle mockup will be used.
+ * To get the correct destionation (example is :1.11) see console when this application has been started.
+ * You sould find something like:
+ *   "handleObjectPathMessageFallback Object: ':1.69' -> Interface: 'org.genivi.NodeStateManager.Consumer' -> Message: 'RegisterShutdownClient'"
+ * when a client registeres itself to the lifecycle mockup.
+ * Now use the the destination ":1.69" to communicate with the client library for dest in dbus-send command.
+ *
+
+  dbus-send --system --dest=:1.11 --type=method_call --print-reply /org/genivi/NodeStateManager/LifeCycleConsumer org.genivi.NodeStateManager.LifeCycleConsumer.LifecycleRequest uint32:1 uint32:22
+
+*/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>