init und deinit is not blocking anymore when they will be called multiple times
[profile/ivi/persistence-client-library.git] / src / persistence_client_library_dbus_service.h
1 #ifndef PERSISTENCE_CLIENT_LIBRARY_DBUS_SERVICE_H_
2 #define PERSISTENCE_CLIENT_LIBRARY_DBUS_SERVICE_H_
3
4 /******************************************************************************
5  * Project         Persistency
6  * (c) copyright   2012
7  * Company         XS Embedded GmbH
8  *****************************************************************************/
9 /******************************************************************************
10  * This Source Code Form is subject to the terms of the
11  * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed
12  * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 ******************************************************************************/
14  /**
15  * @file           persistence_client_library_dbus_service.h
16  * @ingroup        Persistence client library
17  * @author         Ingo Huerner
18  * @brief          Header of the persistence client library dbus service.
19  * @see
20  */
21
22 #include <dbus/dbus.h>
23 #include <poll.h>
24 #include <pthread.h>
25 #include <sys/eventfd.h>
26 #include <sys/timerfd.h>
27
28 /// mutex to make sure main loop is running
29 extern pthread_mutex_t gDbusInitializedMtx;
30 extern pthread_cond_t  gDbusInitializedCond;
31 extern pthread_mutex_t gDbusPendingRegMtx;
32
33 extern pthread_mutex_t gMainLoopMtx;
34
35 // declared in persistence_client_library_dbus_service.c
36 // used to end dbus library
37 extern int bContinue;
38
39 extern pthread_t gMainLoopThread;
40
41
42 /// command definitions for main loop
43 typedef enum ECmd
44 {
45    CMD_NONE = 0,                    /// command none
46    CMD_PAS_BLOCK_AND_WRITE_BACK,    /// command block access and write data back
47    CMD_LC_PREPARE_SHUTDOWN,         /// command to prepare shutdown
48    CMD_SEND_NOTIFY_SIGNAL,          /// command send changed notification signal
49    CMD_REG_NOTIFY_SIGNAL,           /// command send register/unregister command
50    //CMD_SEND_PAS_REQUEST,            /// command send admin request
51    CMD_SEND_PAS_REGISTER,           /// command send admin register/unregister
52    //CMD_SEND_LC_REQUEST,             /// command send lifecycle request
53    CMD_SEND_LC_REGISTER,            /// command send lifecycle register/unregister
54    CMD_QUIT                         /// quit command
55 } tCmd;
56
57
58 /// pipe file descriptors
59 extern int gEfds;
60
61
62 /**
63  * @brief DBus main loop to dispatch events and dbus messages
64  *
65  * @param vtable the function pointer tables for '/org/genivi/persistence/adminconsumer' messages
66  * @param vtable2 the function pointer tables for '/com/contiautomotive/NodeStateManager/LifecycleConsumer' messages
67  * @param vtableFallback the fallback function pointer tables
68  * @param userData data to pass to the main loop
69  *
70  * @return 0
71  */
72 int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
73              DBusObjectPathVTable vtableFallback, void* userData);
74
75
76
77 /**
78  * @brief Setup the dbus main dispatching loop
79  *
80  * @return 0
81  */
82 int setup_dbus_mainloop(void);
83
84
85 int deliverToMainloop(tCmd mainloopCmd, unsigned int param1, unsigned int param2);
86
87
88 int deliverToMainloop_NM(tCmd mainloopCmd, unsigned int param1, unsigned int param2);
89
90
91 #endif /* PERSISTENCE_CLIENT_LIBRARY_DBUS_SERVICE_H_ */