|
17 | 17 | namespace OpenWifi { |
18 | 18 | class ConfigurationValidator : public SubSystemServer { |
19 | 19 | public: |
| 20 | + |
| 21 | + enum class ConfigurationType { AP = 0 , SWITCH = 1}; |
| 22 | + |
20 | 23 | static auto instance() { |
21 | 24 | static auto instance_ = new ConfigurationValidator; |
22 | 25 | return instance_; |
23 | 26 | } |
24 | 27 |
|
25 | | - bool Validate(const std::string &C, std::vector<std::string> &Errors, bool Strict); |
| 28 | + bool Validate(ConfigurationType Type, const std::string &C, std::string &Errors, bool Strict); |
26 | 29 | int Start() override; |
27 | 30 | void Stop() override; |
28 | 31 | void reinitialize(Poco::Util::Application &self) override; |
29 | 32 |
|
| 33 | + inline static ConfigurationType GetType(const std::string &type) { |
| 34 | + std::string Type = Poco::toUpper(type); |
| 35 | + if (Type == "AP") |
| 36 | + return ConfigurationType::AP; |
| 37 | + if (Type == "SWITCH") |
| 38 | + return ConfigurationType::SWITCH; |
| 39 | + return ConfigurationType::AP; |
| 40 | + } |
| 41 | + |
30 | 42 | private: |
31 | 43 | bool Initialized_ = false; |
32 | 44 | bool Working_ = false; |
33 | 45 | void Init(); |
34 | | - std::unique_ptr<valijson::Schema> RootSchema_; |
35 | | - std::unique_ptr<valijson::SchemaParser> SchemaParser_; |
36 | | - std::unique_ptr<valijson::adapters::PocoJsonAdapter> PocoJsonAdapter_; |
37 | | - Poco::JSON::Object::Ptr SchemaDocPtr_; |
38 | | - bool SetSchema(const std::string &SchemaStr); |
| 46 | + std::array<valijson::Schema,2> RootSchema_; |
| 47 | + bool SetSchema(ConfigurationType Type, const std::string &SchemaStr); |
39 | 48 |
|
40 | 49 | ConfigurationValidator() |
41 | 50 | : SubSystemServer("ConfigValidator", "CFG-VALIDATOR", "config.validator") {} |
42 | 51 | }; |
43 | 52 |
|
44 | 53 | inline auto ConfigurationValidator() { return ConfigurationValidator::instance(); } |
45 | | - inline bool ValidateUCentralConfiguration(const std::string &C, std::vector<std::string> &Error, |
| 54 | + inline bool ValidateUCentralConfiguration(ConfigurationValidator::ConfigurationType Type, const std::string &C, std::string &Errors, |
46 | 55 | bool strict) { |
47 | | - return ConfigurationValidator::instance()->Validate(C, Error, strict); |
| 56 | + return ConfigurationValidator::instance()->Validate(Type, C, Errors, strict); |
48 | 57 | } |
49 | 58 | } // namespace OpenWifi |
0 commit comments