2 * @licence app begin@
\r
3 * Copyright (C) 2012 BMW AG
\r
5 * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
\r
7 * Contributions are licensed to the GENIVI Alliance under one or more
\r
8 * Contribution License Agreements.
\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
16 * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012
\r
18 * \file dlt_daemon_common.h
\r
19 * For further information see http://www.genivi.org/.
\r
24 /*******************************************************************************
\r
26 ** SRC-MODULE: dlt_daemon_common.h **
\r
28 ** TARGET : linux **
\r
32 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
\r
39 ** PLATFORM DEPENDANT [yes/no]: yes **
\r
41 ** TO BE CHANGED BY USER [yes/no]: no **
\r
43 *******************************************************************************/
\r
45 /*******************************************************************************
\r
46 ** Author Identity **
\r
47 ********************************************************************************
\r
49 ** Initials Name Company **
\r
50 ** -------- ------------------------- ---------------------------------- **
\r
51 ** aw Alexander Wenzel BMW **
\r
52 ** mk Markus Klein Fraunhofer ESK **
\r
53 *******************************************************************************/
\r
55 /*******************************************************************************
\r
56 ** Revision Control History **
\r
57 *******************************************************************************/
\r
60 * $LastChangedRevision: 1670 $
\r
61 * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
\r
63 Initials Date Comment
\r
64 aw 15.02.2010 initial
\r
67 #ifndef DLT_DAEMON_COMMON_H
\r
68 #define DLT_DAEMON_COMMON_H
\r
71 \defgroup daemonapi DLT Daemon API
\r
72 \addtogroup daemonapi
\r
77 #include <semaphore.h>
\r
78 #include "dlt_common.h"
\r
79 #include "dlt_user.h"
\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
89 #define DLT_DAEMON_SEND_TO_ALL -3 /**< Constant value to identify the command "send to all" */
\r
90 #define DLT_DAEMON_SEND_FORCE -4 /**< Constant value to identify the command "send force to all" */
\r
92 /* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */
\r
94 #define DLT_DAEMON_SEM_LOCK() { sem_wait(&dlt_daemon_mutex); }
\r
95 #define DLT_DAEMON_SEM_FREE() { sem_post(&dlt_daemon_mutex); }
\r
96 extern sem_t dlt_daemon_mutex;
\r
99 * Definitions of DLT daemon logging states
\r
103 DLT_DAEMON_STATE_INIT = 0, /**< Initial state */
\r
104 DLT_DAEMON_STATE_BUFFER = 1, /**< logging is buffered until external logger is connected or internal logging is activated */
\r
105 DLT_DAEMON_STATE_BUFFER_FULL = 2, /**< then internal buffer is full, wait for connect from client */
\r
106 DLT_DAEMON_STATE_SEND_BUFFER = 3, /**< external logger is connected, but buffer is still not empty or external logger queue is full */
\r
107 DLT_DAEMON_STATE_SEND_DIRECT = 4 /**< External logger is connected or internal logging is active, and buffer is empty */
\r
111 * The parameters of a daemon application.
\r
115 char apid[DLT_ID_SIZE]; /**< application id */
\r
116 pid_t pid; /**< process id of user application */
\r
117 int user_handle; /**< connection handle for connection to user application */
\r
118 char *application_description; /**< context description */
\r
119 int num_contexts; /**< number of contexts for this application */
\r
120 } DltDaemonApplication;
\r
123 * The parameters of a daemon context.
\r
127 char apid[DLT_ID_SIZE]; /**< application id */
\r
128 char ctid[DLT_ID_SIZE]; /**< context id */
\r
129 int8_t log_level; /**< the current log level of the context */
\r
130 int8_t trace_status; /**< the current trace status of the context */
\r
131 int log_level_pos; /**< offset of context in context field on user application */
\r
132 int user_handle; /**< connection handle for connection to user application */
\r
133 char *context_description; /**< context description */
\r
134 } DltDaemonContext;
\r
137 * The parameters of a daemon.
\r
141 int num_contexts; /**< Total number of all contexts in all applications */
\r
142 DltDaemonContext *contexts; /**< Pointer to contexts */
\r
143 int num_applications; /**< Number of available application */
\r
144 DltDaemonApplication *applications; /**< Pointer to applications */
\r
145 int8_t default_log_level; /**< Default log level (of daemon) */
\r
146 int8_t default_trace_status; /**< Default trace status (of daemon) */
\r
147 unsigned int overflow_counter; /**< counts the number of lost messages. */
\r
148 int runtime_context_cfg_loaded; /**< Set to one, if runtime context configuration has been loaded, zero otherwise */
\r
149 char ecuid[DLT_ID_SIZE]; /**< ECU ID of daemon */
\r
150 int sendserialheader; /**< 1: send serial header; 0 don't send serial header */
\r
151 int timingpackets; /**< 1: send continous timing packets; 0 don't send continous timing packets */
\r
152 DltBuffer client_ringbuffer; /**< Ring-buffer for storing received logs while no client connection is available */
\r
153 char runtime_application_cfg[PATH_MAX + 1]; /**< Path and filename of persistent application configuration. Set to path max, as it specifies a full path*/
\r
154 char runtime_context_cfg[PATH_MAX + 1]; /**< Path and filename of persistent context configuration */
\r
155 char runtime_configuration[PATH_MAX + 1]; /**< Path and filename of persistent configuration */
\r
156 DltUserLogMode mode; /**< Mode used for tracing: off, external, internal, both */
\r
157 char connectionState; /**< state for tracing: 0 = no client connected, 1 = client connected */
\r
158 char *ECUVersionString; /**< Version string to send to client. Loaded from a file at startup. May be null. */
\r
159 DltDaemonState state; /**< the current logging state of dlt daemon. */
\r
163 * Initialise the dlt daemon structure
\r
164 * This function must be called before using further dlt daemon structure
\r
165 * @param daemon pointer to dlt daemon structure
\r
166 * @param RingbufferMinSize ringbuffer size
\r
167 * @param RingbufferMaxSize ringbuffer size
\r
168 * @param RingbufferStepSize ringbuffer size
\r
169 * @param runtime_directory Directory of persistent configuration
\r
170 * @param verbose if set to true verbose information is printed out.
\r
171 * @return negative value if there was an error
\r
173 int dlt_daemon_init(DltDaemon *daemon,unsigned long RingbufferMinSize,unsigned long RingbufferMaxSize,unsigned long RingbufferStepSize,const char *runtime_directory,int verbose);
\r
175 * De-Initialise the dlt daemon structure
\r
176 * @param daemon pointer to dlt daemon structure
\r
177 * @param verbose if set to true verbose information is printed out.
\r
178 * @return negative value if there was an error
\r
180 int dlt_daemon_free(DltDaemon *daemon,int verbose);
\r
183 * Add (new) application to internal application management
\r
184 * @param daemon pointer to dlt daemon structure
\r
185 * @param apid pointer to application id
\r
186 * @param pid process id of user application
\r
187 * @param description description of application
\r
188 * @param verbose if set to true verbose information is printed out.
\r
189 * @return Pointer to added context, null pointer on error
\r
191 DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pid_t pid,char *description, int verbose);
\r
193 * Delete application from internal application management
\r
194 * @param daemon pointer to dlt daemon structure
\r
195 * @param application pointer to application to be deleted
\r
196 * @param verbose if set to true verbose information is printed out.
\r
197 * @return negative value if there was an error
\r
199 int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *application, int verbose);
\r
201 * Find application with specific application id
\r
202 * @param daemon pointer to dlt daemon structure
\r
203 * @param apid pointer to application id
\r
204 * @param verbose if set to true verbose information is printed out.
\r
205 * @return Pointer to application, null pointer on error or not found
\r
207 DltDaemonApplication* dlt_daemon_application_find(DltDaemon *daemon,char *apid,int verbose);
\r
209 * Load applications from file to internal context management
\r
210 * @param daemon pointer to dlt daemon structure
\r
211 * @param filename name of file to be used for loading
\r
212 * @param verbose if set to true verbose information is printed out.
\r
213 * @return negative value if there was an error
\r
215 int dlt_daemon_applications_load(DltDaemon *daemon,const char *filename, int verbose);
\r
217 * Save applications from internal context management to file
\r
218 * @param daemon pointer to dlt daemon structure
\r
219 * @param filename name of file to be used for saving
\r
220 * @param verbose if set to true verbose information is printed out.
\r
221 * @return negative value if there was an error
\r
223 int dlt_daemon_applications_save(DltDaemon *daemon,const char *filename, int verbose);
\r
225 * Invalidate all applications fd, if fd is reused
\r
226 * @param daemon pointer to dlt daemon structure
\r
227 * @param fd file descriptor
\r
228 * @param verbose if set to true verbose information is printed out.
\r
229 * @return negative value if there was an error
\r
231 int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon,int fd,int verbose);
\r
233 * Clear all applications in internal application management
\r
234 * @param daemon pointer to dlt daemon structure
\r
235 * @param verbose if set to true verbose information is printed out.
\r
236 * @return negative value if there was an error
\r
238 int dlt_daemon_applications_clear(DltDaemon *daemon,int verbose);
\r
241 * Add (new) context to internal context management
\r
242 * @param daemon pointer to dlt daemon structure
\r
243 * @param apid pointer to application id
\r
244 * @param ctid pointer to context id
\r
245 * @param log_level log level of context
\r
246 * @param trace_status trace status of context
\r
247 * @param log_level_pos offset of context in context field on user application
\r
248 * @param user_handle connection handle for connection to user application
\r
249 * @param description description of context
\r
250 * @param verbose if set to true verbose information is printed out.
\r
251 * @return Pointer to added context, null pointer on error
\r
253 DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon,char *apid,char *ctid,int8_t log_level,int8_t trace_status,int log_level_pos, int user_handle,char *description,int verbose);
\r
255 * Delete context from internal context management
\r
256 * @param daemon pointer to dlt daemon structure
\r
257 * @param context pointer to context to be deleted
\r
258 * @param verbose if set to true verbose information is printed out.
\r
259 * @return negative value if there was an error
\r
261 int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int verbose);
\r
263 * Find context with specific application id and context id
\r
264 * @param daemon pointer to dlt daemon structure
\r
265 * @param apid pointer to application id
\r
266 * @param ctid pointer to context id
\r
267 * @param verbose if set to true verbose information is printed out.
\r
268 * @return Pointer to context, null pointer on error or not found
\r
270 DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,char *apid,char *ctid,int verbose);
\r
272 * Invalidate all contexts fd, if fd is reused
\r
273 * @param daemon pointer to dlt daemon structure
\r
274 * @param fd file descriptor
\r
275 * @param verbose if set to true verbose information is printed out.
\r
276 * @return negative value if there was an error
\r
278 int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon,int fd,int verbose);
\r
280 * Clear all contexts in internal context management
\r
281 * @param daemon pointer to dlt daemon structure
\r
282 * @param verbose if set to true verbose information is printed out.
\r
283 * @return negative value if there was an error
\r
285 int dlt_daemon_contexts_clear(DltDaemon *daemon,int verbose);
\r
287 * Load contexts from file to internal context management
\r
288 * @param daemon pointer to dlt daemon structure
\r
289 * @param filename name of file to be used for loading
\r
290 * @param verbose if set to true verbose information is printed out.
\r
291 * @return negative value if there was an error
\r
293 int dlt_daemon_contexts_load(DltDaemon *daemon,const char *filename, int verbose);
\r
295 * Save contexts from internal context management to file
\r
296 * @param daemon pointer to dlt daemon structure
\r
297 * @param filename name of file to be used for saving
\r
298 * @param verbose if set to true verbose information is printed out.
\r
299 * @return negative value if there was an error
\r
301 int dlt_daemon_contexts_save(DltDaemon *daemon,const char *filename, int verbose);
\r
303 * Load persistant configuration
\r
304 * @param daemon pointer to dlt daemon structure
\r
305 * @param filename name of file to be used for loading
\r
306 * @param verbose if set to true verbose information is printed out.
\r
307 * @return negative value if there was an error
\r
309 int dlt_daemon_configuration_load(DltDaemon *daemon,const char *filename, int verbose);
\r
311 * Save configuration persistantly
\r
312 * @param daemon pointer to dlt daemon structure
\r
313 * @param filename name of file to be used for saving
\r
314 * @param verbose if set to true verbose information is printed out.
\r
315 * @return negative value if there was an error
\r
317 int dlt_daemon_configuration_save(DltDaemon *daemon,const char *filename, int verbose);
\r
321 * Send user message DLT_USER_MESSAGE_LOG_LEVEL to user application
\r
322 * @param daemon pointer to dlt daemon structure
\r
323 * @param context pointer to context for response
\r
324 * @param verbose if set to true verbose information is printed out.
\r
325 * @return negative value if there was an error
\r
327 int dlt_daemon_user_send_log_level(DltDaemon *daemon,DltDaemonContext *context, int verbose);
\r
330 * Send user message DLT_USER_MESSAGE_LOG_STATE to user application
\r
331 * @param daemon pointer to dlt daemon structure
\r
332 * @param app pointer to application for response
\r
333 * @param verbose if set to true verbose information is printed out.
\r
334 * @return negative value if there was an error
\r
336 int dlt_daemon_user_send_log_state(DltDaemon *daemon,DltDaemonApplication *app,int verbose);
\r
339 * Send user messages to all user applications using default context, or trace status
\r
340 * to update those values
\r
341 * @param daemon pointer to dlt daemon structure
\r
342 * @param verbose if set to true verbose information is printed out.
\r
344 void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose);
\r
347 * Send user messages to all user applications the log status
\r
348 * everytime the client is connected or disconnected.
\r
349 * @param daemon pointer to dlt daemon structure
\r
350 * @param verbose if set to true verbose information is printed out.
\r
352 void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose);
\r
355 * Process reset to factory default control message
\r
356 * @param daemon pointer to dlt daemon structure
\r
357 * @param filename name of file containing the runtime defaults for applications
\r
358 * @param filename1 name of file containing the runtime defaults for contexts
\r
359 * @param verbose if set to true verbose information is printed out.
\r
361 void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *filename, const char *filename1, int verbose);
\r
364 * Change the logging state of dlt daemon
\r
365 * @param daemon pointer to dlt daemon structure
\r
366 * @param newState the requested new state
\r
368 void dlt_daemon_change_state(DltDaemon *daemon, DltDaemonState newState);
\r
378 #endif /* DLT_DAEMON_COMMON_H */
\r