automotive-dlt
dlt_user_shared.c
Go to the documentation of this file.
1 /*
2  * @licence app begin@
3  * SPDX license identifier: MPL-2.0
4  *
5  * Copyright (C) 2011-2015, BMW AG
6  *
7  * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
8  *
9  * This Source Code Form is subject to the terms of the
10  * Mozilla Public License (MPL), v. 2.0.
11  * If a copy of the MPL was not distributed with this file,
12  * You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  * For further information see http://www.genivi.org/.
15  * @licence end@
16  */
17 
28 /*******************************************************************************
29 ** **
30 ** SRC-MODULE: dlt_user_shared.c **
31 ** **
32 ** TARGET : linux **
33 ** **
34 ** PROJECT : DLT **
35 ** **
36 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
37 ** Markus Klein **
38 ** **
39 ** PURPOSE : **
40 ** **
41 ** REMARKS : **
42 ** **
43 ** PLATFORM DEPENDANT [yes/no]: yes **
44 ** **
45 ** TO BE CHANGED BY USER [yes/no]: no **
46 ** **
47 *******************************************************************************/
48 
49 /*******************************************************************************
50 ** Author Identity **
51 ********************************************************************************
52 ** **
53 ** Initials Name Company **
54 ** -------- ------------------------- ---------------------------------- **
55 ** aw Alexander Wenzel BMW **
56 ** mk Markus Klein Fraunhofer ESK **
57 *******************************************************************************/
58 
59 /*******************************************************************************
60 ** Revision Control History **
61 *******************************************************************************/
62 
63 /*
64  * $LastChangedRevision: 1670 $
65  * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
66  * $LastChangedBy$
67  Initials Date Comment
68  aw 13.01.2010 initial
69  */
70 
71 #include <sys/stat.h>
72 #include <fcntl.h>
73 #include <errno.h>
74 
75 #include <sys/uio.h> /* writev() */
76 
77 #include "dlt_user_shared.h"
78 #include "dlt_user_shared_cfg.h"
79 
80 DltReturnValue dlt_user_set_userheader(DltUserHeader *userheader, uint32_t mtype)
81 {
82  if (userheader == 0)
83  return DLT_RETURN_ERROR;
84 
85  if (mtype <= 0)
86  return DLT_RETURN_ERROR;
87 
88  userheader->pattern[0] = 'D';
89  userheader->pattern[1] = 'U';
90  userheader->pattern[2] = 'H';
91  userheader->pattern[3] = 1;
92  userheader->message = mtype;
93 
94  return DLT_RETURN_OK;
95 }
96 
97 int dlt_user_check_userheader(DltUserHeader *userheader)
98 {
99  if (userheader==0)
100  {
101  return -1;
102  }
103 
104  return ((userheader->pattern[0] == 'D') &&
105  (userheader->pattern[1] == 'U') &&
106  (userheader->pattern[2] == 'H') &&
107  (userheader->pattern[3] == 1));
108 }
109 
110 DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void* ptr2, size_t len2)
111 {
112  struct iovec iov[2];
113  uint32_t bytes_written;
114 
115  if (handle<=0)
116  {
117  /* Invalid handle */
118  return DLT_RETURN_ERROR;
119  }
120 
121  iov[0].iov_base = ptr1;
122  iov[0].iov_len = len1;
123  iov[1].iov_base = ptr2;
124  iov[1].iov_len = len2;
125 
126  bytes_written = writev(handle, iov, 2);
127 
128  if (bytes_written!=(len1+len2))
129  {
130  return DLT_RETURN_ERROR;
131  }
132 
133  return DLT_RETURN_OK;
134 }
135 
136 DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void* ptr2, size_t len2, void *ptr3, size_t len3)
137 {
138  struct iovec iov[3];
139  uint32_t bytes_written;
140 
141  if (handle<=0)
142  {
143  /* Invalid handle */
144  return DLT_RETURN_ERROR;
145  }
146 
147  iov[0].iov_base = ptr1;
148  iov[0].iov_len = len1;
149  iov[1].iov_base = ptr2;
150  iov[1].iov_len = len2;
151  iov[2].iov_base = ptr3;
152  iov[2].iov_len = len3;
153 
154  bytes_written = writev(handle, iov, 3);
155 
156  if (bytes_written!=(len1+len2+len3))
157  {
158  switch(errno)
159  {
160  case EBADF:
161  {
162  return DLT_RETURN_PIPE_ERROR; /* EBADF - handle not open */
163  break;
164  }
165  case EPIPE:
166  {
167  return DLT_RETURN_PIPE_ERROR; /* EPIPE - pipe error */
168  break;
169  }
170  case EAGAIN:
171  {
172  return DLT_RETURN_PIPE_FULL; /* EAGAIN - data could not be written */
173  break;
174  }
175  default:
176  {
177  break;
178  }
179  }
180  return DLT_RETURN_ERROR;
181  }
182 
183  return DLT_RETURN_OK;
184 }
DltReturnValue
Definition: dlt_types.h:86
DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2)
DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3)
int dlt_user_check_userheader(DltUserHeader *userheader)
DltReturnValue dlt_user_set_userheader(DltUserHeader *userheader, uint32_t mtype)