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