automotive-dlt
dlt-adaptor-stdin.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 
27 /*******************************************************************************
28 ** **
29 ** SRC-MODULE: dlt-adaptor-stdin.c **
30 ** **
31 ** TARGET : linux **
32 ** **
33 ** PROJECT : DLT **
34 ** **
35 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
36 ** Markus Klein **
37 ** **
38 ** PURPOSE : **
39 ** **
40 ** REMARKS : **
41 ** **
42 ** PLATFORM DEPENDANT [yes/no]: yes **
43 ** **
44 ** TO BE CHANGED BY USER [yes/no]: no **
45 ** **
46 *******************************************************************************/
47 
48 /*******************************************************************************
49 ** Author Identity **
50 ********************************************************************************
51 ** **
52 ** Initials Name Company **
53 ** -------- ------------------------- ---------------------------------- **
54 ** aw Alexander Wenzel BMW **
55 ** mk Markus Klein Fraunhofer ESK **
56 *******************************************************************************/
57 
58 /*******************************************************************************
59 ** Revision Control History **
60 *******************************************************************************/
61 
62 /*
63  * $LastChangedRevision: 1670 $
64  * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
65  * $LastChangedBy$
66 */
67 
68 #include <stdio.h>
69 #include <stdlib.h>
70 #include <string.h>
71 
72 #include "dlt_common.h"
73 #include "dlt_user.h"
74 
75 #define MAXSTRLEN 1024
76 
77 #define PS_DLT_APP_DESC "stdin adaptor application"
78 #define PS_DLT_CONTEXT_DESC "stdin adaptor context"
79 
80 #define PS_DLT_APP "SINA"
81 #define PS_DLT_CONTEXT "SINC"
82 
84 
85 int main(int argc, char* argv[])
86 {
87  char str[MAXSTRLEN];
88  int opt;
89 
90  char apid[DLT_ID_SIZE];
91  char ctid[DLT_ID_SIZE];
92  char version[255];
93  int timeout = -1;
94  int verbosity = DLT_LOG_INFO;
95 
96  dlt_set_id(apid, PS_DLT_APP);
98 
99  while ((opt = getopt(argc, argv, "a:c:ht:v:")) != -1)
100  {
101  switch (opt)
102  {
103  case 'a':
104  {
105  dlt_set_id(apid,optarg);
106  break;
107  }
108  case 'c':
109  {
110  dlt_set_id(ctid,optarg);
111  break;
112  }
113  case 't':
114  {
115  timeout = atoi(optarg);
116  break;
117  }
118  case 'h':
119  {
120  dlt_get_version(version,255);
121 
122  printf("Usage: dlt-adaptor-stdin [options]\n");
123  printf("Adaptor for forwarding input from stdin to DLT daemon.\n");
124  printf("%s \n", version);
125  printf("Options:\n");
126  printf(" -a apid - Set application id to apid (default: SINA)\n");
127  printf(" -c ctid - Set context id to ctid (default: SINC)\n");
128  printf(" -t timeout - Set timeout when sending messages at exit, in ms (Default: 10000 = 10sec)\n");
129  printf(" -v verbosity level - Set verbosity level (Default: INFO, values: FATAL ERROR WARN INFO DEBUG VERBOSE)\n");
130  printf(" -h - This help\n");
131  return 0;
132  break;
133  }
134  case 'v':
135  {
136  if(!strcmp(optarg, "FATAL"))
137  {
138  verbosity = DLT_LOG_FATAL;
139  break;
140  }
141  else if(!strcmp(optarg, "ERROR"))
142  {
143  verbosity = DLT_LOG_ERROR;
144  break;
145  }
146  else if(!strcmp(optarg, "WARN"))
147  {
148  verbosity = DLT_LOG_WARN;
149  break;
150  }
151  else if(!strcmp(optarg, "INFO"))
152  {
153  verbosity = DLT_LOG_INFO;
154  break;
155  }
156  else if(!strcmp(optarg, "DEBUG"))
157  {
158  verbosity = DLT_LOG_DEBUG;
159  break;
160  }
161  else if(!strcmp(optarg, "VERBOSE"))
162  {
163  verbosity = DLT_LOG_VERBOSE;
164  break;
165  } else
166  {
167  printf("Wrong verbosity level, setting to INFO. Accepted values are: FATAL ERROR WARN INFO DEBUG VERBOSE\n");
168  verbosity = DLT_LOG_INFO;
169  break;
170  }
171  break;
172  }
173  default: /* '?' */
174  {
175  fprintf(stderr, "Unknown option '%c'\n", optopt);
176  return -1;
177  }
178  }
179  }
180 
183  if (timeout > -1)
184  {
186  }
187 
188  while (fgets(str, MAXSTRLEN, stdin))
189  {
190  if (strcmp(str,"")!=0)
191  {
192  DLT_LOG(mycontext, verbosity, DLT_STRING(str));
193  }
194  }
195 
198 
199  return 0;
200 }
201 
int dlt_set_resend_timeout_atexit(uint32_t timeout_in_milliseconds)
Definition: dlt_user.c:1301
#define PS_DLT_CONTEXT_DESC
#define PS_DLT_APP
#define DLT_UNREGISTER_APP()
#define DLT_ID_SIZE
Definition: dlt_common.h:204
#define PS_DLT_CONTEXT
void dlt_set_id(char *id, const char *text)
Definition: dlt_common.c:324
int main(int argc, char *argv[])
Definition: dlt-control.c:276
DLT_DECLARE_CONTEXT(mycontext)
#define DLT_REGISTER_APP(APPID, DESCRIPTION)
#define DLT_STRING(TEXT)
#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION)
#define DLT_UNREGISTER_CONTEXT(CONTEXT)
#define DLT_LOG(CONTEXT, LOGLEVEL, ARGS...)
void dlt_get_version(char *buf, size_t size)
Definition: dlt_common.c:3239
#define PS_DLT_APP_DESC
DltContext mycontext
static char str[DLT_DAEMON_TEXTBUFSIZE]
Definition: dlt-daemon.c:80
#define MAXSTRLEN