nidas  v1.2-1520
NidasApp.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  Copyright 2016 UCAR, NCAR, All Rights Reserved
6  ********************************************************************
7 */
8 #ifndef NIDAS_CORE_NIDASAPP_H
9 #define NIDAS_CORE_NIDASAPP_H
10 
11 #include "SampleTag.h"
12 #include "SampleMatcher.h"
13 #include "Datasets.h"
14 #include <nidas/util/UTime.h>
15 #include <nidas/util/Socket.h>
16 #include <nidas/util/auto_ptr.h>
17 
18 #include <string>
19 #include <list>
20 
21 
22 
23 namespace nidas { namespace core {
24 
25 class Project;
26 
32 {
33 public:
34  NidasAppException(const std::string& what) :
35  Exception(what)
36  {}
37 };
38 
39 
40 class NidasApp;
42 
47 typedef std::vector<NidasAppArg*> nidas_app_arglist_t;
48 
53 typedef std::vector<std::string> ArgVector;
54 
55 inline std::string
56 expectArg(const ArgVector& args, int i)
57 {
58  if (i < (int)args.size())
59  {
60  return args[i];
61  }
62  throw NidasAppException("expected argument for option " + args[i-1]);
63 }
64 
74 {
75 public:
118  NidasAppArg(const std::string& flags,
119  const std::string& syntax = "",
120  const std::string& usage = "",
121  const std::string& default_ = "",
122  bool required = false);
123 
124  virtual
125  ~NidasAppArg();
126 
136  void
137  setRequired(bool isRequired=true);
138 
142  bool
143  isRequired();
144 
150  void
151  acceptShortFlag(bool enable)
152  {
153  _enableShortFlag = enable;
154  }
155 
160  void
161  addFlag(const std::string& flag);
162 
169  void
170  setFlags(const std::string& flags);
171 
177  {
178  nidas_app_arglist_t args;
179  args.push_back(this);
180  return args;
181  }
182 
193  std::string
194  usage(const std::string& indent = " ");
195 
202  bool
203  specified();
204 
210  const std::string&
211  getValue();
212 
218  const std::string&
219  getFlag();
220 
225  bool
226  asBool();
227 
234  int
235  asInt();
236 
240  float
241  asFloat();
242 
253  virtual bool
254  parse(const ArgVector& argv, int* argi = 0);
255 
260  bool
261  accept(const std::string& flag);
262 
263  void
264  setUsageString(const std::string& text)
265  {
266  _usage = text;
267  }
268 
273  std::string
274  getUsageFlags();
275 
276  void
277  setDefault(const std::string& dvalue)
278  {
279  _default = dvalue;
280  }
281 
282  std::string
284  {
285  return _default;
286  }
287 
288 protected:
289 
290  std::string _flags;
291  std::string _syntax;
292  std::string _usage;
293  std::string _default;
294  std::string _arg;
295  std::string _value;
297  bool _required;
298 
305  bool
306  single();
307 
308 private:
309 
310  // Prevent the public NidasAppArg members of NidasApp from being
311  // replaced with other arguments.
312  NidasAppArg&
313  operator=(const NidasAppArg&);
314  NidasAppArg(const NidasAppArg&);
315 
316  friend class NidasApp;
317 };
318 
319 
325 {
326 public:
329 
338  void
339  setDefaultInput(const std::string& spec, int port=0)
340  {
341  default_input = spec;
342  if (port)
343  default_port = port;
344  updateUsage();
345  }
346 
347 private:
348 
350  NidasAppArg("", "input-url [...]"),
351  allowFiles(true),
352  allowSockets(true),
353  default_input(),
354  default_port(0)
355  {
356  }
357 
358  void
359  updateUsage();
360 
361  std::string default_input;
363 
364  virtual
366  {}
367 
368  friend class NidasApp;
369 };
370 
371 
379 
380 
572 class NidasApp
573 {
574 public:
575 
587  typedef enum {
589  } id_format_t;
590 
597  class IdFormat
598  {
599  public:
601  _idFormat(idfmt),
602  _width(0)
603  {
604  }
605 
606  IdFormat(const IdFormat& right) :
607  _idFormat(right._idFormat),
608  _width(right._width)
609  {
610  }
611 
612  IdFormat&
613  setDecimalWidth(int width)
614  {
615  _width = width;
616  return *this;
617  }
618 
619  IdFormat&
620  operator=(const IdFormat& right)
621  {
622  if (right._idFormat != NOFORMAT_ID)
623  _idFormat = right._idFormat;
624  if (right._width != 0)
625  _width = right._width;
626  return *this;
627  }
628 
629  int
631  {
632  if (_width)
633  return _width;
634  return 6;
635  }
636 
639  {
640  if (_idFormat != NOFORMAT_ID)
641  return _idFormat;
642  return AUTO_ID;
643  }
644 
645  bool
647  {
648  return (_idFormat == NOFORMAT_ID && _width == 0);
649  }
650 
652  int _width;
653  };
654 
675 
681 
691  loggingArgs();
692 
697  NidasApp(const std::string& name);
698 
703  ~NidasApp();
704 
705  std::string
707  {
708  return _appname;
709  }
710 
716  void
717  setProcessName(const std::string& argv0);
718 
723  std::string
724  getProcessName();
725 
731  void
733 
738  static NidasApp*
740 
748  void
749  allowUnrecognized(bool allow);
750 
754  bool
756 
782  void
783  enableArguments(const nidas_app_arglist_t& arglist);
784 
792  void
793  requireArguments(const nidas_app_arglist_t& arglist);
794 
799  void
801 
808  getArguments();
809 
814  void
815  requireLongFlag(const nidas_app_arglist_t& arglist, bool require=true)
816  {
817  nidas_app_arglist_t::const_iterator it;
818  for (it = arglist.begin(); it != arglist.end(); ++it)
819  {
820  (*it)->acceptShortFlag(!require);
821  }
822  }
823 
841  void
842  startArgs(const ArgVector& args);
843 
849  void
850  startArgs(int argc, const char* const argv[]) throw (NidasAppException);
851 
870  NidasAppArg*
872 
882  bool
883  nextArg(std::string& arg);
884 
885 
886  ArgVector
887  unparsedArgs();
888 
918  ArgVector
919  parseArgs(const ArgVector& args) throw (NidasAppException);
920 
926  ArgVector
927  parseArgs(int argc, const char* const argv[]) throw (NidasAppException);
928 
933  void
934  parseLogConfig(const std::string& optarg) throw (NidasAppException);
935 
940  void
941  parseLogLevel(const std::string& optarg) throw (NidasAppException)
942  {
943  parseLogConfig(optarg);
944  }
945 
947  parseTime(const std::string& optarg);
948 
949  void
950  parseUsername(const std::string& username);
951 
960  void
961  parseInputs(const std::vector<std::string>& inputs,
962  std::string default_input = "",
963  int default_port = 0) throw (NidasAppException);
964 
967  bool
969  {
970  return _dataFileNames.size() > 0 || _sockAddr.get();
971  }
972 
977  void
978  parseOutput(const std::string& optarg) throw (NidasAppException);
979 
984  std::string
986  {
987  return _outputFileName;
988  }
989 
993  int
995  {
996  return _outputFileLength;
997  }
998 
1002  int
1003  logLevel();
1004 
1010  void
1011  resetLogging();
1012 
1016  void
1017  setProcessData(bool process)
1018  {
1019  _processData = process;
1020  }
1021 
1025  bool
1027  {
1028  return _processData;
1029  }
1030 
1031  std::string
1033  {
1034  return _xmlFileName;
1035  }
1036 
1050  std::string
1051  getConfigsXML();
1052 
1064  getDataset(const std::string& datasetname)
1066 
1069  {
1070  return _startTime;
1071  }
1072 
1075  {
1076  return _endTime;
1077  }
1078 
1087  bool
1088  interrupted(bool allow_exception=true);
1089 
1095  static void
1097 
1109  void
1111 
1115  bool
1116  hasException();
1117 
1124  getException();
1125 
1130  Project*
1131  getProject();
1132 
1138  std::string
1139  usage(const std::string& indent = " ");
1140 
1145  static void
1146  setupSignals(void (*callback)(int signum) = 0);
1147 
1165  static void
1166  addSignal(int signum, void (*callback)(int signum) = 0, bool nolog=false);
1167 
1172  bool
1174  {
1175  return _help;
1176  }
1177 
1181  void
1182  setIdFormat(IdFormat idt);
1183 
1184  IdFormat
1186  {
1187  return _idFormat;
1188  }
1189 
1195  static
1196  std::ostream&
1197  formatSampleId(std::ostream& out, IdFormat idfmt, dsm_sample_id_t sid);
1198 
1205  std::ostream&
1206  formatSampleId(std::ostream& out, dsm_sample_id_t sid);
1207 
1213  std::string
1215 
1233  SampleMatcher&
1235  {
1236  return _sampleMatcher;
1237  }
1238 
1244  std::list<std::string>&
1246  {
1247  return _dataFileNames;
1248  }
1249 
1257  {
1258  return _sockAddr.get();
1259  }
1260 
1265  std::string
1266  getHostName();
1267 
1272  std::string
1273  getShortHostName();
1274 
1279  std::string
1281  {
1282  return _username;
1283  }
1284 
1289  uid_t
1291  {
1292  return _userid;
1293  }
1294 
1299  uid_t
1301  {
1302  return _groupid;
1303  }
1304 
1309  void
1310  setupProcess();
1311 
1320  void
1321  setupDaemonLogging(bool daemon_mode);
1322 
1327  void
1329 
1334  void
1335  setupDaemon(bool daemon_mode);
1336 
1341  void
1342  setupDaemon();
1343 
1348  void
1349  lockMemory();
1350 
1365  int
1366  checkPidFile();
1367 
1368 private:
1369 
1370  void
1371  setupLogScheme();
1372 
1374 
1375  std::string _appname;
1376 
1377  std::string _argv0;
1378 
1380 
1381  std::string _xmlFileName;
1382 
1384 
1386 
1388 
1390 
1391  std::list<std::string> _dataFileNames;
1392 
1393  nidas::util::auto_ptr<nidas::util::SocketAddress> _sockAddr;
1394 
1395  std::string _outputFileName;
1397 
1398  bool _help;
1399 
1400  std::string _username;
1401 
1402  std::string _hostname;
1403 
1404  uid_t _userid;
1405 
1406  gid_t _groupid;
1407 
1409 
1411 
1413  int _argi;
1414 
1417 
1419 
1422 };
1423 
1424 
1443 {
1444  NidasAppArgv(const std::string& argv0,
1445  const std::vector<std::string>& args) :
1446  vargv(), argv(0), argc(0)
1447  {
1448  vargv.push_back(strdup(argv0.c_str()));
1449  for (unsigned int i = 0; i < args.size(); ++i)
1450  {
1451  vargv.push_back(strdup(args[i].c_str()));
1452  }
1453  argv = &(vargv.front());
1454  argc = (int)vargv.size();
1455  }
1456 
1462  ArgVector
1463  unparsedArgs(int optindex)
1464  {
1465  return std::vector<std::string>(vargv.begin()+optindex, vargv.end());
1466  }
1467 
1469  {
1470  for (int i = 0; i < argc; ++i)
1471  {
1472  free(vargv[i]);
1473  }
1474  }
1475 
1476  std::vector<char*> vargv;
1477  char** argv;
1478  int argc;
1479 
1480 private:
1481 
1482  NidasAppArgv(const NidasAppArgv&);
1484 
1485 };
1486 
1487 
1488 
1489 }} // namespace nidas namespace core
1490 
1491 #endif // NIDAS_CORE_NIDASAPP_H
nidas::core::Dataset throw(nidas::util::InvalidParameterException, XMLException)
Derive a path to an XML datasets file according to the current environment settings, searching these paths in order:
Definition: NidasApp.cc:1526
nidas_app_arglist_t getArguments()
Return the list of arguments which are supported by this NidasApp, in other words, the arguments enabled by enableArguments() or requireArguments().
Definition: NidasApp.cc:687
std::string getConfigsXML()
Derive the path to the XML file which lists project configs.
Definition: NidasApp.cc:378
IdFormat & setDecimalWidth(int width)
Definition: NidasApp.h:613
SampleMatcher _sampleMatcher
Definition: NidasApp.h:1385
int _outputFileLength
Definition: NidasApp.h:1396
bool _processData
Definition: NidasApp.h:1379
void enableArguments(const nidas_app_arglist_t &arglist)
Add the list of NidasAppArg pointers to the set of arguments accepted by this NidasApp instance...
Definition: NidasApp.cc:647
id_format_t _idFormat
Definition: NidasApp.h:651
float asFloat()
Same as asInt(), except parse the argument value as a float.
Definition: NidasApp.cc:207
std::list< std::string > _dataFileNames
Definition: NidasApp.h:1391
bool _required
Definition: NidasApp.h:297
IdFormat(const IdFormat &right)
Definition: NidasApp.h:606
static NidasApp * getApplicationInstance()
Return the current application instance.
Definition: NidasApp.cc:611
std::string _default
Definition: NidasApp.h:293
std::string getName()
Definition: NidasApp.h:706
void setApplicationInstance()
An instance of NidasApp can be set as an application-wide instance, like an application context...
Definition: NidasApp.cc:603
void requireArguments(const nidas_app_arglist_t &arglist)
Add arguments to this NidasApp same as enableArguments() but also set them as required.
Definition: NidasApp.cc:655
void setProcessData(bool process)
Set the process-data setting in this NidasApp.
Definition: NidasApp.h:1017
A class for parsing, formatting and doing operations on time, based on Unix time conventions, where leap seconds are ignored, so that there are always 60 seconds in a minute, 3600 seconds in an hour and 86400 seconds in a day.
Definition: UTime.h:76
Extend NidasAppArg so the default input specifier and port can be customized, which in turn updates t...
Definition: NidasApp.h:324
static void setupSignals(void(*callback)(int signum)=0)
Setup signal handling for HUP, INT, and TERM, equivalent to calling addSignal() for each...
Definition: NidasApp.cc:1122
int _argi
Definition: NidasApp.h:1413
NidasAppArg Version
Definition: NidasApp.h:667
std::string _argv0
Definition: NidasApp.h:1377
unsigned int dsm_sample_id_t
Definition: Sample.h:63
NidasAppArgv(const std::string &argv0, const std::vector< std::string > &args)
Definition: NidasApp.h:1444
NidasAppArg SampleRanges
Definition: NidasApp.h:664
uid_t getGroupID()
Return the groupid of the username passed to the Username argument, otherwise 0.
Definition: NidasApp.h:1300
NidasAppArg LogConfig
Definition: NidasApp.h:657
Exception which can be built from an xerces::XMLException, xercesc::SAXException, or xercesc::DOMExce...
Definition: XMLException.h:43
Definition: NidasApp.h:588
NidasAppArg Username
Definition: NidasApp.h:670
std::string _syntax
Definition: NidasApp.h:291
static void setInterrupted(bool interrupted)
Set the global interrupted state for NidasApp.
Definition: NidasApp.cc:1113
nidas_app_arglist_t loggingArgs()
This is a convenience method to return all of the logging-related options in a list, such that this list can be extended if new log options are enabled.
Definition: NidasApp.cc:1162
std::string _xmlFileName
Definition: NidasApp.h:1381
std::string outputFileName()
Return just the output file pattern specified by an output option, without the file length specifier...
Definition: NidasApp.h:985
An interface for a socket address.
Definition: SocketAddress.h:36
void lockMemory()
Attempt mlockall() for this process, first adding the CAP_IPC_LOCK capability if possible.
Definition: NidasApp.cc:1388
uid_t getUserID()
Return the userid of the username passed to the Username argument, otherwise 0.
Definition: NidasApp.h:1290
NidasAppArg DebugDaemon
Definition: NidasApp.h:672
void updateUsage()
Definition: NidasApp.cc:1214
void setFlags(const std::string &flags)
Completely replace the flags which this argument should accept.
Definition: NidasApp.cc:150
bool interrupted(bool allow_exception=true)
Return the value of the global interrupted flag.
Definition: NidasApp.cc:1075
void checkRequiredArguments()
Verify that all NidasAppArg arguments required by this NidasApp have been specified, otherwise throw NidasAppException.
Definition: NidasApp.cc:668
IdFormat getIdFormat()
Definition: NidasApp.h:1185
~NidasApp()
If this instance is the current application instance, then the application instance is reset to null ...
Definition: NidasApp.cc:579
Definition: NidasApp.h:588
std::string _flags
Definition: NidasApp.h:290
IdFormat & operator=(const IdFormat &right)
Definition: NidasApp.h:620
void parseLogLevel(const std::string &optarg)
This is an alias for parseLogConfig(), since the LogConfig string syntax is backwards compatible with...
Definition: NidasApp.h:941
nidas::util::UTime _endTime
Definition: NidasApp.h:1389
NidasAppArg PidFile
It is not enough to enable this arg in an app, the app must must call checkPidFile() as well...
Definition: NidasApp.h:680
NidasApp(const std::string &name)
Construct a NidasApp instance and give it a name to be used for the usage info.
Definition: NidasApp.cc:415
void startArgs(const ArgVector &args)
Set the list of command-line argument strings to be parsed and handled by successive calls to nextArg...
Definition: NidasApp.cc:741
NidasAppInputFilesArg()
Definition: NidasApp.h:349
A Dataset is a named collection of parameters, that are used in data processing.
Definition: Datasets.h:47
nidas::util::SocketAddress * socketAddress()
If parseInputs() parsed a network socket specifier, then this method returns a pointer to the corresp...
Definition: NidasApp.h:1256
std::string xmlHeaderFile()
Definition: NidasApp.h:1032
const std::string & getFlag()
Return the command-line flag which this argument consumed.
Definition: NidasApp.cc:130
NidasAppArg EndTime
Definition: NidasApp.h:663
NidasAppArg LogParam
Definition: NidasApp.h:659
void parseLogConfig(const std::string &optarg)
Parse a LogConfig from the given argument using the LogConfig string syntax, and add that LogConfig t...
Definition: NidasApp.cc:695
bool allowUnrecognized()
Return whether unrecognized flags are allowed or not.
Definition: NidasApp.cc:1315
int asInt()
Parse the argument value as an integer, where the value could be the default if no value has been exp...
Definition: NidasApp.cc:180
nidas::util::UTime parseTime(const std::string &optarg)
Definition: NidasApp.cc:717
char ** argv
Definition: NidasApp.h:1477
A LogScheme is a vector of LogConfig&#39;s and the vector of fields to show in log messages.
Definition: Logger.h:623
Definition: NidasApp.h:588
nidas::util::UTime _startTime
Definition: NidasApp.h:1387
Definition: NidasApp.h:588
void setUsageString(const std::string &text)
Definition: NidasApp.h:264
ArgVector parseArgs(const ArgVector &args)
Parse all arguments accepted by this NidasApp in the command-line argument list args, but only handle the standard arguments.
Definition: NidasApp.cc:916
std::string _value
Definition: NidasApp.h:295
~NidasAppArgv()
Definition: NidasApp.h:1468
int checkPidFile()
Create a pid file for this process and return 0.
Definition: NidasApp.cc:1611
bool _help
Definition: NidasApp.h:1398
int argc
Definition: NidasApp.h:1478
int _width
Definition: NidasApp.h:652
void acceptShortFlag(bool enable)
Set whether short flags are enabled or not.
Definition: NidasApp.h:151
bool single()
Return true for arguments which are only a single argument.
Definition: NidasApp.cc:259
bool _allowUnrecognized
Definition: NidasApp.h:1418
void parseInputs(const std::vector< std::string > &inputs, std::string default_input="", int default_port=0)
Parse one or more input URLs from a list of non-option command-line arguments.
Definition: NidasApp.cc:930
nidas::util::LogScheme _logscheme
NidasApp keeps track of the LogScheme built up from arguments.
Definition: NidasApp.h:1421
nidas::util::UTime getEndTime()
Definition: NidasApp.h:1074
An IdFormat specifies the format for the SPS ID plus other characteristics, like the width when using...
Definition: NidasApp.h:597
std::string _arg
Definition: NidasApp.h:294
std::string getHostName()
Return the hostname passed to the Hostname argument, if any, otherwise return the current hostname as...
Definition: NidasApp.cc:1575
NidasAppInputFilesArg InputFiles
Definition: NidasApp.h:668
std::vector< NidasAppArg * > nidas_app_arglist_t
Lists of arguments can be manipulated together by putting them into this container type...
Definition: NidasApp.h:41
NidasAppException(const std::string &what)
Definition: NidasApp.h:34
nidas_app_arglist_t _app_arguments
Definition: NidasApp.h:1410
Definition: Exception.h:35
NidasAppArg FormatSampleId
Definition: NidasApp.h:666
bool _deleteProject
Definition: NidasApp.h:1408
std::string default_input
Definition: NidasApp.h:361
std::string _outputFileName
Definition: NidasApp.h:1395
bool isRequired()
Return whether this argument is required.
Definition: NidasApp.cc:102
void setDefaultInput(const std::string &spec, int port=0)
Set a default input.
Definition: NidasApp.h:339
std::string getUserName()
Return the username passed to the Username argument, if enabled, otherwise return an empty string...
Definition: NidasApp.h:1280
bool allowFiles
Definition: NidasApp.h:327
std::string getProcessName()
Get the process name, as set by setProcessName(), or else return the app name from getName()...
Definition: NidasApp.cc:625
NidasAppArg * parseNext()
Parse the next recognized argument from the list set in startArgs().
Definition: NidasApp.cc:777
void setRequired(bool isRequired=true)
Set whether this argument is required.
Definition: NidasApp.cc:94
NidasAppArg ProcessData
Definition: NidasApp.h:661
void setupDaemonLogging()
Call setupDaemonLogging(daemon_mode), where daemon_mode is true only if DebugDaemon is false...
Definition: NidasApp.cc:1332
A NidasAppArg is command-line argument which can be handled by NidasApp.
Definition: NidasApp.h:73
Project * getProject()
Return a pointer to the application-wide Project instance.
Definition: NidasApp.cc:1205
std::string usage(const std::string &indent=" ")
Return a usage string describing the arguments accepted by this application, rendering each argument ...
Definition: NidasApp.cc:1188
NidasAppArg XmlHeaderFile
Definition: NidasApp.h:655
std::string formatId(dsm_sample_id_t sid)
A more convenient form of formatSampleId() which just returns a string, and also includes the DSM id ...
Definition: NidasApp.cc:1286
int logLevel()
Return LogScheme::logLevel() for the current log scheme.
Definition: NidasApp.cc:1297
The NidasApp class throws a NidasAppException when command-line options do not parse.
Definition: NidasApp.h:31
nidas_app_arglist_t operator|(nidas_app_arglist_t arglist1, nidas_app_arglist_t arglist2)
Combine two arglists into a single arglist without any duplicates.
Definition: NidasApp.cc:1172
bool hasException()
See setException().
Definition: NidasApp.cc:1097
bool _enableShortFlag
Definition: NidasApp.h:296
NidasAppArg LogShow
Definition: NidasApp.h:656
NidasAppArg FormatHexId
Definition: NidasApp.h:665
NidasAppArg ConfigsArg
Definition: NidasApp.h:673
ArgVector _argv
Definition: NidasApp.h:1412
IdFormat _idFormat
Definition: NidasApp.h:1383
nidas::util::UTime getStartTime()
Definition: NidasApp.h:1068
NidasAppArg Help
Definition: NidasApp.h:660
std::string _appname
Definition: NidasApp.h:1375
void setDefault(const std::string &dvalue)
Definition: NidasApp.h:277
std::string _usage
Definition: NidasApp.h:292
std::string _username
Definition: NidasApp.h:1400
bool inputsProvided()
Definition: NidasApp.h:968
static void addSignal(int signum, void(*callback)(int signum)=0, bool nolog=false)
Add the given signal signum to the list of signals handled by the NidasApp signal handler...
Definition: NidasApp.cc:1133
NidasAppArg OutputFiles
Definition: NidasApp.h:669
bool _hasException
Definition: NidasApp.h:1415
NidasApp handles common options for NIDAS applications.
Definition: NidasApp.h:572
bool processData()
Return the current process-data setting for this NidasApp.
Definition: NidasApp.h:1026
void setException(const nidas::util::Exception &ex)
Like setInterrupted(true), but also allows an exception to be stored which can be tested and retrieve...
Definition: NidasApp.cc:1087
NidasAppArg(const std::string &flags, const std::string &syntax="", const std::string &usage="", const std::string &default_="", bool required=false)
Construct a NidasAppArg from a list of accepted short and long flags, the syntax for any arguments to...
Definition: NidasApp.cc:71
std::string getShortHostName()
Like getHostName(), but any &#39;.
Definition: NidasApp.cc:1602
std::string _hostname
Definition: NidasApp.h:1402
virtual bool parse(const ArgVector &argv, int *argi=0)
If argv[argi] matches this argument, then set the flag that was found and also the value if this argu...
Definition: NidasApp.cc:235
void requireLongFlag(const nidas_app_arglist_t &arglist, bool require=true)
Call acceptShortFlag(false) on the given list of NidasApp instances, meaning only the long flag will ...
Definition: NidasApp.h:815
static n_u::SerialPort port
Definition: sing.cc:68
bool asBool()
An argument is true if it is a stand-alone flag and was specified in the arguments, or else if the flag value evaluates to true.
Definition: NidasApp.cc:158
gid_t _groupid
Definition: NidasApp.h:1406
Convert vector&lt;string&gt; args to dynamically allocated (argc, argv) pair which will be freed when the i...
Definition: NidasApp.h:1442
NidasAppArg Hostname
Definition: NidasApp.h:671
void parseUsername(const std::string &username)
Definition: NidasApp.cc:1489
virtual const char * what() const
Definition: Exception.h:98
void setupDaemon()
Call setupDaemon(daemon_mode), where daemon_mode is true only if DebugDaemon is false.
Definition: NidasApp.cc:1363
int outputFileLength()
Return the output file length in seconds.
Definition: NidasApp.h:994
Match samples according to DSM and Sample ID ranges, and configure the ranges with criteria in text f...
Definition: SampleMatcher.h:20
void setupLogScheme()
Definition: NidasApp.cc:556
Exception(const std::string &type, const std::string &n, const std::string &m)
Definition: Exception.h:41
int decimalWidth()
Definition: NidasApp.h:630
NidasAppArg StartTime
Definition: NidasApp.h:662
std::vector< std::string > ArgVector
Convenience typedef for handling the command-line argv as a vector of strings.
Definition: NidasApp.h:53
Definition: Project.h:60
std::list< std::string > & dataFileNames()
Return the list of filenames parsed from the input URLs with parseInputs().
Definition: NidasApp.h:1245
void setProcessName(const std::string &argv0)
Set the name of this particular process, usually argv[0].
Definition: NidasApp.cc:618
uid_t _userid
Definition: NidasApp.h:1404
std::string getUsageFlags()
Return the string of flags accepted by this NidasAppArg according to the acceptShortFlag() setting...
Definition: NidasApp.cc:309
NidasAppArgv & operator=(const NidasAppArgv &)
void setupProcess()
Setup a process with the user and group specified by the Username argument, and attempt to set relate...
Definition: NidasApp.cc:1412
nidas::util::auto_ptr< nidas::util::SocketAddress > _sockAddr
Definition: NidasApp.h:1393
void addFlag(const std::string &flag)
Add a flag which this argument should accept.
Definition: NidasApp.cc:138
void parseOutput(const std::string &optarg)
Parse an output specifier in the form &lt;strptime-filename-pattern&gt;[&lt;length&gt;[smh]]. ...
Definition: NidasApp.cc:998
ArgVector unparsedArgs(int optindex)
Given the opt index after getopt() finishes, return a vector of any remaining arguments, suitable for passing to NidasApp::parseInputs().
Definition: NidasApp.h:1463
bool unset()
Definition: NidasApp.h:646
int default_port
Definition: NidasApp.h:362
nidas::util::Exception getException()
Return the current exception.
Definition: NidasApp.cc:1105
id_format_t idFormat()
Definition: NidasApp.h:638
const std::string & getValue()
If this argument has been parsed from a command line list (specified() returns true), then return the value passed after the flag.
Definition: NidasApp.cc:118
bool allowSockets
Definition: NidasApp.h:328
id_format_t
The four possible output formats for sensor-plus-sample IDs:
Definition: NidasApp.h:587
virtual ~NidasAppInputFilesArg()
Definition: NidasApp.h:365
std::string getDefault()
Definition: NidasApp.h:283
static std::ostream & formatSampleId(std::ostream &out, IdFormat idfmt, dsm_sample_id_t sid)
Write the sensor-plus-sample ID part of sid to stream out using the format specified in idfmt...
Definition: NidasApp.cc:1246
NidasAppArg LogFields
Definition: NidasApp.h:658
void setIdFormat(IdFormat idt)
Store the format in which sample IDs should be shown.
Definition: NidasApp.cc:1238
ArgVector unparsedArgs()
Definition: NidasApp.cc:733
std::string expectArg(const ArgVector &args, int i)
Definition: NidasApp.h:56
NidasAppArg & operator=(const NidasAppArg &)
Definition: NidasApp.h:588
void resetLogging()
Reset logging to the NidasApp default.
Definition: NidasApp.cc:1323
bool nextArg(std::string &arg)
If the next argument to be parsed does not start with &#39;-&#39;, then copy it into arg and remove it from t...
Definition: NidasApp.cc:762
NidasAppArg DatasetName
Definition: NidasApp.h:674
IdFormat(id_format_t idfmt=NOFORMAT_ID)
Definition: NidasApp.h:600
SampleMatcher & sampleMatcher()
Use this method to access the SampleMatcher instance for this NidasApp.
Definition: NidasApp.h:1234
bool accept(const std::string &flag)
Return true if the given command-line flag matches one of this argument&#39;s flags.
Definition: NidasApp.cc:267
bool helpRequested()
Return true when a help option was parsed, meaning the usage info has been requested.
Definition: NidasApp.h:1173
std::vector< char * > vargv
Definition: NidasApp.h:1476
static NidasApp * application_instance
Definition: NidasApp.h:1373
Definition: InvalidParameterException.h:35
nidas::util::Exception _exception
Definition: NidasApp.h:1416
virtual ~NidasAppArg()
Definition: NidasApp.cc:88
bool specified()
Return true if this argument has been filled in from a command-line argument list, such as after a call to NidasApp::parseArgs().
Definition: NidasApp.cc:110
std::string usage(const std::string &indent=" ")
Render the usage string for this particular argument, taking into account which flags are enabled...
Definition: NidasApp.cc:342