Back to index

natlog  0.91.0
options.h
Go to the documentation of this file.
00001 #ifndef INCLUDED_OPTIONS_
00002 #define INCLUDED_OPTIONS_
00003 
00004 #include <string>
00005 #include <unordered_map>
00006 
00007 #include <bobcat/argconfig>
00008 #include <bobcat/syslogstream>      // for the enums
00009 
00010 struct Options
00011 {
00012     enum Time
00013     {
00014         RAW,
00015         UTC,
00016         LT
00017     };
00018 
00019     enum ExitStatus
00020     {
00021         OK,
00022         FAILED
00023     };
00024     
00025     private:
00026         FBB::ArgConfig &d_arg;
00027     
00028         bool d_daemon;
00029         bool d_stdout;
00030         bool d_useSyslog;
00031         bool d_verbose;
00032         bool d_warnings;
00033 
00034         std::unordered_map<std::string, Time>::const_iterator d_time;
00035     
00036         std::string d_conntrackPath;
00037         std::string d_syslogTag;
00038         std::string d_PIDfile;
00039         std::string d_timeSpecError;
00040         std::string d_syslogPriorityError;
00041         std::string d_syslogFacilityError;
00042     
00043         std::unordered_map<std::string, FBB::Facility>::const_iterator 
00044                                                             d_syslogFacility;
00045         std::unordered_map<std::string, FBB::Priority>::const_iterator 
00046                                                             d_syslogPriority;
00047 
00048             // default values:
00049 
00050         static char const s_defaultConfigPath[];
00051         static char const s_defaultConntrackPath[];
00052         static char const s_defaultSyslogIdent[];
00053         static char const s_defaultSyslogFacility[];
00054         static char const s_defaultSyslogPriority[];
00055         static char const s_defaultPIDfile[];
00056     
00057         static std::unordered_map<std:: string, Time> const s_time;
00058         static std::unordered_map<std::string, FBB::Facility> const 
00059                                                            s_syslogFacilities;
00060         static std::unordered_map<std::string, FBB::Priority> const 
00061                                                            s_syslogPriorities;
00062 
00063         static Options *s_options;
00064 
00065     public:
00066         static Options &instance();
00067 
00068         Options(Options const &other) = delete;
00069 
00070         bool daemon() const;
00071         bool stdout() const;
00072         bool syslog() const;
00073         bool verbose() const;
00074         bool warnings() const;
00075 
00076         Time time() const;
00077         std::string const &timeTxt() const;
00078 
00079         std::string const &timeSpecError() const;
00080         std::string const &pidFile() const;
00081         std::string const &conntrackPath() const;
00082         std::string const &syslogTag() const;
00083 
00084         FBB::Priority syslogPriority() const;
00085         FBB::Facility syslogFacility() const;
00086 
00087         std::string const &priority() const;
00088         std::string const &facility() const;
00089 
00090         std::string syslogPriorityError() const;
00091         std::string syslogFacilityError() const;
00092 
00093         char const *operator[](size_t idx) const;   // forwards ArgConfig's
00094         size_t nArgs() const;                       // values.
00095         std::string const &basename() const;
00096 
00097         static char const *defaultConfigPath();
00098         static char const *defaultConntrackPath();
00099         static char const *defaultSyslogIdent();
00100         static char const *defaultSyslogFacility();
00101         static char const *defaultSyslogPriority();
00102         static char const *defaultPIDfile();
00103 
00104     private:
00105         Options();
00106 
00107         void openConfig();
00108         void setSyslogParams();
00109         void setBoolMembers();
00110         void setSyslogFacility();
00111         void setSyslogPriority();
00112         void setTime(std::string const &time);
00113 };
00114 
00115 inline bool Options::stdout() const
00116 {   
00117     return d_stdout;
00118 }
00119 
00120 inline bool Options::verbose() const
00121 {   
00122     return d_verbose;
00123 }
00124 
00125 inline bool Options::daemon() const
00126 {   
00127     return d_daemon;
00128 }
00129 
00130 inline bool Options::warnings() const
00131 {   
00132     return d_warnings;
00133 }
00134 
00135 inline bool Options::syslog() const
00136 {   
00137     return d_useSyslog;
00138 }
00139 
00140 inline Options::Time Options::time() const
00141 {   
00142     return d_time->second;
00143 }
00144 
00145 inline std::string const &Options::timeTxt() const
00146 {   
00147     return d_time->first;
00148 }
00149 
00150 inline std::string const &Options::syslogTag() const
00151 {   
00152     return d_syslogTag;
00153 }
00154 
00155 inline std::string const &Options::pidFile() const
00156 {   
00157     return d_PIDfile;
00158 }
00159 
00160 inline std::string const &Options::timeSpecError() const
00161 {   
00162     return d_timeSpecError;
00163 }
00164 
00165 inline FBB::Priority Options::syslogPriority() const
00166 {   
00167     return d_syslogPriority->second;
00168 }
00169 
00170 inline std::string const &Options::priority() const
00171 {   
00172     return d_syslogPriority->first;
00173 }
00174 
00175 inline std::string Options::syslogPriorityError() const
00176 {   
00177     return d_syslogPriorityError;
00178 }
00179 
00180 inline FBB::Facility Options::syslogFacility() const
00181 {   
00182     return d_syslogFacility->second;
00183 }
00184 
00185 inline std::string Options::syslogFacilityError() const
00186 {   
00187     return d_syslogFacilityError;
00188 }
00189 
00190 inline char const *Options::defaultPIDfile() 
00191 {
00192     return s_defaultPIDfile;
00193 }
00194 
00195 inline char const *Options::defaultConfigPath() 
00196 {
00197     return s_defaultConfigPath;
00198 }
00199 
00200 inline std::string const &Options::facility() const
00201 {   
00202     return d_syslogFacility->first;
00203 }
00204 
00205 inline std::string const &Options::conntrackPath() const
00206 {
00207     return d_conntrackPath;
00208 }
00209 
00210 inline char const *Options::operator[](size_t idx) const
00211 {
00212     return d_arg[idx];
00213 }
00214 
00215 inline size_t Options::nArgs() const
00216 {
00217     return d_arg.nArgs();
00218 }
00219 
00220 inline std::string const &Options::basename() const
00221 {
00222     return d_arg.basename();
00223 }
00224 
00225 inline char const *Options::defaultConntrackPath() 
00226 {
00227     return s_defaultConntrackPath;
00228 }
00229 
00230 inline char const *Options::defaultSyslogIdent() 
00231 {
00232     return s_defaultSyslogIdent;
00233 }
00234 
00235 inline char const *Options::defaultSyslogFacility() 
00236 {
00237     return s_defaultSyslogFacility;
00238 }
00239 
00240 inline char const *Options::defaultSyslogPriority() 
00241 {
00242     return s_defaultSyslogPriority;
00243 }
00244 
00245 #endif
00246 
00247 
00248 
00249 
00250 
00251