This is Unofficial EPICS BASE Doxygen Site
libComRegister.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2007 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The University of Saskatchewan
5 * Copyright (c) 2002 The Regents of the University of California, as
6 * Operator of Los Alamos National Laboratory.
7 * EPICS BASE is distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 
11 #include <stdlib.h>
12 
13 #include "iocsh.h"
14 #include "asLib.h"
15 #include "epicsStdioRedirect.h"
16 #include "epicsString.h"
17 #include "epicsTime.h"
18 #include "epicsThread.h"
19 #include "epicsMutex.h"
20 #include "envDefs.h"
21 #include "osiUnistd.h"
22 #include "logClient.h"
23 #include "errlog.h"
24 #include "taskwd.h"
25 #include "registry.h"
26 #include "epicsGeneralTime.h"
27 #include "libComRegister.h"
28 
29 
30 /* date */
31 void date(const char *format)
32 {
33  epicsTimeStamp now;
34  char nowText[80] = {'\0'};
35 
36  if (epicsTimeGetCurrent(&now)) {
37  puts("Current time not available.");
38  return;
39  }
40  if (format == NULL || format[0] == '\0')
41  format = "%Y/%m/%d %H:%M:%S.%06f";
42  epicsTimeToStrftime(nowText, sizeof(nowText), format, &now);
43  puts(nowText);
44 }
45 
46 static const iocshArg dateArg0 = { "format",iocshArgString};
47 static const iocshArg * const dateArgs[] = {&dateArg0};
48 static const iocshFuncDef dateFuncDef = {"date", 1, dateArgs};
49 static void dateCallFunc (const iocshArgBuf *args)
50 {
51  date(args[0].sval);
52 }
53 
54 /* echo */
56 {
57  if (str)
58  dbTranslateEscape(str, str); /* in-place is safe */
59  else
60  str = "";
61  printf("%s\n", str);
62 }
63 
64 static const iocshArg echoArg0 = { "string",iocshArgString};
65 static const iocshArg * const echoArgs[1] = {&echoArg0};
66 static const iocshFuncDef echoFuncDef = {"echo",1,echoArgs};
67 static void echoCallFunc(const iocshArgBuf *args)
68 {
69  echo(args[0].sval);
70 }
71 
72 /* chdir */
73 static const iocshArg chdirArg0 = { "directory name",iocshArgString};
74 static const iocshArg * const chdirArgs[1] = {&chdirArg0};
75 static const iocshFuncDef chdirFuncDef = {"cd",1,chdirArgs};
76 static void chdirCallFunc(const iocshArgBuf *args)
77 {
78  if (args[0].sval == NULL ||
79  iocshSetError(chdir(args[0].sval))) {
80  fprintf(stderr, "Invalid directory path, ignored\n");
81  }
82 }
83 
84 /* print current working directory */
85 static const iocshFuncDef pwdFuncDef = { "pwd", 0, 0 };
86 static void pwdCallFunc (const iocshArgBuf *args)
87 {
88  char buf[256];
89  char *pwd = getcwd ( buf, sizeof(buf) - 1 );
90  if ( pwd ) {
91  printf ( "%s\n", pwd );
92  }
93 }
94 
95 /* epicsEnvSet */
96 static const iocshArg epicsEnvSetArg0 = { "name",iocshArgString};
97 static const iocshArg epicsEnvSetArg1 = { "value",iocshArgString};
98 static const iocshArg * const epicsEnvSetArgs[2] = {&epicsEnvSetArg0,&epicsEnvSetArg1};
99 static const iocshFuncDef epicsEnvSetFuncDef = {"epicsEnvSet",2,epicsEnvSetArgs};
100 static void epicsEnvSetCallFunc(const iocshArgBuf *args)
101 {
102  char *name = args[0].sval;
103  char *value = args[1].sval;
104 
105  if (name == NULL) {
106  fprintf(stderr, "Missing environment variable name argument.\n");
107  return;
108  }
109  if (value == NULL) {
110  fprintf(stderr, "Missing environment variable value argument.\n");
111  return;
112  }
113  epicsEnvSet (name, value);
114 }
115 
116 /* epicsEnvUnset */
117 static const iocshArg epicsEnvUnsetArg0 = { "name",iocshArgString};
118 static const iocshArg * const epicsEnvUnsetArgs[1] = {&epicsEnvUnsetArg0};
119 static const iocshFuncDef epicsEnvUnsetFuncDef = {"epicsEnvUnset",1,epicsEnvUnsetArgs};
120 static void epicsEnvUnsetCallFunc(const iocshArgBuf *args)
121 {
122  char *name = args[0].sval;
123 
124  if (name == NULL) {
125  fprintf(stderr, "Missing environment variable name argument.\n");
126  return;
127  }
128  epicsEnvUnset (name);
129 }
130 
131 /* epicsParamShow */
133 {
135 }
136 
137 static const iocshFuncDef epicsParamShowFuncDef = {"epicsParamShow",0,NULL};
138 static void epicsParamShowCallFunc(const iocshArgBuf *args)
139 {
140  epicsParamShow ();
141 }
142 
143 /* epicsPrtEnvParams */
144 static const iocshFuncDef epicsPrtEnvParamsFuncDef = {"epicsPrtEnvParams",0,0};
145 static void epicsPrtEnvParamsCallFunc(const iocshArgBuf *args)
146 {
148 }
149 
150 /* epicsEnvShow */
151 static const iocshArg epicsEnvShowArg0 = { "[name]",iocshArgString};
152 static const iocshArg * const epicsEnvShowArgs[1] = {&epicsEnvShowArg0};
153 static const iocshFuncDef epicsEnvShowFuncDef = {"epicsEnvShow",1,epicsEnvShowArgs};
154 static void epicsEnvShowCallFunc(const iocshArgBuf *args)
155 {
156  epicsEnvShow (args[0].sval);
157 }
158 
159 /* registryDump */
160 static const iocshFuncDef registryDumpFuncDef = {"registryDump",0,NULL};
161 static void registryDumpCallFunc(const iocshArgBuf *args)
162 {
163  registryDump ();
164 }
165 
166 /* iocLogInit */
167 static const iocshFuncDef iocLogInitFuncDef = {"iocLogInit",0};
168 static void iocLogInitCallFunc(const iocshArgBuf *args)
169 {
170  iocLogInit ();
171 }
172 
173 /* iocLogDisable */
175 {
176  iocLogDisable = val;
177 }
178 
179 static const iocshArg iocLogDisableArg0 = {"(0,1)=>(false,true)",iocshArgInt};
180 static const iocshArg * const iocLogDisableArgs[1] = {&iocLogDisableArg0};
181 static const iocshFuncDef iocLogDisableFuncDef = {"setIocLogDisable",1,iocLogDisableArgs};
182 static void iocLogDisableCallFunc(const iocshArgBuf *args)
183 {
184  setIocLogDisable(args[0].ival);
185 }
186 
187 /* iocLogShow */
188 static const iocshArg iocLogShowArg0 = {"level",iocshArgInt};
189 static const iocshArg * const iocLogShowArgs[1] = {&iocLogShowArg0};
190 static const iocshFuncDef iocLogShowFuncDef = {"iocLogShow",1,iocLogShowArgs};
191 static void iocLogShowCallFunc(const iocshArgBuf *args)
192 {
193  iocLogShow (args[0].ival);
194 }
195 
196 /* eltc */
197 static const iocshArg eltcArg0 = {"(0,1)=>(false,true)",iocshArgInt};
198 static const iocshArg * const eltcArgs[1] = {&eltcArg0};
199 static const iocshFuncDef eltcFuncDef = {"eltc",1,eltcArgs};
200 static void eltcCallFunc(const iocshArgBuf *args)
201 {
202  eltc(args[0].ival);
203 }
204 
205 /* errlogInit */
206 static const iocshArg errlogInitArg0 = { "bufsize",iocshArgInt};
207 static const iocshArg * const errlogInitArgs[1] = {&errlogInitArg0};
208 static const iocshFuncDef errlogInitFuncDef =
209  {"errlogInit",1,errlogInitArgs};
210 static void errlogInitCallFunc(const iocshArgBuf *args)
211 {
212  errlogInit(args[0].ival);
213 }
214 
215 /* errlogInit2 */
216 static const iocshArg errlogInit2Arg0 = { "bufSize",iocshArgInt};
217 static const iocshArg errlogInit2Arg1 = { "maxMsgSize",iocshArgInt};
218 static const iocshArg * const errlogInit2Args[] =
219  {&errlogInit2Arg0, &errlogInit2Arg1};
220 static const iocshFuncDef errlogInit2FuncDef =
221  {"errlogInit2", 2, errlogInit2Args};
222 static void errlogInit2CallFunc(const iocshArgBuf *args)
223 {
224  errlogInit2(args[0].ival, args[1].ival);
225 }
226 
227 /* errlog */
228 IOCSH_STATIC_FUNC void errlog(const char *message)
229 {
230  errlogPrintfNoConsole("%s\n", message);
231 }
232 
233 static const iocshArg errlogArg0 = { "message",iocshArgString};
234 static const iocshArg * const errlogArgs[1] = {&errlogArg0};
235 static const iocshFuncDef errlogFuncDef = {"errlog",1,errlogArgs};
236 static void errlogCallFunc(const iocshArgBuf *args)
237 {
238  errlog(args[0].sval);
239  errlogFlush();
240 }
241 
242 /* iocLogPrefix */
243 static const iocshArg iocLogPrefixArg0 = { "prefix",iocshArgString};
244 static const iocshArg * const iocLogPrefixArgs[1] = {&iocLogPrefixArg0};
245 static const iocshFuncDef iocLogPrefixFuncDef = {"iocLogPrefix",1,iocLogPrefixArgs};
246 static void iocLogPrefixCallFunc(const iocshArgBuf *args)
247 {
248  iocLogPrefix(args[0].sval);
249 }
250 
251 /* epicsThreadShowAll */
252 static const iocshArg epicsThreadShowAllArg0 = { "level",iocshArgInt};
253 static const iocshArg * const epicsThreadShowAllArgs[1] = {&epicsThreadShowAllArg0};
254 static const iocshFuncDef epicsThreadShowAllFuncDef =
255  {"epicsThreadShowAll",1,epicsThreadShowAllArgs};
256 static void epicsThreadShowAllCallFunc(const iocshArgBuf *args)
257 {
258  epicsThreadShowAll(args[0].ival);
259 }
260 
261 /* epicsThreadShow */
262 static const iocshArg threadArg0 = { "[-level] [thread ...]", iocshArgArgv};
263 static const iocshArg * const threadArgs[1] = { &threadArg0 };
264 static const iocshFuncDef threadFuncDef = {"epicsThreadShow",1,threadArgs};
265 static void threadCallFunc(const iocshArgBuf *args)
266 {
267  int i = 1;
268  int first = 1;
269  int level = 0;
270  const char *cp;
271  epicsThreadId tid;
272  unsigned long ltmp;
273  int argc = args[0].aval.ac;
274  char **argv = args[0].aval.av;
275  char *endp;
276 
277  if ((i < argc) && (*(cp = argv[i]) == '-')) {
278  level = atoi (cp + 1);
279  i++;
280  }
281  if (i >= argc) {
282  epicsThreadShowAll (level);
283  return;
284  }
285  for ( ; i < argc ; i++) {
286  cp = argv[i];
287  ltmp = strtoul (cp, &endp, 0);
288  if (*endp) {
289  tid = epicsThreadGetId (cp);
290  if (!tid) {
291  fprintf(stderr, "\t'%s' is not a known thread name\n", cp);
292  continue;
293  }
294  }
295  else {
296  tid = (epicsThreadId)ltmp;
297  }
298  if (first) {
299  epicsThreadShow (0, level);
300  first = 0;
301  }
302  epicsThreadShow (tid, level);
303  }
304 }
305 
306 /* taskwdShow */
307 static const iocshArg taskwdShowArg0 = { "level",iocshArgInt};
308 static const iocshArg * const taskwdShowArgs[1] = {&taskwdShowArg0};
309 static const iocshFuncDef taskwdShowFuncDef =
310  {"taskwdShow",1,taskwdShowArgs};
311 static void taskwdShowCallFunc(const iocshArgBuf *args)
312 {
313  taskwdShow(args[0].ival);
314 }
315 
316 /* epicsMutexShowAll */
317 static const iocshArg epicsMutexShowAllArg0 = { "onlyLocked",iocshArgInt};
318 static const iocshArg epicsMutexShowAllArg1 = { "level",iocshArgInt};
319 static const iocshArg * const epicsMutexShowAllArgs[2] =
320  {&epicsMutexShowAllArg0,&epicsMutexShowAllArg1};
321 static const iocshFuncDef epicsMutexShowAllFuncDef =
322  {"epicsMutexShowAll",2,epicsMutexShowAllArgs};
323 static void epicsMutexShowAllCallFunc(const iocshArgBuf *args)
324 {
325  epicsMutexShowAll(args[0].ival,args[1].ival);
326 }
327 
328 /* epicsThreadSleep */
329 static const iocshArg epicsThreadSleepArg0 = { "seconds",iocshArgDouble};
330 static const iocshArg * const epicsThreadSleepArgs[1] = {&epicsThreadSleepArg0};
331 static const iocshFuncDef epicsThreadSleepFuncDef =
332  {"epicsThreadSleep",1,epicsThreadSleepArgs};
333 static void epicsThreadSleepCallFunc(const iocshArgBuf *args)
334 {
335  epicsThreadSleep(args[0].dval);
336 }
337 
338 /* epicsThreadResume */
339 static const iocshArg epicsThreadResumeArg0 = { "[thread ...]", iocshArgArgv};
340 static const iocshArg * const epicsThreadResumeArgs[1] = { &epicsThreadResumeArg0 };
341 static const iocshFuncDef epicsThreadResumeFuncDef = {"epicsThreadResume",1,epicsThreadResumeArgs};
342 static void epicsThreadResumeCallFunc(const iocshArgBuf *args)
343 {
344  int i;
345  const char *cp;
346  epicsThreadId tid;
347  unsigned long ltmp;
348  char nameBuf[64];
349  int argc = args[0].aval.ac;
350  char **argv = args[0].aval.av;
351  char *endp;
352 
353  for (i = 1 ; i < argc ; i++) {
354  cp = argv[i];
355  ltmp = strtoul(cp, &endp, 0);
356  if (*endp) {
357  tid = epicsThreadGetId(cp);
358  if (!tid) {
359  fprintf(stderr, "'%s' is not a valid thread name\n", cp);
360  continue;
361  }
362  }
363  else {
364  tid =(epicsThreadId)ltmp;
365  epicsThreadGetName(tid, nameBuf, sizeof nameBuf);
366  if (nameBuf[0] == '\0') {
367  fprintf(stderr, "'%s' is not a valid thread id\n", cp);
368  continue;
369  }
370 
371  }
372  if (!epicsThreadIsSuspended(tid)) {
373  fprintf(stderr, "Thread %s is not suspended\n", cp);
374  continue;
375  }
376  epicsThreadResume(tid);
377  }
378 }
379 
380 /* generalTimeReport */
381 static const iocshArg generalTimeReportArg0 = { "interest_level", iocshArgArgv};
382 static const iocshArg * const generalTimeReportArgs[1] = { &generalTimeReportArg0 };
383 static const iocshFuncDef generalTimeReportFuncDef = {"generalTimeReport",1,generalTimeReportArgs};
384 static void generalTimeReportCallFunc(const iocshArgBuf *args)
385 {
386  generalTimeReport(args[0].ival);
387 }
388 
389 /* installLastResortEventProvider */
390 static const iocshFuncDef installLastResortEventProviderFuncDef = {"installLastResortEventProvider", 0, NULL};
391 static void installLastResortEventProviderCallFunc(const iocshArgBuf *args)
392 {
394 }
395 
396 static iocshVarDef asCheckClientIPDef[] = { { "asCheckClientIP", iocshArgInt, 0 }, { NULL, iocshArgInt, NULL } };
397 
398 void epicsStdCall libComRegister(void)
399 {
400  iocshRegister(&dateFuncDef, dateCallFunc);
401  iocshRegister(&echoFuncDef, echoCallFunc);
402  iocshRegister(&chdirFuncDef, chdirCallFunc);
403  iocshRegister(&pwdFuncDef, pwdCallFunc);
404 
405  iocshRegister(&epicsEnvSetFuncDef, epicsEnvSetCallFunc);
406  iocshRegister(&epicsEnvUnsetFuncDef, epicsEnvUnsetCallFunc);
407  iocshRegister(&epicsParamShowFuncDef, epicsParamShowCallFunc);
408  iocshRegister(&epicsPrtEnvParamsFuncDef, epicsPrtEnvParamsCallFunc);
409  iocshRegister(&epicsEnvShowFuncDef, epicsEnvShowCallFunc);
410  iocshRegister(&registryDumpFuncDef, registryDumpCallFunc);
411 
412  iocshRegister(&iocLogInitFuncDef, iocLogInitCallFunc);
413  iocshRegister(&iocLogDisableFuncDef, iocLogDisableCallFunc);
414  iocshRegister(&iocLogShowFuncDef, iocLogShowCallFunc);
415  iocshRegister(&eltcFuncDef, eltcCallFunc);
416  iocshRegister(&errlogInitFuncDef,errlogInitCallFunc);
417  iocshRegister(&errlogInit2FuncDef,errlogInit2CallFunc);
418  iocshRegister(&errlogFuncDef, errlogCallFunc);
419  iocshRegister(&iocLogPrefixFuncDef, iocLogPrefixCallFunc);
420 
421  iocshRegister(&epicsThreadShowAllFuncDef,epicsThreadShowAllCallFunc);
422  iocshRegister(&threadFuncDef, threadCallFunc);
423  iocshRegister(&taskwdShowFuncDef,taskwdShowCallFunc);
424  iocshRegister(&epicsMutexShowAllFuncDef,epicsMutexShowAllCallFunc);
425  iocshRegister(&epicsThreadSleepFuncDef,epicsThreadSleepCallFunc);
426  iocshRegister(&epicsThreadResumeFuncDef,epicsThreadResumeCallFunc);
427 
428  iocshRegister(&generalTimeReportFuncDef,generalTimeReportCallFunc);
429  iocshRegister(&installLastResortEventProviderFuncDef, installLastResortEventProviderCallFunc);
430 
431  asCheckClientIPDef[0].pval = &asCheckClientIP;
432  iocshRegisterVariable(asCheckClientIPDef);
433 }
void errlogFlush(void)
Definition: errlog.c:529
The generalTime framework provides a mechanism for several time providers to be present within the sy...
Definition: link.h:174
LIBCOM_API int asCheckClientIP
Definition: asLibRoutines.c:31
int errlogInit2(int bufsize, int maxMsgSize)
Definition: errlog.c:500
struct iocshArgBuf::@13 aval
int i
Definition: scan.c:967
Routines to get and set EPICS environment parameters.
#define printf
Definition: epicsStdio.h:41
void epicsStdCall iocshRegister(const iocshFuncDef *piocshFuncDef, iocshCallFunc func)
Definition: iocsh.cpp:111
struct epicsThreadOSD * epicsThreadId
Definition: epicsThread.h:106
LIBCOM_API void epicsStdCall epicsThreadShowAll(unsigned int level)
Definition: osdThread.c:883
#define NULL
Definition: catime.c:38
LIBCOM_API long epicsStdCall epicsPrtEnvParams(void)
Prints all configuration parameters and their current value.
Definition: envSubr.c:384
char * sval
Definition: iocsh.h:42
LIBCOM_API void epicsStdCall epicsThreadShow(epicsThreadId id, unsigned int level)
Definition: osdThread.c:903
#define str(v)
char ** av
Definition: iocsh.h:46
#define IOCSH_STATIC_FUNC
Definition: iocsh.h:23
LIBCOM_API void epicsStdCall epicsEnvSet(const char *name, const char *value)
Set an environment variable&#39;s value.
Definition: osdEnv.c:35
int errlogInit(int bufsize)
Definition: errlog.c:524
IOCSH_STATIC_FUNC void echo(char *str)
int dbTranslateEscape(char *dst, const char *src)
Definition: epicsString.c:30
LIBCOM_API void epicsStdCall epicsEnvUnset(const char *name)
Clear the value of an environment variable.
Definition: osdEnv.c:46
LIBCOM_API size_t epicsStdCall epicsTimeToStrftime(char *pBuff, size_t bufLength, const char *pFormat, const epicsTimeStamp *pTS)
Convert epicsTimeStamp to string. See epicsTime::strftime()
Definition: epicsTime.cpp:1120
int epicsStdCall iocLogInit(void)
Definition: iocLog.c:121
#define puts
Definition: epicsStdio.h:46
IOCSH_STATIC_FUNC void setIocLogDisable(int val)
APIs for the epicsMutex mutual exclusion semaphore.
int ac
Definition: iocsh.h:45
int errlogPrintfNoConsole(const char *pFormat,...)
Definition: errlog.c:186
int epicsStdCall epicsTimeGetCurrent(epicsTimeStamp *pDest)
Get current time into *pDest.
LIBCOM_API void epicsStdCall epicsThreadResume(epicsThreadId id)
Definition: osdThread.c:423
int iocshSetError(int err)
Signal error from an IOC shell function.
Definition: iocsh.cpp:536
LIBCOM_API void epicsStdCall epicsThreadGetName(epicsThreadId id, char *name, size_t size)
Definition: osdThread.c:857
int eltc(int yesno)
Definition: errlog.c:368
IOCSH_STATIC_FUNC void epicsParamShow()
void date(const char *format)
void epicsStdCall iocshRegisterVariable(const iocshVarDef *piocshVarDef)
Definition: iocsh.cpp:167
void epicsStdCall libComRegister(void)
void epicsStdCall iocLogPrefix(const char *prefix)
Definition: logClient.c:549
EPICS time stamp, for use from C code.
Definition: epicsTime.h:33
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
LIBCOM_API int epicsStdCall epicsThreadIsSuspended(epicsThreadId id)
Definition: osdThread.c:784
int installLastResortEventProvider(void)
Install a Time Event time provider that returns the current time for any Time event number...
#define stderr
Definition: epicsStdio.h:32
void epicsStdCall iocLogShow(unsigned level)
Definition: iocLog.c:147
void * pval
Definition: iocsh.h:53
EPICS time-stamps (epicsTimeStamp), epicsTime C++ class and C functions for handling wall-clock times...
C++ and C descriptions for a thread.
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetId(const char *name)
Definition: osdThread.c:826
void epicsStdCall epicsMutexShowAll(int onlyLocked, unsigned int level)
Display information about all epicsMutex semaphores.
Definition: epicsMutex.cpp:217
LIBCOM_API int epicsStdCall registryDump(void)
Definition: registry.c:86
int iocLogDisable
Definition: iocLog.c:25
IOCSH_STATIC_FUNC void errlog(const char *message)
LIBCOM_API void taskwdShow(int level)
Definition: taskwd.c:358
long generalTimeReport(int level)
Provide information about the installed providers and their current best times.
Definition: iocsh.h:56
LIBCOM_API void epicsStdCall epicsEnvShow(const char *name)
Print value of an environment variable, or all variables.
Definition: osdEnv.c:55