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