[D4099]: Integrated fix from Alexander Wenzel. This will check for
[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 <semaphore.h>\r
77 #include "dlt_common.h"\r
78 #include "dlt_user.h"\r
79 \r
80 #ifdef __cplusplus\r
81 extern "C" {\r
82 #endif\r
83 \r
84 #define DLT_DAEMON_RINGBUFFER_MIN_SIZE  100000 /**< Ring buffer size for storing log messages while no client is connected */\r
85 #define DLT_DAEMON_RINGBUFFER_MAX_SIZE  500000 /**< Ring buffer size for storing log messages while no client is connected */\r
86 #define DLT_DAEMON_RINGBUFFER_STEP_SIZE 100000 /**< Ring buffer size for storing log messages while no client is connected */\r
87 \r
88 #define DLT_DAEMON_STORE_TO_BUFFER -2   /**< Constant value to identify the command "store to buffer" */\r
89 \r
90 /* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */\r
91 \r
92 #define DLT_DAEMON_SEM_LOCK() { sem_wait(&dlt_daemon_mutex); }\r
93 #define DLT_DAEMON_SEM_FREE() { sem_post(&dlt_daemon_mutex); }\r
94 extern sem_t dlt_daemon_mutex;\r
95 \r
96 \r
97 /**\r
98  * The parameters of a daemon application.\r
99  */\r
100 typedef struct\r
101 {\r
102         char  apid[DLT_ID_SIZE];                  /**< application id */\r
103         pid_t pid;                   /**< process id of user application */\r
104         int user_handle;    /**< connection handle for connection to user application */\r
105         char *application_description; /**< context description */\r
106         int num_contexts; /**< number of contexts for this application */\r
107 } DltDaemonApplication;\r
108 \r
109 /**\r
110  * The parameters of a daemon context.\r
111  */\r
112 typedef struct\r
113 {\r
114         char apid[DLT_ID_SIZE];               /**< application id */\r
115         char ctid[DLT_ID_SIZE];                 /**< context id */\r
116         int8_t log_level;               /**< the current log level of the context */\r
117         int8_t trace_status;    /**< the current trace status of the context */\r
118         int log_level_pos;  /**< offset of context in context field on user application */\r
119         int user_handle;    /**< connection handle for connection to user application */\r
120         char *context_description; /**< context description */\r
121 } DltDaemonContext;\r
122 \r
123 /**\r
124  * The parameters of a daemon.\r
125  */\r
126 typedef struct\r
127 {\r
128         int num_contexts;               /**< Total number of all contexts in all applications */\r
129         DltDaemonContext *contexts;         /**< Pointer to contexts */\r
130         int num_applications;                   /**< Number of available application */\r
131         DltDaemonApplication *applications; /**< Pointer to applications */\r
132         int8_t default_log_level;          /**< Default log level (of daemon) */\r
133         int8_t default_trace_status;       /**< Default trace status (of daemon) */\r
134         int message_buffer_overflow;   /**< Set to one, if buffer overflow has occured, zero otherwise */\r
135         int runtime_context_cfg_loaded;         /**< Set to one, if runtime context configuration has been loaded, zero otherwise */\r
136         char ecuid[DLT_ID_SIZE];       /**< ECU ID of daemon */\r
137         int sendserialheader;          /**< 1: send serial header; 0 don't send serial header */\r
138         int timingpackets;              /**< 1: send continous timing packets; 0 don't send continous timing packets */\r
139         DltBuffer client_ringbuffer; /**< Ring-buffer for storing received logs while no client connection is available */\r
140         char runtime_application_cfg[256]; /**< Path and filename of persistent application configuration */\r
141         char runtime_context_cfg[256]; /**< Path and filename of persistent context configuration */\r
142         char runtime_configuration[256]; /**< Path and filename of persistent configuration */\r
143     DltUserLogMode mode;        /**< Mode used for tracing: off, external, internal, both */\r
144     char state;                         /**< state for tracing: 0 = no client connected, 1 = client connected */\r
145 } DltDaemon;\r
146 \r
147 /**\r
148  * Initialise the dlt daemon structure\r
149  * This function must be called before using further dlt daemon structure\r
150  * @param daemon pointer to dlt daemon structure\r
151  * @param runtime_directory Directory of persistent configuration\r
152  * @param verbose if set to true verbose information is printed out.\r
153  * @return negative value if there was an error\r
154  */\r
155 int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory,int verbose);\r
156 /**\r
157  * De-Initialise the dlt daemon structure\r
158  * @param daemon pointer to dlt daemon structure\r
159  * @param verbose if set to true verbose information is printed out.\r
160  * @return negative value if there was an error\r
161  */\r
162 int dlt_daemon_free(DltDaemon *daemon,int verbose);\r
163 \r
164 /**\r
165  * Add (new) application to internal application management\r
166  * @param daemon pointer to dlt daemon structure\r
167  * @param apid pointer to application id\r
168  * @param pid process id of user application\r
169  * @param description description of application\r
170  * @param verbose if set to true verbose information is printed out.\r
171  * @return Pointer to added context, null pointer on error\r
172  */\r
173 DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pid_t pid,char *description, int verbose);\r
174 /**\r
175  * Delete application from internal application management\r
176  * @param daemon pointer to dlt daemon structure\r
177  * @param application pointer to application to be deleted\r
178  * @param verbose if set to true verbose information is printed out.\r
179  * @return negative value if there was an error\r
180  */\r
181 int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *application, int verbose);\r
182 /**\r
183  * Find application with specific application id\r
184  * @param daemon pointer to dlt daemon structure\r
185  * @param apid pointer to application id\r
186  * @param verbose if set to true verbose information is printed out.\r
187  * @return Pointer to application, null pointer on error or not found\r
188  */\r
189 DltDaemonApplication* dlt_daemon_application_find(DltDaemon *daemon,char *apid,int verbose);\r
190 /**\r
191  * Load applications from file to internal context management\r
192  * @param daemon pointer to dlt daemon structure\r
193  * @param filename name of file to be used for loading\r
194  * @param verbose if set to true verbose information is printed out.\r
195  * @return negative value if there was an error\r
196  */\r
197 int dlt_daemon_applications_load(DltDaemon *daemon,const char *filename, int verbose);\r
198 /**\r
199  * Save applications from internal context management to file\r
200  * @param daemon pointer to dlt daemon structure\r
201  * @param filename name of file to be used for saving\r
202  * @param verbose if set to true verbose information is printed out.\r
203  * @return negative value if there was an error\r
204  */\r
205 int dlt_daemon_applications_save(DltDaemon *daemon,const char *filename, int verbose);\r
206 /**\r
207  * Invalidate all applications fd, if fd is reused\r
208  * @param daemon pointer to dlt daemon structure\r
209  * @param fd file descriptor\r
210  * @param verbose if set to true verbose information is printed out.\r
211  * @return negative value if there was an error\r
212  */\r
213 int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon,int fd,int verbose);\r
214 /**\r
215  * Clear all applications in internal application management\r
216  * @param daemon pointer to dlt daemon structure\r
217  * @param verbose if set to true verbose information is printed out.\r
218  * @return negative value if there was an error\r
219  */\r
220 int dlt_daemon_applications_clear(DltDaemon *daemon,int verbose);\r
221 \r
222 /**\r
223  * Add (new) context to internal context management\r
224  * @param daemon pointer to dlt daemon structure\r
225  * @param apid pointer to application id\r
226  * @param ctid pointer to context id\r
227  * @param log_level log level of context\r
228  * @param trace_status trace status of context\r
229  * @param log_level_pos offset of context in context field on user application\r
230  * @param user_handle connection handle for connection to user application\r
231  * @param description description of context\r
232  * @param verbose if set to true verbose information is printed out.\r
233  * @return Pointer to added context, null pointer on error\r
234  */\r
235 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
236 /**\r
237  * Delete context from internal context management\r
238  * @param daemon pointer to dlt daemon structure\r
239  * @param context pointer to context to be deleted\r
240  * @param verbose if set to true verbose information is printed out.\r
241  * @return negative value if there was an error\r
242  */\r
243 int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int verbose);\r
244 /**\r
245  * Find context with specific application id and context id\r
246  * @param daemon pointer to dlt daemon structure\r
247  * @param apid pointer to application id\r
248  * @param ctid pointer to context id\r
249  * @param verbose if set to true verbose information is printed out.\r
250  * @return Pointer to context, null pointer on error or not found\r
251  */\r
252 DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,char *apid,char *ctid,int verbose);\r
253 /**\r
254  * Invalidate all contexts fd, if fd is reused\r
255  * @param daemon pointer to dlt daemon structure\r
256  * @param fd file descriptor\r
257  * @param verbose if set to true verbose information is printed out.\r
258  * @return negative value if there was an error\r
259  */\r
260 int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon,int fd,int verbose);\r
261 /**\r
262  * Clear all contexts in internal context management\r
263  * @param daemon pointer to dlt daemon structure\r
264  * @param verbose if set to true verbose information is printed out.\r
265  * @return negative value if there was an error\r
266  */\r
267 int dlt_daemon_contexts_clear(DltDaemon *daemon,int verbose);\r
268 /**\r
269  * Load contexts from file to internal context management\r
270  * @param daemon pointer to dlt daemon structure\r
271  * @param filename name of file to be used for loading\r
272  * @param verbose if set to true verbose information is printed out.\r
273  * @return negative value if there was an error\r
274  */\r
275 int dlt_daemon_contexts_load(DltDaemon *daemon,const char *filename, int verbose);\r
276 /**\r
277  * Save contexts from internal context management to file\r
278  * @param daemon pointer to dlt daemon structure\r
279  * @param filename name of file to be used for saving\r
280  * @param verbose if set to true verbose information is printed out.\r
281  * @return negative value if there was an error\r
282  */\r
283 int dlt_daemon_contexts_save(DltDaemon *daemon,const char *filename, int verbose);\r
284 /**\r
285  * Load persistant configuration\r
286  * @param daemon pointer to dlt daemon structure\r
287  * @param filename name of file to be used for loading\r
288  * @param verbose if set to true verbose information is printed out.\r
289  * @return negative value if there was an error\r
290  */\r
291 int dlt_daemon_configuration_load(DltDaemon *daemon,const char *filename, int verbose);\r
292 /**\r
293  * Save configuration persistantly\r
294  * @param daemon pointer to dlt daemon structure\r
295  * @param filename name of file to be used for saving\r
296  * @param verbose if set to true verbose information is printed out.\r
297  * @return negative value if there was an error\r
298  */\r
299 int dlt_daemon_configuration_save(DltDaemon *daemon,const char *filename, int verbose);\r
300 \r
301 \r
302 /**\r
303  * Send user message DLT_USER_MESSAGE_LOG_LEVEL to user application\r
304  * @param daemon pointer to dlt daemon structure\r
305  * @param context pointer to context for response\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_user_send_log_level(DltDaemon *daemon,DltDaemonContext *context, int verbose);\r
310 \r
311 /**\r
312  * Send user message DLT_USER_MESSAGE_LOG_STATE to user application\r
313  * @param daemon pointer to dlt daemon structure\r
314  * @param app pointer to application for response\r
315  * @param verbose if set to true verbose information is printed out.\r
316  * @return negative value if there was an error\r
317  */\r
318 int dlt_daemon_user_send_log_state(DltDaemon *daemon,DltDaemonApplication *app,int verbose);\r
319 \r
320 /**\r
321  * Send user messages to all user applications using default context, or trace status\r
322  * to update those values\r
323  * @param daemon pointer to dlt daemon structure\r
324  * @param verbose if set to true verbose information is printed out.\r
325  */\r
326 void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose);\r
327 \r
328 /**\r
329  * Send user messages to all user applications the log status\r
330  * everytime the client is connected or disconnected.\r
331  * @param daemon pointer to dlt daemon structure\r
332  * @param verbose if set to true verbose information is printed out.\r
333  */\r
334 void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose);\r
335 \r
336 /**\r
337  * Process received control message from dlt client\r
338  * @param sock connection handle used for sending response\r
339  * @param daemon pointer to dlt daemon structure\r
340  * @param msg pointer to received control message\r
341  * @param verbose if set to true verbose information is printed out.\r
342  */\r
343 int dlt_daemon_control_process_control(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
344 /**\r
345  * Generate response to control message from dlt client\r
346  * @param sock connection handle used for sending response\r
347  * @param daemon pointer to dlt daemon structure\r
348  * @param service_id service id of control message\r
349  * @param status status of response (e.g. ok, not supported, error)\r
350  * @param verbose if set to true verbose information is printed out.\r
351  */\r
352 void dlt_daemon_control_service_response(int sock, DltDaemon *daemon, uint32_t service_id, int8_t status, int verbose);\r
353 /**\r
354  * Send out response message to dlt client\r
355  * @param sock connection handle used for sending response\r
356  * @param daemon pointer to dlt daemon structure\r
357  * @param msg pointer to response message\r
358  * @param appid pointer to application id to be used in response message\r
359  * @param contid pointer to context id to be used in response message\r
360  * @param verbose if set to true verbose information is printed out.\r
361  */\r
362 void dlt_daemon_control_send_control_message(int sock, DltDaemon *daemon, DltMessage *msg, char* appid, char* contid, int verbose);\r
363 \r
364 /**\r
365  * Process and generate response to received sw injection control message\r
366  * @param sock connection handle used for sending response\r
367  * @param daemon pointer to dlt daemon structure\r
368  * @param msg pointer to received sw injection control message\r
369  * @param verbose if set to true verbose information is printed out.\r
370  */\r
371 void dlt_daemon_control_callsw_cinjection(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
372 /**\r
373  * Process and generate response to received set log level control message\r
374  * @param sock connection handle used for sending response\r
375  * @param daemon pointer to dlt daemon structure\r
376  * @param msg pointer to received control message\r
377  * @param verbose if set to true verbose information is printed out.\r
378  */\r
379 void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
380 /**\r
381  * Process and generate response to received set trace status control message\r
382  * @param sock connection handle used for sending response\r
383  * @param daemon pointer to dlt daemon structure\r
384  * @param msg pointer to received control message\r
385  * @param verbose if set to true verbose information is printed out.\r
386  */\r
387 void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
388 /**\r
389  * Process and generate response to received set default log level control message\r
390  * @param sock connection handle used for sending response\r
391  * @param daemon pointer to dlt daemon structure\r
392  * @param msg pointer to received control message\r
393  * @param verbose if set to true verbose information is printed out.\r
394  */\r
395 void dlt_daemon_control_set_default_log_level(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
396 /**\r
397  * Process and generate response to received set default trace status control message\r
398  * @param sock connection handle used for sending response\r
399  * @param daemon pointer to dlt daemon structure\r
400  * @param msg pointer to received control message\r
401  * @param verbose if set to true verbose information is printed out.\r
402  */\r
403 void dlt_daemon_control_set_default_trace_status(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
404 /**\r
405  * Process and generate response to set timing packets control message\r
406  * @param sock connection handle used for sending response\r
407  * @param daemon pointer to dlt daemon structure\r
408  * @param msg pointer to received control message\r
409  * @param verbose if set to true verbose information is printed out.\r
410  */\r
411 void dlt_daemon_control_set_timing_packets(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
412 /**\r
413  * Process and generate response to received get software version control message\r
414  * @param sock connection handle used for sending response\r
415  * @param daemon pointer to dlt daemon structure\r
416  * @param verbose if set to true verbose information is printed out.\r
417  */\r
418 void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, int verbose);\r
419 /**\r
420  * Process and generate response to received get default log level control message\r
421  * @param sock connection handle used for sending response\r
422  * @param daemon pointer to dlt daemon structure\r
423  * @param verbose if set to true verbose information is printed out.\r
424  */\r
425 void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, int verbose);\r
426 /**\r
427  * Process and generate response to received get log info control message\r
428  * @param sock connection handle used for sending response\r
429  * @param daemon pointer to dlt daemon structure\r
430  * @param msg pointer to received control message\r
431  * @param verbose if set to true verbose information is printed out.\r
432  */\r
433 void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
434 /**\r
435  * Process and generate response to message buffer overflow control message\r
436  * @param sock connection handle used for sending response\r
437  * @param daemon pointer to dlt daemon structure\r
438  * @param verbose if set to true verbose information is printed out.\r
439  */\r
440 void dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, int verbose);\r
441 /**\r
442  * Process reset to factory default control message\r
443  * @param daemon pointer to dlt daemon structure\r
444  * @param filename name of file containing the runtime defaults for applications\r
445  * @param filename1 name of file containing the runtime defaults for contexts\r
446  * @param verbose if set to true verbose information is printed out.\r
447  */\r
448 void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *filename, const char *filename1, int verbose);\r
449 /**\r
450  * Send time control message\r
451  * @param sock connection handle used for sending response\r
452  * @param daemon pointer to dlt daemon structure\r
453  * @param verbose if set to true verbose information is printed out.\r
454  */\r
455 void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose);\r
456 \r
457 #ifdef __cplusplus\r
458 }\r
459 #endif\r
460 \r
461 /**\r
462   \}\r
463 */\r
464 \r
465 #endif /* DLT_DAEMON_COMMON_H */\r