0fd63674b85b65425d9c4eb334d6589b30565c37
[profile/ivi/dlt-daemon.git] / src / shared / dlt_user_shared.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_user_shared.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 **                      Author Identity                                       **\r
72 ********************************************************************************\r
73 **                                                                            **\r
74 ** Initials     Name                       Company                            **\r
75 ** --------     -------------------------  ---------------------------------- **\r
76 **  aw          Alexander Wenzel           BMW                                **\r
77 **  mk          Markus Klein               Fraunhofer ESK                     **\r
78 *******************************************************************************/\r
79 \r
80 #ifndef DLT_USER_SHARED_H\r
81 #define DLT_USER_SHARED_H\r
82
83 #include "dlt_types.h"\r
84 #include "dlt_user.h"\r
85 \r
86 #include <sys/types.h>\r
87
88 /**\r
89  * This are the return values for the functions dlt_user_log_out2() and dlt_user_log_out3()\r
90  */
91 typedef enum
92 {
93         DLT_RETURN_PIPE_FULL  = -3,
94         DLT_RETURN_PIPE_ERROR = -2,
95         DLT_RETURN_ERROR      = -1,
96         DLT_RETURN_OK         =  0
97 } DltReturnValue;
98 \r
99 /**\r
100  * This is the header of each message to be exchanged between application and daemon.\r
101  */\r
102 typedef struct\r
103 {\r
104         char pattern[DLT_ID_SIZE];      /**< This pattern should be DUH0x01 */\r
105         uint32_t message;               /**< messsage info */\r
106 } PACKED DltUserHeader;\r
107 \r
108 /**\r
109  * This is the internal message content to exchange control msg register app information between application and daemon.\r
110  */\r
111 typedef struct\r
112 {\r
113         char apid[DLT_ID_SIZE];          /**< application id */\r
114         pid_t pid;                       /**< process id of user application */\r
115     uint32_t description_length;     /**< length of description */\r
116 } PACKED DltUserControlMsgRegisterApplication;\r
117 \r
118 /**\r
119  * This is the internal message content to exchange control msg unregister app information between application and daemon.\r
120  */\r
121 typedef struct\r
122 {\r
123         char apid[DLT_ID_SIZE];         /**< application id */\r
124     pid_t pid;                      /**< process id of user application */\r
125 } PACKED DltUserControlMsgUnregisterApplication;\r
126 \r
127 /**\r
128  * This is the internal message content to exchange control msg register information between application and daemon.\r
129  */\r
130 typedef struct\r
131 {\r
132         char apid[DLT_ID_SIZE];          /**< application id */\r
133         char ctid[DLT_ID_SIZE];          /**< context id */\r
134         int32_t log_level_pos;           /**< offset in management structure on user-application side */\r
135         int8_t log_level;                /**< log level */\r
136         int8_t trace_status;             /**< trace status */\r
137         pid_t pid;                       /**< process id of user application */\r
138     uint32_t description_length;     /**< length of description */\r
139 } PACKED DltUserControlMsgRegisterContext;\r
140 \r
141 /**\r
142  * This is the internal message content to exchange control msg unregister information between application and daemon.\r
143  */\r
144 typedef struct\r
145 {\r
146         char apid[DLT_ID_SIZE];         /**< application id */\r
147         char ctid[DLT_ID_SIZE];         /**< context id */\r
148         pid_t pid;                      /**< process id of user application */\r
149 } PACKED DltUserControlMsgUnregisterContext;\r
150 \r
151 /**\r
152  * This is the internal message content to exchange control msg log level information between application and daemon.\r
153  */\r
154 typedef struct\r
155 {\r
156         uint8_t log_level;             /**< log level */\r
157         uint8_t trace_status;          /**< trace status */\r
158         int32_t log_level_pos;          /**< offset in management structure on user-application side */\r
159 } PACKED DltUserControlMsgLogLevel;\r
160 \r
161 /**\r
162  * This is the internal message content to exchange control msg injection information between application and daemon.\r
163  */\r
164 typedef struct\r
165 {\r
166         int32_t log_level_pos;          /**< offset in management structure on user-application side */\r
167         uint32_t service_id;            /**< service id of injection */\r
168     uint32_t data_length_inject;    /**< length of injection message data field */\r
169 } PACKED DltUserControlMsgInjection;\r
170 \r
171 /**\r
172  * This is the internal message content to exchange information about application log level and trace stats between\r
173  * application and daemon.\r
174  */\r
175 typedef struct\r
176 {\r
177     char apid[DLT_ID_SIZE];        /**< application id */\r
178         uint8_t log_level;             /**< log level */\r
179         uint8_t trace_status;          /**< trace status */\r
180 } PACKED DltUserControlMsgAppLogLevelTraceStatus;\r
181 \r
182 /**\r
183  * This is the internal message content to set the logging mode: off, external, internal, both.\r
184  */\r
185 typedef struct\r
186 {\r
187         int8_t log_mode;          /**< the mode to be used for logging: off, external, internal, both */\r
188 } PACKED DltUserControlMsgLogMode;\r
189 \r
190 /**\r
191  * This is the internal message content to get the logging state: 0 = off, 1 = external client connected.\r
192  */\r
193 typedef struct\r
194 {\r
195         int8_t log_state;          /**< the state to be used for logging state: 0 = off, 1 = external client connected */\r
196 } PACKED DltUserControlMsgLogState;\r
197 \r
198 /**************************************************************************************************\r
199 * The folowing functions are used shared between the user lib and the daemon implementation\r
200 **************************************************************************************************/\r
201 \r
202 /**\r
203  * Set user header marker and store message type in user header\r
204  * @param userheader pointer to the userheader\r
205  * @param mtype user message type of internal message\r
206  * @return negative value if there was an error {
207                         return -1;
208                     }\r
209  */\r
210 int dlt_user_set_userheader(DltUserHeader *userheader, uint32_t mtype);\r
211 \r
212 /**\r
213  * Check if user header contains its marker\r
214  * @param userheader pointer to the userheader\r
215  * @return 0 no, 1 yes, negative value if there was an error\r
216  */\r
217 int dlt_user_check_userheader(DltUserHeader *userheader);\r
218 \r
219 /**\r
220  * Atomic write to file descriptor, using vector of 2 elements\r
221  * @param handle file descriptor\r
222  * @param ptr1 generic pointer to first segment of data to be written\r
223  * @param len1 length of first segment of data to be written\r
224  * @param ptr2 generic pointer to second segment of data to be written\r
225  * @param len2 length of second segment of data to be written\r
226  * @return Value from DltReturnValue enum\r
227  */\r
228 DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void* ptr2, size_t len2);\r
229 \r
230 /**\r
231  * Atomic write to file descriptor, using vector of 3 elements\r
232  * @param handle file descriptor\r
233  * @param ptr1 generic pointer to first segment of data to be written\r
234  * @param len1 length of first segment of data to be written\r
235  * @param ptr2 generic pointer to second segment of data to be written\r
236  * @param len2 length of second segment of data to be written\r
237  * @param ptr3 generic pointer to third segment of data to be written\r
238  * @param len3 length of third segment of data to be written\r
239  * @return Value from DltReturnValue enum\r
240  */\r
241 DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void* ptr2, size_t len2, void *ptr3, size_t len3);\r
242 \r
243 #endif /* DLT_USER_SHARED_H */\r