iceoryx_posh  2.0.2
toml_gateway_config_parser.hpp
1 // Copyright (c) 2020 - 2021 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 
18 #ifndef IOX_POSH_GW_TOML_FILE_CONFIG_PARSER_HPP
19 #define IOX_POSH_GW_TOML_FILE_CONFIG_PARSER_HPP
20 
21 #include "iceoryx_hoofs/cxx/expected.hpp"
22 #include "iceoryx_posh/gateway/gateway_config.hpp"
23 #include "iceoryx_posh/iceoryx_posh_types.hpp"
24 
25 #include <cpptoml.h>
26 #include <limits> // workaround for missing include in cpptoml.h
27 
28 namespace iox
29 {
30 namespace config
31 {
32 enum TomlGatewayConfigParseError
33 {
34  FILE_NOT_FOUND,
35  INCOMPLETE_CONFIGURATION,
36  INCOMPLETE_SERVICE_DESCRIPTION,
37  INVALID_SERVICE_DESCRIPTION,
38  EXCEPTION_IN_PARSER,
39  MAXIMUM_NUMBER_OF_ENTRIES_EXCEEDED
40 };
41 
42 constexpr const char* TOML_GATEWAY_CONFIG_FILE_PARSE_ERROR_STRINGS[] = {"FILE_NOT_FOUND",
43  "INCOMPLETE_CONFIGURATION",
44  "INCOMPLETE_SERVICE_DESCRIPTION",
45  "INVALID_SERVICE_DESCRIPTION",
46  "EXCEPTION_IN_PARSER",
47  "MAXIMUM_NUMBER_OF_ENTRIES_EXCEEDED"};
48 
49 static constexpr const char REGEX_VALID_CHARACTERS[] = "^[a-zA-Z_][a-zA-Z0-9_]*$";
50 
51 static constexpr const char DEFAULT_CONFIG_FILE_PATH[] = "/etc/iceoryx/gateway_config.toml";
52 static constexpr const char GATEWAY_CONFIG_SERVICE_TABLE_NAME[] = "services";
53 static constexpr const char GATEWAY_CONFIG_SERVICE_NAME[] = "service";
54 static constexpr const char GATEWAY_CONFIG_SERVICE_INSTANCE_NAME[] = "instance";
55 static constexpr const char GATEWAY_CONFIG_SERVICE_EVENT_NAME[] = "event";
56 
61 {
62  public:
63  static cxx::expected<GatewayConfig, TomlGatewayConfigParseError>
64  parse(const roudi::ConfigFilePathString_t& path = roudi::ConfigFilePathString_t(DEFAULT_CONFIG_FILE_PATH)) noexcept;
65 
66  protected:
67  static cxx::expected<TomlGatewayConfigParseError> validate(const cpptoml::table& parsedToml) noexcept;
68 
69  private:
70  static bool hasInvalidCharacter(const std::string& s) noexcept;
71 };
72 
73 } // namespace config
74 } // namespace iox
75 
76 #endif // IOX_POSH_GW_TOML_FILE_CONFIG_PARSER_HPP
The TomlGatewayConfigParser class provides methods for parsing gateway configs from toml text files.
Definition: toml_gateway_config_parser.hpp:61