1870295a6b06c4e94da759328ac839e0a9ee7f60
[profile/ivi/dlt-daemon.git] / src / daemon / dlt_daemon_common.h
1 /*\r
2  * Dlt- Diagnostic Log and Trace daemon\r
3  * @licence app begin@
4  *
5  * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de>
6  * 
7  * This program is free software; you can redistribute it and/or modify it under the terms of the 
8  * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 
11  * Public License, version 2.1, for more details.
12  * 
13  * You should have received a copy of the GNU Lesser General Public License, version 2.1, along 
14  * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
15  * 
16  * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may 
17  * also be applicable to programs even in cases in which the program is not a library in the technical sense.
18  * 
19  * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may 
20  * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to 
21  * license your linked modules under the GNU Lesser General Public License, version 2.1, you 
22  * may use the program under the following exception.
23  * 
24  * As a special exception, the copyright holders of DLT give you permission to combine DLT 
25  * with software programs or libraries that are released under any license unless such a combination is not
26  * permitted by the license of such a software program or library. You may copy and distribute such a 
27  * system following the terms of the GNU Lesser General Public License, version 2.1, including this
28  * special exception, for DLT and the licenses of the other code concerned.
29  * 
30  * Note that people who make modified versions of DLT are not obligated to grant this special exception 
31  * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, 
32  * version 2.1, gives permission to release a modified version without this exception; this exception 
33  * also makes it possible to release a modified version which carries forward this exception.
34  *
35  * @licence end@\r
36  */\r
37 \r
38 \r
39 /*******************************************************************************\r
40 **                                                                            **\r
41 **  SRC-MODULE: dlt_daemon_common.h                                           **\r
42 **                                                                            **\r
43 **  TARGET    : linux                                                         **\r
44 **                                                                            **\r
45 **  PROJECT   : DLT                                                           **\r
46 **                                                                            **\r
47 **  AUTHOR    : Alexander Wenzel Alexander.AW.Wenzel@bmw.de                   **\r
48 **              Markus Klein                                                  **\r
49 **                                                                            **\r
50 **  PURPOSE   :                                                               **\r
51 **                                                                            **\r
52 **  REMARKS   :                                                               **\r
53 **                                                                            **\r
54 **  PLATFORM DEPENDANT [yes/no]: yes                                          **\r
55 **                                                                            **\r
56 **  TO BE CHANGED BY USER [yes/no]: no                                        **\r
57 **                                                                            **\r
58 *******************************************************************************/\r
59 \r
60 /*******************************************************************************\r
61 **                      Author Identity                                       **\r
62 ********************************************************************************\r
63 **                                                                            **\r
64 ** Initials     Name                       Company                            **\r
65 ** --------     -------------------------  ---------------------------------- **\r
66 **  aw          Alexander Wenzel           BMW                                **\r
67 **  mk          Markus Klein               Fraunhofer ESK                     **\r
68 *******************************************************************************/\r
69 \r
70 /*******************************************************************************\r
71 **                      Revision Control History                              **\r
72 *******************************************************************************/\r
73 \r
74 /*\r
75  * $LastChangedRevision: 1670 $\r
76  * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $\r
77  * $LastChangedBy$\r
78  Initials    Date         Comment\r
79  aw          15.02.2010   initial\r
80  */\r
81 \r
82 #ifndef DLT_DAEMON_COMMON_H\r
83 #define DLT_DAEMON_COMMON_H\r
84 \r
85 /**\r
86   \defgroup daemonapi DLT Daemon API\r
87   \addtogroup daemonapi\r
88   \{\r
89 */\r
90 \r
91 #include <semaphore.h>\r
92 #include "dlt_common.h"\r
93 #include "dlt_user.h"\r
94 \r
95 #ifdef __cplusplus\r
96 extern "C" {\r
97 #endif\r
98 \r
99 #define DLT_DAEMON_RINGBUFFER_MIN_SIZE  100000 /**< Ring buffer size for storing log messages while no client is connected */\r
100 #define DLT_DAEMON_RINGBUFFER_MAX_SIZE  500000 /**< Ring buffer size for storing log messages while no client is connected */\r
101 #define DLT_DAEMON_RINGBUFFER_STEP_SIZE 100000 /**< Ring buffer size for storing log messages while no client is connected */\r
102 \r
103 #define DLT_DAEMON_STORE_TO_BUFFER -2   /**< Constant value to identify the command "store to buffer" */\r
104 \r
105 /* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */\r
106 \r
107 #define DLT_DAEMON_SEM_LOCK() { sem_wait(&dlt_daemon_mutex); }\r
108 #define DLT_DAEMON_SEM_FREE() { sem_post(&dlt_daemon_mutex); }\r
109 extern sem_t dlt_daemon_mutex;\r
110 \r
111 \r
112 /**\r
113  * The parameters of a daemon application.\r
114  */\r
115 typedef struct\r
116 {\r
117         char  apid[DLT_ID_SIZE];                  /**< application id */\r
118         pid_t pid;                   /**< process id of user application */\r
119         int user_handle;    /**< connection handle for connection to user application */\r
120         char *application_description; /**< context description */\r
121         int num_contexts; /**< number of contexts for this application */\r
122 } DltDaemonApplication;\r
123 \r
124 /**\r
125  * The parameters of a daemon context.\r
126  */\r
127 typedef struct\r
128 {\r
129         char apid[DLT_ID_SIZE];               /**< application id */\r
130         char ctid[DLT_ID_SIZE];                 /**< context id */\r
131         int8_t log_level;               /**< the current log level of the context */\r
132         int8_t trace_status;    /**< the current trace status of the context */\r
133         int log_level_pos;  /**< offset of context in context field on user application */\r
134         int user_handle;    /**< connection handle for connection to user application */\r
135         char *context_description; /**< context description */\r
136 } DltDaemonContext;\r
137 \r
138 /**\r
139  * The parameters of a daemon.\r
140  */\r
141 typedef struct\r
142 {\r
143         int num_contexts;               /**< Total number of all contexts in all applications */\r
144         DltDaemonContext *contexts;         /**< Pointer to contexts */\r
145         int num_applications;                   /**< Number of available application */\r
146         DltDaemonApplication *applications; /**< Pointer to applications */\r
147         int8_t default_log_level;          /**< Default log level (of daemon) */\r
148         int8_t default_trace_status;       /**< Default trace status (of daemon) */\r
149         int message_buffer_overflow;   /**< Set to one, if buffer overflow has occured, zero otherwise */\r
150         int runtime_context_cfg_loaded;         /**< Set to one, if runtime context configuration has been loaded, zero otherwise */\r
151         char ecuid[DLT_ID_SIZE];       /**< ECU ID of daemon */\r
152         int sendserialheader;          /**< 1: send serial header; 0 don't send serial header */\r
153         int timingpackets;              /**< 1: send continous timing packets; 0 don't send continous timing packets */\r
154         DltBuffer client_ringbuffer; /**< Ring-buffer for storing received logs while no client connection is available */\r
155         char runtime_application_cfg[256]; /**< Path and filename of persistent application configuration */\r
156         char runtime_context_cfg[256]; /**< Path and filename of persistent context configuration */\r
157         char runtime_configuration[256]; /**< Path and filename of persistent configuration */\r
158     DltUserLogMode mode;        /**< Mode used for tracing: off, external, internal, both */\r
159     char state;                         /**< state for tracing: 0 = no client connected, 1 = client connected */\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 runtime_directory Directory of persistent configuration\r
167  * @param verbose if set to true verbose information is printed out.\r
168  * @return negative value if there was an error\r
169  */\r
170 int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory,int verbose);\r
171 /**\r
172  * De-Initialise the dlt daemon structure\r
173  * @param daemon pointer to dlt daemon structure\r
174  * @param verbose if set to true verbose information is printed out.\r
175  * @return negative value if there was an error\r
176  */\r
177 int dlt_daemon_free(DltDaemon *daemon,int verbose);\r
178 \r
179 /**\r
180  * Add (new) application to internal application management\r
181  * @param daemon pointer to dlt daemon structure\r
182  * @param apid pointer to application id\r
183  * @param pid process id of user application\r
184  * @param description description of application\r
185  * @param verbose if set to true verbose information is printed out.\r
186  * @return Pointer to added context, null pointer on error\r
187  */\r
188 DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pid_t pid,char *description, int verbose);\r
189 /**\r
190  * Delete application from internal application management\r
191  * @param daemon pointer to dlt daemon structure\r
192  * @param application pointer to application to be deleted\r
193  * @param verbose if set to true verbose information is printed out.\r
194  * @return negative value if there was an error\r
195  */\r
196 int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *application, int verbose);\r
197 /**\r
198  * Find application with specific application id\r
199  * @param daemon pointer to dlt daemon structure\r
200  * @param apid pointer to application id\r
201  * @param verbose if set to true verbose information is printed out.\r
202  * @return Pointer to application, null pointer on error or not found\r
203  */\r
204 DltDaemonApplication* dlt_daemon_application_find(DltDaemon *daemon,char *apid,int verbose);\r
205 /**\r
206  * Load applications from file to internal context management\r
207  * @param daemon pointer to dlt daemon structure\r
208  * @param filename name of file to be used for loading\r
209  * @param verbose if set to true verbose information is printed out.\r
210  * @return negative value if there was an error\r
211  */\r
212 int dlt_daemon_applications_load(DltDaemon *daemon,const char *filename, int verbose);\r
213 /**\r
214  * Save applications from internal context management to file\r
215  * @param daemon pointer to dlt daemon structure\r
216  * @param filename name of file to be used for saving\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_save(DltDaemon *daemon,const char *filename, int verbose);\r
221 /**\r
222  * Clear all applications in internal application management\r
223  * @param daemon pointer to dlt daemon structure\r
224  * @param verbose if set to true verbose information is printed out.\r
225  * @return negative value if there was an error\r
226  */\r
227 int dlt_daemon_applications_clear(DltDaemon *daemon,int verbose);\r
228 \r
229 /**\r
230  * Add (new) context to internal context management\r
231  * @param daemon pointer to dlt daemon structure\r
232  * @param apid pointer to application id\r
233  * @param ctid pointer to context id\r
234  * @param log_level log level of context\r
235  * @param trace_status trace status of context\r
236  * @param log_level_pos offset of context in context field on user application\r
237  * @param user_handle connection handle for connection to user application\r
238  * @param description description of context\r
239  * @param verbose if set to true verbose information is printed out.\r
240  * @return Pointer to added context, null pointer on error\r
241  */\r
242 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
243 /**\r
244  * Delete context from internal context management\r
245  * @param daemon pointer to dlt daemon structure\r
246  * @param context pointer to context to be deleted\r
247  * @param verbose if set to true verbose information is printed out.\r
248  * @return negative value if there was an error\r
249  */\r
250 int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int verbose);\r
251 /**\r
252  * Find context with specific application id and context id\r
253  * @param daemon pointer to dlt daemon structure\r
254  * @param apid pointer to application id\r
255  * @param ctid pointer to context id\r
256  * @param verbose if set to true verbose information is printed out.\r
257  * @return Pointer to context, null pointer on error or not found\r
258  */\r
259 DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,char *apid,char *ctid,int verbose);\r
260 /**\r
261  * Clear all contexts in internal context management\r
262  * @param daemon pointer to dlt daemon structure\r
263  * @param verbose if set to true verbose information is printed out.\r
264  * @return negative value if there was an error\r
265  */\r
266 int dlt_daemon_contexts_clear(DltDaemon *daemon,int verbose);\r
267 /**\r
268  * Load contexts from file to internal context management\r
269  * @param daemon pointer to dlt daemon structure\r
270  * @param filename name of file to be used for loading\r
271  * @param verbose if set to true verbose information is printed out.\r
272  * @return negative value if there was an error\r
273  */\r
274 int dlt_daemon_contexts_load(DltDaemon *daemon,const char *filename, int verbose);\r
275 /**\r
276  * Save contexts from internal context management to file\r
277  * @param daemon pointer to dlt daemon structure\r
278  * @param filename name of file to be used for saving\r
279  * @param verbose if set to true verbose information is printed out.\r
280  * @return negative value if there was an error\r
281  */\r
282 int dlt_daemon_contexts_save(DltDaemon *daemon,const char *filename, int verbose);\r
283 /**\r
284  * Load persistant configuration\r
285  * @param daemon pointer to dlt daemon structure\r
286  * @param filename name of file to be used for loading\r
287  * @param verbose if set to true verbose information is printed out.\r
288  * @return negative value if there was an error\r
289  */\r
290 int dlt_daemon_configuration_load(DltDaemon *daemon,const char *filename, int verbose);\r
291 /**\r
292  * Save configuration persistantly\r
293  * @param daemon pointer to dlt daemon structure\r
294  * @param filename name of file to be used for saving\r
295  * @param verbose if set to true verbose information is printed out.\r
296  * @return negative value if there was an error\r
297  */\r
298 int dlt_daemon_configuration_save(DltDaemon *daemon,const char *filename, int verbose);\r
299 \r
300 \r
301 /**\r
302  * Send user message DLT_USER_MESSAGE_LOG_LEVEL to user application\r
303  * @param daemon pointer to dlt daemon structure\r
304  * @param context pointer to context for response\r
305  * @param verbose if set to true verbose information is printed out.\r
306  * @return negative value if there was an error\r
307  */\r
308 int dlt_daemon_user_send_log_level(DltDaemon *daemon,DltDaemonContext *context, int verbose);\r
309 \r
310 /**\r
311  * Send user message DLT_USER_MESSAGE_LOG_STATE to user application\r
312  * @param daemon pointer to dlt daemon structure\r
313  * @param app pointer to application for response\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_user_send_log_state(DltDaemon *daemon,DltDaemonApplication *app,int verbose);\r
318 \r
319 /**\r
320  * Send user messages to all user applications using default context, or trace status\r
321  * to update those values\r
322  * @param daemon pointer to dlt daemon structure\r
323  * @param verbose if set to true verbose information is printed out.\r
324  */\r
325 void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose);\r
326 \r
327 /**\r
328  * Send user messages to all user applications the log status\r
329  * everytime the client is connected or disconnected.\r
330  * @param daemon pointer to dlt daemon structure\r
331  * @param verbose if set to true verbose information is printed out.\r
332  */\r
333 void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose);\r
334 \r
335 /**\r
336  * Process received control message from dlt client\r
337  * @param sock connection handle used for sending response\r
338  * @param daemon pointer to dlt daemon structure\r
339  * @param msg pointer to received control message\r
340  * @param verbose if set to true verbose information is printed out.\r
341  */\r
342 int dlt_daemon_control_process_control(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
343 /**\r
344  * Generate response to control message from dlt client\r
345  * @param sock connection handle used for sending response\r
346  * @param daemon pointer to dlt daemon structure\r
347  * @param service_id service id of control message\r
348  * @param status status of response (e.g. ok, not supported, error)\r
349  * @param verbose if set to true verbose information is printed out.\r
350  */\r
351 void dlt_daemon_control_service_response(int sock, DltDaemon *daemon, uint32_t service_id, int8_t status, int verbose);\r
352 /**\r
353  * Send out response message to dlt client\r
354  * @param sock connection handle used for sending response\r
355  * @param daemon pointer to dlt daemon structure\r
356  * @param msg pointer to response message\r
357  * @param appid pointer to application id to be used in response message\r
358  * @param contid pointer to context id to be used in response message\r
359  * @param verbose if set to true verbose information is printed out.\r
360  */\r
361 void dlt_daemon_control_send_control_message(int sock, DltDaemon *daemon, DltMessage *msg, char* appid, char* contid, int verbose);\r
362 \r
363 /**\r
364  * Process and generate response to received sw injection control message\r
365  * @param sock connection handle used for sending response\r
366  * @param daemon pointer to dlt daemon structure\r
367  * @param msg pointer to received sw injection control message\r
368  * @param verbose if set to true verbose information is printed out.\r
369  */\r
370 void dlt_daemon_control_callsw_cinjection(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
371 /**\r
372  * Process and generate response to received set log level control message\r
373  * @param sock connection handle used for sending response\r
374  * @param daemon pointer to dlt daemon structure\r
375  * @param msg pointer to received control message\r
376  * @param verbose if set to true verbose information is printed out.\r
377  */\r
378 void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
379 /**\r
380  * Process and generate response to received set trace status control message\r
381  * @param sock connection handle used for sending response\r
382  * @param daemon pointer to dlt daemon structure\r
383  * @param msg pointer to received control message\r
384  * @param verbose if set to true verbose information is printed out.\r
385  */\r
386 void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
387 /**\r
388  * Process and generate response to received set default log level control message\r
389  * @param sock connection handle used for sending response\r
390  * @param daemon pointer to dlt daemon structure\r
391  * @param msg pointer to received control message\r
392  * @param verbose if set to true verbose information is printed out.\r
393  */\r
394 void dlt_daemon_control_set_default_log_level(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
395 /**\r
396  * Process and generate response to received set default trace status control message\r
397  * @param sock connection handle used for sending response\r
398  * @param daemon pointer to dlt daemon structure\r
399  * @param msg pointer to received control message\r
400  * @param verbose if set to true verbose information is printed out.\r
401  */\r
402 void dlt_daemon_control_set_default_trace_status(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
403 /**\r
404  * Process and generate response to set timing packets control message\r
405  * @param sock connection handle used for sending response\r
406  * @param daemon pointer to dlt daemon structure\r
407  * @param msg pointer to received control message\r
408  * @param verbose if set to true verbose information is printed out.\r
409  */\r
410 void dlt_daemon_control_set_timing_packets(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
411 /**\r
412  * Process and generate response to received get software version control message\r
413  * @param sock connection handle used for sending response\r
414  * @param daemon pointer to dlt daemon structure\r
415  * @param verbose if set to true verbose information is printed out.\r
416  */\r
417 void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, int verbose);\r
418 /**\r
419  * Process and generate response to received get default log level control message\r
420  * @param sock connection handle used for sending response\r
421  * @param daemon pointer to dlt daemon structure\r
422  * @param verbose if set to true verbose information is printed out.\r
423  */\r
424 void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, int verbose);\r
425 /**\r
426  * Process and generate response to received get log info control message\r
427  * @param sock connection handle used for sending response\r
428  * @param daemon pointer to dlt daemon structure\r
429  * @param msg pointer to received control message\r
430  * @param verbose if set to true verbose information is printed out.\r
431  */\r
432 void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltMessage *msg, int verbose);\r
433 /**\r
434  * Process and generate response to message buffer overflow control message\r
435  * @param sock connection handle used for sending response\r
436  * @param daemon pointer to dlt daemon structure\r
437  * @param verbose if set to true verbose information is printed out.\r
438  */\r
439 void dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, int verbose);\r
440 /**\r
441  * Process reset to factory default control message\r
442  * @param daemon pointer to dlt daemon structure\r
443  * @param filename name of file containing the runtime defaults for applications\r
444  * @param filename1 name of file containing the runtime defaults for contexts\r
445  * @param verbose if set to true verbose information is printed out.\r
446  */\r
447 void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *filename, const char *filename1, int verbose);\r
448 /**\r
449  * Send time control message\r
450  * @param sock connection handle used for sending response\r
451  * @param daemon pointer to dlt daemon structure\r
452  * @param verbose if set to true verbose information is printed out.\r
453  */\r
454 void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose);\r
455 \r
456 #ifdef __cplusplus\r
457 }\r
458 #endif\r
459 \r
460 /**\r
461   \}\r
462 */\r
463 \r
464 #endif /* DLT_DAEMON_COMMON_H */\r