Fix FTBFS for x86_64
[profile/ivi/dlt-daemon.git] / src / daemon / dlt_daemon_common.h
1 /**\r
2  * @licence app begin@\r
3  * Copyright (C) 2012  BMW AG\r
4  *\r
5  * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.\r
6  *\r
7  * Contributions are licensed to the GENIVI Alliance under one or more\r
8  * Contribution License Agreements.\r
9  *\r
10  * \copyright\r
11  * This Source Code Form is subject to the terms of the\r
12  * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with\r
13  * this file, You can obtain one at http://mozilla.org/MPL/2.0/.\r
14  *\r
15  *\r
16  * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012\r
17  *\r
18  * \file dlt_daemon_common.h\r
19  * For further information see http://www.genivi.org/.\r
20  * @licence end@\r
21  */\r
22 \r
23 \r
24 /*******************************************************************************\r
25 **                                                                            **\r
26 **  SRC-MODULE: dlt_daemon_common.h                                           **\r
27 **                                                                            **\r
28 **  TARGET    : linux                                                         **\r
29 **                                                                            **\r
30 **  PROJECT   : DLT                                                           **\r
31 **                                                                            **\r
32 **  AUTHOR    : Alexander Wenzel Alexander.AW.Wenzel@bmw.de                   **\r
33 **              Markus Klein                                                  **\r
34 **                                                                            **\r
35 **  PURPOSE   :                                                               **\r
36 **                                                                            **\r
37 **  REMARKS   :                                                               **\r
38 **                                                                            **\r
39 **  PLATFORM DEPENDANT [yes/no]: yes                                          **\r
40 **                                                                            **\r
41 **  TO BE CHANGED BY USER [yes/no]: no                                        **\r
42 **                                                                            **\r
43 *******************************************************************************/\r
44 \r
45 /*******************************************************************************\r
46 **                      Author Identity                                       **\r
47 ********************************************************************************\r
48 **                                                                            **\r
49 ** Initials     Name                       Company                            **\r
50 ** --------     -------------------------  ---------------------------------- **\r
51 **  aw          Alexander Wenzel           BMW                                **\r
52 **  mk          Markus Klein               Fraunhofer ESK                     **\r
53 *******************************************************************************/\r
54 \r
55 /*******************************************************************************\r
56 **                      Revision Control History                              **\r
57 *******************************************************************************/\r
58 \r
59 /*\r
60  * $LastChangedRevision: 1670 $\r
61  * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $\r
62  * $LastChangedBy$\r
63  Initials    Date         Comment\r
64  aw          15.02.2010   initial\r
65  */\r
66 \r
67 #ifndef DLT_DAEMON_COMMON_H\r
68 #define DLT_DAEMON_COMMON_H\r
69 \r
70 /**\r
71   \defgroup daemonapi DLT Daemon API\r
72   \addtogroup daemonapi\r
73   \{\r
74 */\r
75 \r
76 #include <limits.h>\r
77 #include <semaphore.h>\r
78 #include "dlt_common.h"\r
79 #include "dlt_user.h"\r
80 \r
81 #ifdef __cplusplus\r
82 extern "C" {\r
83 #endif\r
84 \r
85 #define DLT_DAEMON_RINGBUFFER_MIN_SIZE    500000 /**< Ring buffer size for storing log messages while no client is connected */\r
86 #define DLT_DAEMON_RINGBUFFER_MAX_SIZE  10000000 /**< Ring buffer size for storing log messages while no client is connected */\r
87 #define DLT_DAEMON_RINGBUFFER_STEP_SIZE   500000 /**< Ring buffer size for storing log messages while no client is connected */\r
88 \r
89 #define DLT_DAEMON_SEND_TO_ALL     -3   /**< Constant value to identify the command "send to all" */\r
90 #define DLT_DAEMON_SEND_FORCE      -4   /**< Constant value to identify the command "send force to all" */\r
91 \r
92 /* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */\r
93 \r
94 #define DLT_DAEMON_SEM_LOCK() { sem_wait(&dlt_daemon_mutex); }\r
95 #define DLT_DAEMON_SEM_FREE() { sem_post(&dlt_daemon_mutex); }\r
96 extern sem_t dlt_daemon_mutex;\r
97 \r
98 /**\r
99  * Definitions of DLT daemon logging states\r
100  */\r
101 typedef enum\r
102 {\r
103         DLT_DAEMON_STATE_INIT =                          0,  /**< Initial state */\r
104         DLT_DAEMON_STATE_BUFFER =            1,  /**< logging is buffered until external logger is connected or internal logging is activated */\r
105         DLT_DAEMON_STATE_BUFFER_FULL =       2,  /**< then internal buffer is full, wait for connect from client */\r
106         DLT_DAEMON_STATE_SEND_BUFFER =       3,  /**< external logger is connected, but buffer is still not empty or external logger queue is full */\r
107         DLT_DAEMON_STATE_SEND_DIRECT =       4   /**< External logger is connected or internal logging is active, and buffer is empty */\r
108 } DltDaemonState;\r
109 \r
110 /**\r
111  * The parameters of a daemon application.\r
112  */\r
113 typedef struct\r
114 {\r
115         char  apid[DLT_ID_SIZE];                  /**< application id */\r
116         pid_t pid;                   /**< process id of user application */\r
117         int user_handle;    /**< connection handle for connection to user application */\r
118         char *application_description; /**< context description */\r
119         int num_contexts; /**< number of contexts for this application */\r
120 } DltDaemonApplication;\r
121 \r
122 /**\r
123  * The parameters of a daemon context.\r
124  */\r
125 typedef struct\r
126 {\r
127         char apid[DLT_ID_SIZE];               /**< application id */\r
128         char ctid[DLT_ID_SIZE];                 /**< context id */\r
129         int8_t log_level;               /**< the current log level of the context */\r
130         int8_t trace_status;    /**< the current trace status of the context */\r
131         int log_level_pos;  /**< offset of context in context field on user application */\r
132         int user_handle;    /**< connection handle for connection to user application */\r
133         char *context_description; /**< context description */\r
134 } DltDaemonContext;\r
135 \r
136 /**\r
137  * The parameters of a daemon.\r
138  */\r
139 typedef struct\r
140 {\r
141         int num_contexts;               /**< Total number of all contexts in all applications */\r
142         DltDaemonContext *contexts;         /**< Pointer to contexts */\r
143         int num_applications;                   /**< Number of available application */\r
144         DltDaemonApplication *applications; /**< Pointer to applications */\r
145         int8_t default_log_level;          /**< Default log level (of daemon) */\r
146         int8_t default_trace_status;       /**< Default trace status (of daemon) */\r
147         unsigned int overflow_counter;   /**< counts the number of lost messages. */\r
148         int runtime_context_cfg_loaded;         /**< Set to one, if runtime context configuration has been loaded, zero otherwise */\r
149         char ecuid[DLT_ID_SIZE];       /**< ECU ID of daemon */\r
150         int sendserialheader;          /**< 1: send serial header; 0 don't send serial header */\r
151         int timingpackets;              /**< 1: send continous timing packets; 0 don't send continous timing packets */\r
152         DltBuffer client_ringbuffer; /**< Ring-buffer for storing received logs while no client connection is available */\r
153     char runtime_application_cfg[PATH_MAX + 1]; /**< Path and filename of persistent application configuration. Set to path max, as it specifies a full path*/\r
154     char runtime_context_cfg[PATH_MAX + 1]; /**< Path and filename of persistent context configuration */\r
155     char runtime_configuration[PATH_MAX + 1]; /**< Path and filename of persistent configuration */\r
156     DltUserLogMode mode;        /**< Mode used for tracing: off, external, internal, both */\r
157     char connectionState;                               /**< state for tracing: 0 = no client connected, 1 = client connected */\r
158     char *ECUVersionString; /**< Version string to send to client. Loaded from a file at startup. May be null. */\r
159     DltDaemonState state;   /**< the current logging state of dlt daemon. */\r
160 } DltDaemon;\r
161 \r
162 /**\r
163  * Initialise the dlt daemon structure\r
164  * This function must be called before using further dlt daemon structure\r
165  * @param daemon pointer to dlt daemon structure\r
166  * @param RingbufferMinSize ringbuffer size\r
167  * @param RingbufferMaxSize ringbuffer size\r
168  * @param RingbufferStepSize ringbuffer size\r
169  * @param runtime_directory Directory of persistent configuration\r
170  * @param verbose if set to true verbose information is printed out.\r
171  * @return negative value if there was an error\r
172  */\r
173 int dlt_daemon_init(DltDaemon *daemon,unsigned long RingbufferMinSize,unsigned long RingbufferMaxSize,unsigned long RingbufferStepSize,const char *runtime_directory,int verbose);\r
174 /**\r
175  * De-Initialise the dlt daemon structure\r
176  * @param daemon pointer to dlt daemon structure\r
177  * @param verbose if set to true verbose information is printed out.\r
178  * @return negative value if there was an error\r
179  */\r
180 int dlt_daemon_free(DltDaemon *daemon,int verbose);\r
181 \r
182 /**\r
183  * Add (new) application to internal application management\r
184  * @param daemon pointer to dlt daemon structure\r
185  * @param apid pointer to application id\r
186  * @param pid process id of user application\r
187  * @param description description of application\r
188  * @param verbose if set to true verbose information is printed out.\r
189  * @return Pointer to added context, null pointer on error\r
190  */\r
191 DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pid_t pid,char *description, int verbose);\r
192 /**\r
193  * Delete application from internal application management\r
194  * @param daemon pointer to dlt daemon structure\r
195  * @param application pointer to application to be deleted\r
196  * @param verbose if set to true verbose information is printed out.\r
197  * @return negative value if there was an error\r
198  */\r
199 int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *application, int verbose);\r
200 /**\r
201  * Find application with specific application id\r
202  * @param daemon pointer to dlt daemon structure\r
203  * @param apid pointer to application id\r
204  * @param verbose if set to true verbose information is printed out.\r
205  * @return Pointer to application, null pointer on error or not found\r
206  */\r
207 DltDaemonApplication* dlt_daemon_application_find(DltDaemon *daemon,char *apid,int verbose);\r
208 /**\r
209  * Load applications from file to internal context management\r
210  * @param daemon pointer to dlt daemon structure\r
211  * @param filename name of file to be used for loading\r
212  * @param verbose if set to true verbose information is printed out.\r
213  * @return negative value if there was an error\r
214  */\r
215 int dlt_daemon_applications_load(DltDaemon *daemon,const char *filename, int verbose);\r
216 /**\r
217  * Save applications from internal context management to file\r
218  * @param daemon pointer to dlt daemon structure\r
219  * @param filename name of file to be used for saving\r
220  * @param verbose if set to true verbose information is printed out.\r
221  * @return negative value if there was an error\r
222  */\r
223 int dlt_daemon_applications_save(DltDaemon *daemon,const char *filename, int verbose);\r
224 /**\r
225  * Invalidate all applications fd, if fd is reused\r
226  * @param daemon pointer to dlt daemon structure\r
227  * @param fd file descriptor\r
228  * @param verbose if set to true verbose information is printed out.\r
229  * @return negative value if there was an error\r
230  */\r
231 int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon,int fd,int verbose);\r
232 /**\r
233  * Clear all applications in internal application management\r
234  * @param daemon pointer to dlt daemon structure\r
235  * @param verbose if set to true verbose information is printed out.\r
236  * @return negative value if there was an error\r
237  */\r
238 int dlt_daemon_applications_clear(DltDaemon *daemon,int verbose);\r
239 \r
240 /**\r
241  * Add (new) context to internal context management\r
242  * @param daemon pointer to dlt daemon structure\r
243  * @param apid pointer to application id\r
244  * @param ctid pointer to context id\r
245  * @param log_level log level of context\r
246  * @param trace_status trace status of context\r
247  * @param log_level_pos offset of context in context field on user application\r
248  * @param user_handle connection handle for connection to user application\r
249  * @param description description of context\r
250  * @param verbose if set to true verbose information is printed out.\r
251  * @return Pointer to added context, null pointer on error\r
252  */\r
253 DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon,char *apid,char *ctid,int8_t log_level,int8_t trace_status,int log_level_pos, int user_handle,char *description,int verbose);\r
254 /**\r
255  * Delete context from internal context management\r
256  * @param daemon pointer to dlt daemon structure\r
257  * @param context pointer to context to be deleted\r
258  * @param verbose if set to true verbose information is printed out.\r
259  * @return negative value if there was an error\r
260  */\r
261 int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int verbose);\r
262 /**\r
263  * Find context with specific application id and context id\r
264  * @param daemon pointer to dlt daemon structure\r
265  * @param apid pointer to application id\r
266  * @param ctid pointer to context id\r
267  * @param verbose if set to true verbose information is printed out.\r
268  * @return Pointer to context, null pointer on error or not found\r
269  */\r
270 DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,char *apid,char *ctid,int verbose);\r
271 /**\r
272  * Invalidate all contexts fd, if fd is reused\r
273  * @param daemon pointer to dlt daemon structure\r
274  * @param fd file descriptor\r
275  * @param verbose if set to true verbose information is printed out.\r
276  * @return negative value if there was an error\r
277  */\r
278 int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon,int fd,int verbose);\r
279 /**\r
280  * Clear all contexts in internal context management\r
281  * @param daemon pointer to dlt daemon structure\r
282  * @param verbose if set to true verbose information is printed out.\r
283  * @return negative value if there was an error\r
284  */\r
285 int dlt_daemon_contexts_clear(DltDaemon *daemon,int verbose);\r
286 /**\r
287  * Load contexts from file to internal context management\r
288  * @param daemon pointer to dlt daemon structure\r
289  * @param filename name of file to be used for loading\r
290  * @param verbose if set to true verbose information is printed out.\r
291  * @return negative value if there was an error\r
292  */\r
293 int dlt_daemon_contexts_load(DltDaemon *daemon,const char *filename, int verbose);\r
294 /**\r
295  * Save contexts from internal context management to file\r
296  * @param daemon pointer to dlt daemon structure\r
297  * @param filename name of file to be used for saving\r
298  * @param verbose if set to true verbose information is printed out.\r
299  * @return negative value if there was an error\r
300  */\r
301 int dlt_daemon_contexts_save(DltDaemon *daemon,const char *filename, int verbose);\r
302 /**\r
303  * Load persistant configuration\r
304  * @param daemon pointer to dlt daemon structure\r
305  * @param filename name of file to be used for loading\r
306  * @param verbose if set to true verbose information is printed out.\r
307  * @return negative value if there was an error\r
308  */\r
309 int dlt_daemon_configuration_load(DltDaemon *daemon,const char *filename, int verbose);\r
310 /**\r
311  * Save configuration persistantly\r
312  * @param daemon pointer to dlt daemon structure\r
313  * @param filename name of file to be used for saving\r
314  * @param verbose if set to true verbose information is printed out.\r
315  * @return negative value if there was an error\r
316  */\r
317 int dlt_daemon_configuration_save(DltDaemon *daemon,const char *filename, int verbose);\r
318 \r
319 \r
320 /**\r
321  * Send user message DLT_USER_MESSAGE_LOG_LEVEL to user application\r
322  * @param daemon pointer to dlt daemon structure\r
323  * @param context pointer to context for response\r
324  * @param verbose if set to true verbose information is printed out.\r
325  * @return negative value if there was an error\r
326  */\r
327 int dlt_daemon_user_send_log_level(DltDaemon *daemon,DltDaemonContext *context, int verbose);\r
328 \r
329 /**\r
330  * Send user message DLT_USER_MESSAGE_LOG_STATE to user application\r
331  * @param daemon pointer to dlt daemon structure\r
332  * @param app pointer to application for response\r
333  * @param verbose if set to true verbose information is printed out.\r
334  * @return negative value if there was an error\r
335  */\r
336 int dlt_daemon_user_send_log_state(DltDaemon *daemon,DltDaemonApplication *app,int verbose);\r
337 \r
338 /**\r
339  * Send user messages to all user applications using default context, or trace status\r
340  * to update those values\r
341  * @param daemon pointer to dlt daemon structure\r
342  * @param verbose if set to true verbose information is printed out.\r
343  */\r
344 void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose);\r
345 \r
346 /**\r
347  * Send user messages to all user applications the log status\r
348  * everytime the client is connected or disconnected.\r
349  * @param daemon pointer to dlt daemon structure\r
350  * @param verbose if set to true verbose information is printed out.\r
351  */\r
352 void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose);\r
353 \r
354 /**\r
355  * Process reset to factory default control message\r
356  * @param daemon pointer to dlt daemon structure\r
357  * @param filename name of file containing the runtime defaults for applications\r
358  * @param filename1 name of file containing the runtime defaults for contexts\r
359  * @param verbose if set to true verbose information is printed out.\r
360  */\r
361 void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *filename, const char *filename1, int verbose);\r
362 \r
363 /**\r
364  * Change the logging state of dlt daemon\r
365  * @param daemon pointer to dlt daemon structure\r
366  * @param newState the requested new state\r
367  */\r
368 void dlt_daemon_change_state(DltDaemon *daemon, DltDaemonState newState);\r
369 \r
370 #ifdef __cplusplus\r
371 }\r
372 #endif\r
373 \r
374 /**\r
375   \}\r
376 */\r
377 \r
378 #endif /* DLT_DAEMON_COMMON_H */\r