summaryrefslogtreecommitdiff
path: root/src/persistence_client_library_dbus_service.h
blob: d3f70d65dc6480bce67d053eece0edb4f2120370 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef PERSISTENCE_CLIENT_LIBRARY_DBUS_SERVICE_H_
#define PERSISTENCE_CLIENT_LIBRARY_DBUS_SERVICE_H_

/******************************************************************************
 * Project         Persistency
 * (c) copyright   2012
 * Company         XS Embedded GmbH
 *****************************************************************************/
/******************************************************************************
 * This Source Code Form is subject to the terms of the
 * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed
 * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
******************************************************************************/
 /**
 * @file           persistence_client_library_dbus_service.h
 * @ingroup        Persistence client library
 * @author         Ingo Huerner
 * @brief          Header of the persistence client library dbus service.
 * @see
 */

#include <dbus/dbus.h>

#include <poll.h>
#include <pthread.h>
#include <sys/eventfd.h>
#include <sys/timerfd.h>

#include "persistence_client_library_data_organization.h"

/// command definitions for main loop
typedef enum ECmd
{
	/// command none
   CMD_NONE = 0,
   /// command block access and write data back
   CMD_PAS_BLOCK_AND_WRITE_BACK,
   /// command to prepare shutdown
   CMD_LC_PREPARE_SHUTDOWN,
   /// command send changed notification signal
   CMD_SEND_NOTIFY_SIGNAL,
   /// command send register/unregister command
   CMD_REG_NOTIFY_SIGNAL,
   /// command send admin register/unregister
   CMD_SEND_PAS_REGISTER,
   /// command send lifecycle register/unregister
   CMD_SEND_LC_REGISTER,
   /// quit command
   CMD_QUIT
} tCmd;


/// command data union definition
typedef struct MainLoopData_u_{

   /// dbus mainloop command
   uint32_t cmd;
   /// unsigned int parameters
   uint32_t params[4];
   /// string parameter
   char string[PERS_DB_MAX_LENGTH_KEY_NAME];


} MainLoopData_u;

/// dbus pending mutex => visibility "hidden" to prevent the use outside the library
extern pthread_mutex_t gDbusPendingRegMtx __attribute__ ((visibility ("hidden")));
extern pthread_cond_t  gDbusPendingCond;
extern int gDbusPendingCondValue;

/// dbus mainloop conditional variable => visibility "hidden" to prevent the use outside the library
extern pthread_mutex_t gMainCondMtx __attribute__ ((visibility ("hidden")));
/// dbus mainloop mutex => visibility "hidden" to prevent the use outside the library
extern pthread_t gMainLoopThread;

extern int gMainLoopCondValue __attribute__ ((visibility ("hidden")));


/// lifecycle consumer interface dbus name
extern const char* gDbusLcConsterface;
/// lifecycle consumer dbus interface
extern const char* gDbusLcCons;
/// lifecycle consumer dbus destination
extern const char* gDbusLcConsDest;
/// lifecycle consumer dbus path
extern const char* gDbusLcConsPath;
/// lifecycle consumer debus message
extern const char* gDbusLcConsMsg;
/// lifecycle consumer dbus interface
extern const char* gDbusLcInterface;

/// persistence administrator consumer dbus interface
extern const char* gDbusPersAdminConsInterface;
/// persistence administrator consumer dbus
extern const char* gDbusPersAdminPath;
/// persistence administrator consumer dbus interface message
extern const char* gDbusPersAdminConsMsg;
/// persistence administrator dbus
extern const char* gDbusPersAdminInterface;
/// persistence administrator dbus path
extern const char* gPersAdminConsumerPath;


/**
 * @brief DBus main loop to dispatch events and dbus messages
 *
 * @param userData data to pass to the main loop
 *
 * @return void*
 */
void* mainLoop(void* userData);


/**
 * @brief Setup the dbus main dispatching loop
 *
 * @return 0
 */
int setup_dbus_mainloop(void);


/**
 * @brief deliver message to mainloop (blocking)
 *        The function blocks until the message has
 *        been delivered to the mainloop
 *
 * @param payload the message to deliver to the mainloop (command and data)
 *
 * @return 0
 */
int deliverToMainloop(MainLoopData_u* payload);


/**
 * @brief deliver message to mainloop (non blocking)
 *        The function does N O T  block until the message has
 *        been delivered to the mainloop
 *
 * @param payload the message to deliver to the mainloop (command and data)
 *
 * @return 0
 */
int deliverToMainloop_NM(MainLoopData_u* payload);


#endif /* PERSISTENCE_CLIENT_LIBRARY_DBUS_SERVICE_H_ */