LogService
libdadi: utility tools for distributed applications
|
00001 /****************************************************************************/ 00002 /* DIET forwarder implementation - Executable options */ 00003 /* */ 00004 /* Author(s): */ 00005 /* - Gael Le Mahec (gael.le.mahec@ens-lyon.fr) */ 00006 /* */ 00007 /* This file is part of DIET . */ 00008 /* */ 00009 /* Copyright (C) 2000-2003 ENS Lyon, LIFC, INSA, INRIA and SysFera (2000) */ 00010 /* */ 00011 /* - Frederic.Desprez@ens-lyon.fr (Project Manager) */ 00012 /* - Eddy.Caron@ens-lyon.fr (Technical Manager) */ 00013 /* - Tech@sysfera.com (Maintainer and Technical Support) */ 00014 /* */ 00015 /* This software is a computer program whose purpose is to provide an */ 00016 /* distributed logging services. */ 00017 /* */ 00018 /* */ 00019 /* This software is governed by the CeCILL license under French law and */ 00020 /* abiding by the rules of distribution of free software. You can use, */ 00021 /* modify and/ or redistribute the software under the terms of the CeCILL */ 00022 /* license as circulated by CEA, CNRS and INRIA at the following URL */ 00023 /* "http://www.cecill.info". */ 00024 /* */ 00025 /* As a counterpart to the access to the source code and rights to copy, */ 00026 /* modify and redistribute granted by the license, users are provided */ 00027 /* only with a limited warranty and the software's author, the holder */ 00028 /* of the economic rights, and the successive licensors have only */ 00029 /* limited liability. */ 00030 /* */ 00031 /* In this respect, the user's attention is drawn to the risks */ 00032 /* associated with loading, using, modifying and/or developing or */ 00033 /* reproducing the software by the user in light of its specific status */ 00034 /* of free software, that may mean that it is complicated to */ 00035 /* manipulate, and that also therefore means that it is reserved for */ 00036 /* developers and experienced professionals having in-depth computer */ 00037 /* knowledge. Users are therefore encouraged to load and test the */ 00038 /* software's suitability as regards their requirements in conditions */ 00039 /* enabling the security of their systems and/or data to be ensured and, */ 00040 /* more generally, to use and operate it in the same conditions as */ 00041 /* regards security. */ 00042 /* */ 00043 /* The fact that you are presently reading this means that you have had */ 00044 /* knowledge of the CeCILL license and that you accept its terms. */ 00045 /* */ 00046 /****************************************************************************/ 00047 #ifndef OPTIONS_HH 00048 #define OPTIONS_HH 00049 00050 #include <list> 00051 #include <map> 00052 #include <string> 00053 00054 class Options; 00055 00056 /* Standard configuration class. Used as an abstract class for parameters 00057 * processing. 00058 */ 00059 class Configuration { 00060 public: 00061 Configuration(); 00062 00063 explicit Configuration(const std::string& pgName); 00064 00065 const std::string& 00066 getPgName() const; 00067 00068 const std::string& 00069 getConfigFile() const; 00070 00071 void 00072 setConfigFile(const std::string& configFile); 00073 00074 private: 00075 std::string pgName; 00076 std::string configFile; 00077 }; 00078 00079 /* Callback function type definition. */ 00080 typedef void (*optCallback)(const std::string&, Configuration*); 00081 00082 /* Options class. Used to process the users command line parameters. */ 00083 /* This class is a generic command line parameters processing tool. 00084 */ 00085 class Options { 00086 public: 00087 Options(Configuration* config, int argc, char* argv[], char* envp[] = NULL); 00088 00089 void 00090 setOptCallback(const std::string& arg, optCallback callBack); 00091 00092 void 00093 setEnvCallback(const std::string& arg, optCallback callBack); 00094 00095 void 00096 setParamCallback(unsigned int idx, optCallback callBack); 00097 00098 void 00099 setFlagCallback(const char flag, optCallback callBack); 00100 00101 void 00102 processOptions(); 00103 00104 void 00105 processEnv(); 00106 00107 private: 00108 Configuration* config; 00109 std::map<std::string, std::string> arguments; 00110 std::map<std::string, std::string> environment; 00111 std::map<unsigned int, std::string> params; 00112 std::list<std::string> singleArgs; 00113 std::list<std::string> singleEnvs; 00114 std::list<char> flags; 00115 std::map<std::string, optCallback> optCallbacks; 00116 std::map<std::string, optCallback> envCallbacks; 00117 std::map<unsigned int, optCallback> paramCallbacks; 00118 std::map<char, optCallback> flagCallbacks; 00119 }; 00120 00121 /* A simple configuration file class. 00122 * The file must respect the format: 00123 * <attribute> = <value> 00124 */ 00125 class ConfigFile { 00126 public: 00127 ConfigFile(); 00128 00129 explicit ConfigFile(const std::string& path); 00130 00131 void 00132 parseFile(const std::string& path); 00133 00134 const std::string& 00135 getAttr(const std::string& key); 00136 00137 private: 00138 std::map<std::string, std::string> attributes; 00139 }; 00140 #endif