/usr/include/Aria/ArConfig.h is in libaria-dev 2.8.0+repack-1.2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | /*
Adept MobileRobots Robotics Interface for Applications (ARIA)
Copyright (C) 2004, 2005 ActivMedia Robotics LLC
Copyright (C) 2006, 2007, 2008, 2009, 2010 MobileRobots Inc.
Copyright (C) 2011, 2012, 2013 Adept Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
If you wish to redistribute ARIA under different terms, contact
Adept MobileRobots for information about a commercial version of ARIA at
robots@mobilerobots.com or
Adept MobileRobots, 10 Columbia Drive, Amherst, NH 03031; +1-603-881-7960
*/
#ifndef ARCONFIG_H
#define ARCONFIG_H
#include "ArConfigArg.h"
#include "ArFileParser.h"
#include "ArHasFileName.h"
#include <set>
class ArArgumentBuilder;
class ArConfigSection;
/// Stores configuration information which may be read to and from files or other sources
/**
* The configuration is a set of parameters (or config arguments), organized into
* sections. Parameters contain a key or name (a short string), a value
* (which may be one of several types), a priority (important, normal, or trivial
* to most users), a longer description, and a display hint which suggests
* what kind of UI control might be most appropriate for the parameter.
* After adding a parameter to the configuration, its value may be changed
* when the configuration is loaded or reloaded from a file.
* Various program modules may register callbacks to be notified
* when a shared global configuration (such as the static ArConfig object kept
* by the Aria class) is loaded or otherwise changed.
*
* Classes dealing with more specialized kinds of config files
* inherit from this one.
*
* Important methods in this class are: addParam(), addProcessFileCB(),
* remProcessFileCB(), parseFile(), writeFile().
*
* Usually, configuration data are read from and written to a file using
* parseFile() and writeFile(), or are set
* by a remote client via ArNetworking. It is also possible to import
* configuration settings from an ArArgumentParser (which, for example, may
* contain a program's command line arguments) using useArgumentParser().
*
* @warning ArConfig does not escape any special characters when writing or
* loading to/from a file. Therefore in general parameter names, values, section
* names, and comments must not contain characters which have special meaning
* in a config file, such as '#', ';', tab or newline. (see also ArFileParser) Parameter names may
* have spaces, though by convention they generally do not.
@ingroup OptionalClasses
*/
class ArConfig : public ArHasFileName
{
private:
/// Current version of the output config file.
static const char *CURRENT_CONFIG_VERSION;
/// Parser tag that introduces the config file version.
static const char *CONFIG_VERSION_TAG;
/// Current version of the output config resource file.
static const char *CURRENT_RESOURCE_VERSION;
/// Parser tag that introduces the config resource file version.
static const char *RESOURCE_VERSION_TAG;
public:
/// Sections related to I/O, ARCL, display, network communication, etc.
static const char *CATEGORY_ROBOT_INTERFACE;
/// Sections related to robot behavior, docking, driving, navigation, etc.
static const char *CATEGORY_ROBOT_OPERATION;
/// Sections related to the robot hardware and its sensors/accessories.
static const char *CATEGORY_ROBOT_PHYSICAL;
/// Sections related to the fleet, enterprise manager, etc.
static const char *CATEGORY_FLEET;
/// Sections related to security.
static const char *CATEGORY_SECURITY;
/// Sections related to debug, including logging, replay, etc.
static const char *CATEGORY_DEBUG;
public:
/// Constructor
AREXPORT ArConfig(const char *baseDirectory = NULL,
bool noBlanksBetweenParams = false,
bool ignoreBounds = false,
bool failOnBadSection = false,
bool saveUnknown = true);
/// Destructor
AREXPORT virtual ~ArConfig();
/// Copy constructor
AREXPORT ArConfig(const ArConfig &config);
/// Assignment operator
AREXPORT ArConfig &operator=(const ArConfig &config);
/// Copies the given config to this one, detaching any pointers so they are not shared
AREXPORT virtual void copyAndDetach(const ArConfig &config);
/// Stores an optional config and robot name to be used in log messages.
AREXPORT virtual void setConfigName(const char *configName,
const char *robotName = NULL);
/// Turn on this flag to reduce the number of verbose log messages.
AREXPORT virtual void setQuiet(bool isQuiet);
/// Sets an associate config that provides translations for each parameter (as read from a resource file).
AREXPORT virtual void setTranslator(ArConfig *xlatorConfig);
/// Returns the associated translator config, or NULL if none.
AREXPORT virtual ArConfig *getTranslator() const;
/// Parse a config file
AREXPORT bool parseFile(const char *fileName,
bool continueOnError = false,
bool noFileNotFoundMessage = false,
char *errorBuffer = NULL,
size_t errorBufferLen = 0,
std::list<std::string> *sectionsToParse = NULL,
ArPriority::Priority highestPriority = ArPriority::FIRST_PRIORITY,
ArPriority::Priority lowestPriority = ArPriority::LAST_PRIORITY,
ArConfigArg::RestartLevel *restartLevelNeeded = NULL);
/// Write out a config file
AREXPORT bool writeFile(const char *fileName,
bool append = false,
std::set<std::string> *alreadyWritten = NULL,
bool writeExtras = false,
std::list<std::string> *sectionsToWrite = NULL,
ArPriority::Priority highestPriority = ArPriority::FIRST_PRIORITY,
ArPriority::Priority lowestPriority = ArPriority::LAST_PRIORITY);
/// Parse a config resource file, for translation.
AREXPORT bool parseResourceFile(const char *fileName,
bool continueOnError = true,
char *errorBuffer = NULL,
size_t errorBufferLen = 0,
std::list<std::string> *sectionsToParse = NULL);
/// Parse a config resource file with parameters suitable for custom commands.
AREXPORT void parseResourceFile(ArArgumentBuilder *builder);
/// Write a config resource file, for translation.
AREXPORT bool writeResourceFile(const char *fileName,
bool append = false,
std::set<std::string> *alreadyWritten = NULL,
std::list<std::string> *sectionsToWrite = NULL);
/// Write a config resource file with parameters suitable for custom commands.
AREXPORT void writeResourceFile(ArArgumentBuilder *builder);
/// Command to add a section and its description to the specified category.
/**
* The category is expected to be one of the CATEGORY_ constants defined above.
**/
AREXPORT bool addSection(const char *categoryName,
const char *sectionName,
const char *sectionDescription);
/// Command to add a parameter to the given section with given priority
AREXPORT bool addParam(const ArConfigArg &arg,
const char *sectionName = "",
ArPriority::Priority priority = ArPriority::NORMAL,
const char *displayHint = NULL,
ArConfigArg::RestartLevel restart = ArConfigArg::NO_RESTART);
/// Command to add a new comment to the given section with given priority
AREXPORT bool addComment(const char *comment, const char *sectionName = "",
ArPriority::Priority priority = ArPriority::NORMAL);
/// Adds a parameter that has all the other information on it
/// already set
AREXPORT bool addParamAsIs(const ArConfigArg &arg,
const char *sectionName = "");
/// Sets the comment for a section
AREXPORT void setSectionComment(const char *sectionName,
const char *comment);
/// Uses this argument parser after it parses a file before it processes
AREXPORT void useArgumentParser(ArArgumentParser *parser);
/// for inheritors this is called after the file is processed
/**
For classes that inherit from ArConfig this function is called
after parseFile and all of the processFileCBs are called... If
you want to call something before the processFileCBs then just
add a processFileCB... this is only called if there were no
errors parsing the file or continueOnError was set to false when
parseFile was called
@return true if the config parsed was good (parseFile will return
true) false if the config parsed wasn't (parseFile will return false)
**/
AREXPORT virtual bool processFile(void) { return true; }
/// Adds a callback to be invoked when the configuration is loaded or
/// reloaded.
AREXPORT void addProcessFileCB(ArRetFunctor<bool> *functor,
int priority = 0);
/// Adds a callback to be invoked when the configuration is loaded
/// or reloaded.... if you really want errors you should use
/// addProcessFileWithErrorCB, this is just to catch mistakes
AREXPORT void addProcessFileCB(ArRetFunctor2<bool, char *, size_t> *functor,
int priority = 0);
/// Adds a callback to be invoked when the configuration is loaded or
/// reloaded, which may also receive error messages
AREXPORT void addProcessFileWithErrorCB(
ArRetFunctor2<bool, char *, size_t> *functor,
int priority = 0);
/// Removes a processedFile callback
AREXPORT void remProcessFileCB(ArRetFunctor<bool> *functor);
/// Removes a processedFile callback
AREXPORT void remProcessFileCB(
ArRetFunctor2<bool, char *, size_t> *functor);
/// Call the processFileCBs
AREXPORT bool callProcessFileCallBacks(bool continueOnError,
char *errorBuffer = NULL,
size_t errorBufferLen = 0);
/// This parses the argument given (for parser or other use)
AREXPORT bool parseArgument(ArArgumentBuilder *arg,
char *errorBuffer = NULL,
size_t errorBufferLen = 0);
/// Parses the config file version information.
AREXPORT bool parseVersion(ArArgumentBuilder *arg,
char *errorBuffer = NULL,
size_t errorBufferLen = 0);
/// This parses the section change (for parser or other use)
AREXPORT bool parseSection(ArArgumentBuilder *arg,
char *errorBuffer = NULL,
size_t errorBufferLen = 0);
AREXPORT bool parseListBegin(ArArgumentBuilder *arg,
char *errorBuffer,
size_t errorBufferLen);
AREXPORT bool parseListEnd(ArArgumentBuilder *arg,
char *errorBuffer,
size_t errorBufferLen);
/// This parses an unknown argument (so we can save it)
AREXPORT bool parseUnknown(ArArgumentBuilder *arg,
char *errorBuffer = NULL,
size_t errorBufferLen = 0);
/// Gets the restart level needed
AREXPORT ArConfigArg::RestartLevel getRestartLevelNeeded(void) const;
/// Gets the restart level needed
AREXPORT void resetRestartLevelNeeded(void);
/// Get the base directory
AREXPORT const char *getBaseDirectory(void) const;
/// Set the base directory
AREXPORT void setBaseDirectory(const char *baseDirectory);
/// Get the file name we loaded
AREXPORT const char *getFileName(void) const;
/// Set whether we have blanks between the params or not
AREXPORT void setNoBlanksBetweenParams(bool noBlanksBetweenParams);
/// Get whether we have blanks between the params or not
AREXPORT bool getNoBlanksBetweenParams(void);
/// Use an argument parser to change the config
AREXPORT bool parseArgumentParser(ArArgumentParser *parser,
bool continueOnError = false,
char *errorBuffer = NULL,
size_t errorBufferLen = 0);
/// Returns the list of categories contained in this config.
AREXPORT std::list<std::string> getCategoryNames() const;
/// Returns the names of the sections that have been added to the specified category.
AREXPORT std::list<std::string> getSectionNamesInCategory(const char *categoryName) const;
/// Returns the names of all sections in the config.
AREXPORT std::list<std::string> getSectionNames() const;
/// Get the sections themselves (use only if you know what to do)
AREXPORT std::list<ArConfigSection *> *getSections(void);
/// Find the section with the given name.
/// @return section object, or NULL if not found.
AREXPORT ArConfigSection *findSection(const char *sectionName) const;
/// Set the log level used when loading or reloading the configuration
AREXPORT void setProcessFileCallbacksLogLevel(ArLog::LogLevel level)
{ myProcessFileCallbacksLogLevel = level; }
/// Get the log level used when loading or reloading the configuration
AREXPORT ArLog::LogLevel getProcessFileCallbacksLogLevel(void)
{ return myProcessFileCallbacksLogLevel; }
/// Sets whether we save unknown items (if we don't save 'em we ignore 'em)
AREXPORT void setSaveUnknown(bool saveUnknown)
{ mySaveUnknown = saveUnknown; }
/// Gets whether we save unknowns (if we don't save 'em we ignore 'em)
AREXPORT bool getSaveUnknown(void) { return mySaveUnknown; }
/// Clears out all the section information
AREXPORT void clearSections(void);
/// Clears out all the section information and the processFileCBs
AREXPORT void clearAll(void);
/// adds a flag to a section
AREXPORT bool addSectionFlags(const char *sectionName,
const char *flags);
/// Removes a flag from a section
AREXPORT bool remSectionFlag(const char *sectionName,
const char *flag);
/// calls clearValueSet on the whole config (internal for default configs)
AREXPORT void clearAllValueSet(void);
/// Removes all unset values from the config (internal for default configs)
AREXPORT void removeAllUnsetValues(void);
/// Removes all values from sections in which no value has been set (internal)
AREXPORT void removeAllUnsetSections(void);
/// Logs the config
AREXPORT void log(bool isSummary = true,
std::list<std::string> *sectionNameList = NULL,
const char *logPrefix = "");
/// Sets permissions on some things
AREXPORT void setPermissions(bool allowFactory = true,
bool rememberUnknowns = true);
/// Adds a section for this config to always skip
void addSectionNotToParse(const char *section);
/// Removes a section for this config to always skip
void remSectionNotToParse(const char *section);
protected:
/// Write out a section
AREXPORT void writeSection(ArConfigSection *section,
FILE *file,
std::set<std::string> *alreadyWritten,
bool writeExtras,
ArPriority::Priority highestPriority,
ArPriority::Priority lowestPriority);
/// Write out a section in CSV format for translation
AREXPORT void writeSectionResource(ArConfigSection *section,
FILE *file,
std::set<std::string> *alreadyWritten);
AREXPORT void translateSection(ArConfigSection *section);
void copySectionsToParse(std::list<std::string> *from);
/// Removes unset values from the config.
/**
* @param isRemovingUnsetSectionsOnly a bool set to true if unset parameters should
* not be removed from sections that have any set parameters; false if all unset
* values should be removed
**/
AREXPORT void removeAllUnsetValues(bool isRemovingUnsetSectionsOnly);
/**
This class's job is to make the two functor types largely look
like the same one from the code's perspective, this is so we can
store them both in the same map for order of operations purposes.
The funkiness with the constructor is because the retfunctor2
looks like the retfunctor and winds up always falling into that
constructor.
**/
class ProcessFileCBType
{
public:
ProcessFileCBType(
ArRetFunctor2<bool, char *, size_t> *functor)
{
myCallbackWithError = functor;
myCallback = NULL;
}
ProcessFileCBType(ArRetFunctor<bool> *functor)
{
myCallbackWithError = NULL;
myCallback = functor;
}
~ProcessFileCBType() {}
bool call(char *errorBuffer, size_t errorBufferLen)
{
if (myCallbackWithError != NULL)
return myCallbackWithError->invokeR(errorBuffer, errorBufferLen);
else if (myCallback != NULL)
return myCallback->invokeR();
// if we get here there's a problem
ArLog::log(ArLog::Terse, "ArConfig: Horrible problem with process callbacks");
return false;
}
bool haveFunctor(ArRetFunctor2<bool, char *, size_t> *functor)
{
if (myCallbackWithError == functor)
return true;
else
return false;
}
bool haveFunctor(ArRetFunctor<bool> *functor)
{
if (myCallback == functor)
return true;
else
return false;
}
const char *getName(void)
{
if (myCallbackWithError != NULL)
return myCallbackWithError->getName();
else if (myCallback != NULL)
return myCallback->getName();
// if we get here there's a problem
ArLog::log(ArLog::Terse, "ArConfig: Horrible problem with process callback names");
return NULL;
}
protected:
ArRetFunctor2<bool, char *, size_t> *myCallbackWithError;
ArRetFunctor<bool> *myCallback;
};
void addParserHandlers(void);
void remParserHandlers(void);
void addListNamesToParser(const ArConfigArg &parent);
/// Optional name of the robot with which the config is associated.
std::string myRobotName;
/// Optional name of the config instance.
std::string myConfigName;
/// Prefix to be inserted in log messages (contains the robot and config names).
std::string myLogPrefix;
ArArgumentParser *myArgumentParser;
std::multimap<int, ProcessFileCBType *> myProcessFileCBList;
bool myNoBlanksBetweenParams;
/// Version information read from config file
std::string myConfigVersion;
ArConfig *myTranslator;
char myCsvSeparatorChar;
std::string mySection;
std::list<std::string> *mySectionsToParse;
std::set<std::string> mySectionsNotToParse;
ArPriority::Priority myHighestPriorityToParse;
ArPriority::Priority myLowestPriorityToParse;
ArConfigArg::RestartLevel myRestartLevelNeeded;
bool myCheckingForRestartLevel;
bool mySectionBroken;
bool mySectionIgnored;
bool myUsingSections;
std::list<std::string> myParsingListNames;
bool myIsParsingListBroken;
std::string myFileName;
std::string myBaseDirectory;
ArFileParser myParser;
bool myIgnoreBounds;
bool myFailOnBadSection;
bool myDuplicateParams;
bool mySaveUnknown;
bool myIsQuiet;
bool myPermissionAllowFactory;
bool myPermissionSaveUnknown;
ArLog::LogLevel myProcessFileCallbacksLogLevel;
/// Map that defines the section names contained in each category.
std::map<std::string, std::list<std::string> > myCategoryToSectionsMap;
// our list of sections which has in it the argument list for each
std::list<ArConfigSection *> mySections;
// callback for the file parser
ArRetFunctor3C<bool, ArConfig, ArArgumentBuilder *, char *, size_t> myParserCB;
// callback for the config version in the file parser
ArRetFunctor3C<bool, ArConfig, ArArgumentBuilder *, char *, size_t> myVersionCB;
// callback for the section in the file parser
ArRetFunctor3C<bool, ArConfig, ArArgumentBuilder *, char *, size_t> mySectionCB;
// callback for the _listBegin in the file parser
ArRetFunctor3C<bool, ArConfig, ArArgumentBuilder *, char *, size_t> myListBeginCB;
// callback for the _listEnd in the file parser
ArRetFunctor3C<bool, ArConfig, ArArgumentBuilder *, char *, size_t> myListEndCB;
// callback for the unknown param (or whatever) file parser
ArRetFunctor3C<bool, ArConfig, ArArgumentBuilder *, char *, size_t> myUnknownCB;
};
/** Represents a section in the configuration. Sections are used to
* group items used by separate parts of Aria.
*/
class ArConfigSection
{
public:
AREXPORT ArConfigSection(const char *name = NULL,
const char *comment = NULL,
bool isQuiet = false,
const char *categoryName = NULL);
AREXPORT virtual ~ArConfigSection();
AREXPORT ArConfigSection(const ArConfigSection §ion);
AREXPORT ArConfigSection &operator=(const ArConfigSection §ion);
/// Copies the given section to this one, detaching any pointers so they are not shared
AREXPORT virtual void copyAndDetach(const ArConfigSection §ion);
/** @return The name of this section */
const char *getName(void) const { return myName.c_str(); }
/** @return A comment describing this section */
const char *getComment(void) const { return myComment.c_str(); }
/// Returns the name of the category that contains this section.
AREXPORT const char *getCategoryName() const;
const char *getFlags(void) const { return myFlags->getFullString(); }
AREXPORT bool hasFlag(const char *flag) const;
std::list<ArConfigArg> *getParams(void) { return &myParams; }
void setName(const char *name);
void setComment(const char *comment);
AREXPORT bool addFlags(const char *flags, bool isQuiet = false);
AREXPORT bool remFlag(const char *dataFlag);
/// Finds a parameter item in this section with the given name. Returns NULL if not found.
AREXPORT ArConfigArg *findParam(const char *paramName,
bool isAllowStringHolders = false);
/// Finds a list member parameter with the specified name path. Returns NULL if not found.
AREXPORT ArConfigArg *findParam(const std::list<std::string> ¶mNamePath,
bool isAllowHolders = false);
/// Finds a list member parameter with the specified name path. Returns NULL if not found.
AREXPORT ArConfigArg *findParam(const char **paramNamePath,
int pathLength,
bool isAllowHolders = false);
/// Determines whether the current section contains parameters in the specified priority ran
AREXPORT bool containsParamsOfPriority(ArPriority::Priority highestPriority,
ArPriority::Priority lowestPriority);
/// Removes a string holder for this param, returns true if it found one
AREXPORT bool remStringHolder(const char *paramName);
/// Turn on this flag to reduce the number of verbose log messages.
AREXPORT void setQuiet(bool isQuiet);
protected:
/// Give the config access to the protected category name setter.
friend class ArConfig;
/// Sets the name of the category to which this section belongs.
void setCategoryName(const char *categoryName);
protected:
std::string myName;
std::string myComment;
std::string myCategoryName;
std::string myDisplayName; // Not yet supported
ArArgumentBuilder *myFlags;
std::list<ArConfigArg> myParams;
bool myIsQuiet;
}; // end class ArConfigSection
#endif // ARCONFIG
|