Go to the documentation of this file.00001 #ifndef CONFIGURATION_H_
00002 #define CONFIGURATION_H_
00003
00004 #include "ibrcommon/data/ConfigFile.h"
00005 #include "core/Node.h"
00006 #include "routing/StaticRoutingExtension.h"
00007 #include "ibrcommon/Exceptions.h"
00008 #include "ibrcommon/net/NetInterface.h"
00009
00010 using namespace dtn::net;
00011 using namespace dtn::core;
00012 using namespace dtn::data;
00013
00014 namespace dtn
00015 {
00016 namespace daemon
00017 {
00021 class Configuration
00022 {
00023 private:
00024 Configuration();
00025 virtual ~Configuration();
00026
00027 public:
00028 class NetConfig
00029 {
00030 public:
00031 enum NetType
00032 {
00033 NETWORK_UNKNOWN = 0,
00034 NETWORK_TCP = 1,
00035 NETWORK_UDP = 2,
00036 NETWORK_HTTP = 3,
00037 NETWORK_LOWPAN = 4
00038 };
00039
00040 NetConfig(std::string name, NetType type, const std::string &address, int port, bool discovery = true);
00041 NetConfig(std::string name, NetType type, const ibrcommon::NetInterface &iface, int port, bool discovery = true);
00042 ~NetConfig();
00043
00044 std::string name;
00045 NetType type;
00046 ibrcommon::NetInterface interface;
00047 std::string address;
00048 int port;
00049 bool discovery;
00050 };
00051
00052 class ParameterNotSetException : ibrcommon::Exception
00053 {
00054 };
00055
00056 class ParameterNotFoundException : ibrcommon::Exception
00057 {
00058 };
00059
00060 static Configuration &getInstance();
00061
00065 void load();
00066 void load(string filename);
00067
00068 void params(int argc, char *argv[]);
00069
00073 string getNodename();
00074
00080 int getTimezone();
00081
00088 ibrcommon::File getPath(string name);
00089
00096 unsigned int getUID();
00097
00104 unsigned int getGID();
00105
00110 bool doAPI();
00111
00112 Configuration::NetConfig getAPIInterface();
00113 ibrcommon::File getAPISocket();
00114
00119 std::string version();
00120
00127 std::string getNotifyCommand();
00128
00133 std::string getStorage() const;
00134
00135 enum RoutingExtension
00136 {
00137 DEFAULT_ROUTING = 0,
00138 EPIDEMIC_ROUTING = 1,
00139 FLOOD_ROUTING = 2
00140 };
00141
00147 size_t getLimit(std::string);
00148
00149 class Extension
00150 {
00151 protected:
00152 virtual void load(const ibrcommon::ConfigFile &conf) = 0;
00153 };
00154
00155 class Discovery : public Configuration::Extension
00156 {
00157 friend class Configuration;
00158 protected:
00159 Discovery();
00160 ~Discovery();
00161 void load(const ibrcommon::ConfigFile &conf);
00162
00163 bool _enabled;
00164 unsigned int _timeout;
00165
00166 public:
00167 bool enabled() const;
00168 bool announce() const;
00169 bool shortbeacon() const;
00170 char version() const;
00171 std::string address() const throw (ParameterNotFoundException);
00172 int port() const;
00173 unsigned int timeout() const;
00174 };
00175
00176 class Statistic : public Configuration::Extension
00177 {
00178 friend class Configuration;
00179 protected:
00180 Statistic();
00181 ~Statistic();
00182 void load(const ibrcommon::ConfigFile &conf);
00183
00184 public:
00188 bool enabled() const;
00189
00193 ibrcommon::File logfile() const throw (ParameterNotSetException);
00194
00198 std::string type() const;
00199
00203 unsigned int interval() const;
00204
00208 std::string address() const;
00209
00213 unsigned int port() const;
00214 };
00215
00216 class Debug : public Configuration::Extension
00217 {
00218 friend class Configuration;
00219 protected:
00220 Debug();
00221 ~Debug();
00222 void load(const ibrcommon::ConfigFile &conf);
00223
00224 bool _enabled;
00225 bool _quiet;
00226 int _level;
00227
00228 public:
00232 int level() const;
00233
00237 bool enabled() const;
00238
00243 bool quiet() const;
00244
00245 };
00246
00247 class Logger : public Configuration::Extension
00248 {
00249 friend class Configuration;
00250 protected:
00251 Logger();
00252 ~Logger();
00253 void load(const ibrcommon::ConfigFile &conf);
00254
00255 bool _quiet;
00256 unsigned int _options;
00257
00258 public:
00263 bool quiet() const;
00264
00274 unsigned int options() const;
00275
00279 std::ostream &output() const;
00280 };
00281
00282 class Network : public Configuration::Extension
00283 {
00284 friend class Configuration;
00285 protected:
00286 Network();
00287 ~Network();
00288 void load(const ibrcommon::ConfigFile &conf);
00289
00290 std::list<dtn::routing::StaticRoutingExtension::StaticRoute> _static_routes;
00291 std::list<Node> _nodes;
00292 std::list<NetConfig> _interfaces;
00293 std::string _routing;
00294 bool _forwarding;
00295 bool _tcp_nodelay;
00296 size_t _tcp_chunksize;
00297 ibrcommon::NetInterface _default_net;
00298 bool _use_default_net;
00299
00300 public:
00304 const std::list<NetConfig>& getInterfaces() const;
00305
00309 const std::list<Node>& getStaticNodes() const;
00310
00314 const list<dtn::routing::StaticRoutingExtension::StaticRoute>& getStaticRoutes() const;
00315
00319 RoutingExtension getRoutingExtension() const;
00320
00325 bool doForwarding() const;
00326
00330 bool getTCPOptionNoDelay() const;
00331
00335 size_t getTCPChunkSize() const;
00336 };
00337
00338 const Configuration::Discovery& getDiscovery() const;
00339 const Configuration::Statistic& getStatistic() const;
00340 const Configuration::Debug& getDebug() const;
00341 const Configuration::Logger& getLogger() const;
00342 const Configuration::Network& getNetwork() const;
00343
00344 private:
00345 ibrcommon::ConfigFile _conf;
00346 Configuration::Discovery _disco;
00347 Configuration::Statistic _stats;
00348 Configuration::Debug _debug;
00349 Configuration::Logger _logger;
00350 Configuration::Network _network;
00351
00352 string _filename;
00353 bool _doapi;
00354 };
00355 }
00356 }
00357
00358 #endif