iceoryx_doc  1.0.1
toml_gateway_config_parser.hpp
1 // Copyright (c) 2020 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_posh/gateway/gateway_config.hpp"
22 #include "iceoryx_posh/iceoryx_posh_types.hpp"
23 #include "iceoryx_utils/cxx/expected.hpp"
24 
25 #include <cpptoml.h>
26 
27 namespace iox
28 {
29 namespace config
30 {
31 enum TomlGatewayConfigParseError
32 {
33  INVALID_STATE,
34  FILE_NOT_FOUND,
35  INCOMPLETE_CONFIGURATION,
36  INCOMPLETE_SERVICE_DESCRIPTION,
37  INVALID_SERVICE_DESCRIPTION,
38  EXCEPTION_IN_PARSER
39 };
40 
41 constexpr char TOML_GATEWAY_CONFIG_FILE_PARSE_ERROR_STRINGS[][64] = {"INVALID_STATE",
42  "FILE_NOT_FOUND",
43  "INCOMPLETE_CONFIGURATION",
44  "INCOMPLETE_SERVICE_DESCRIPTION",
45  "INVALID_SERVICE_DESCRIPTION",
46  "EXCEPTION_IN_PARSER"};
47 
48 static constexpr const char REGEX_VALID_CHARACTERS[] = "^[a-zA-Z_][a-zA-Z0-9_]*$";
49 
50 static constexpr const char DEFAULT_CONFIG_FILE_PATH[] = "/etc/iceoryx/gateway_config.toml";
51 static constexpr const char GATEWAY_CONFIG_SERVICE_TABLE_NAME[] = "services";
52 static constexpr const char GATEWAY_CONFIG_SERVICE_NAME[] = "service";
53 static constexpr const char GATEWAY_CONFIG_SERVICE_INSTANCE_NAME[] = "instance";
54 static constexpr const char GATEWAY_CONFIG_SERVICE_EVENT_NAME[] = "event";
55 
60 {
61  public:
62  static cxx::expected<GatewayConfig, TomlGatewayConfigParseError> parse();
63  static cxx::expected<GatewayConfig, TomlGatewayConfigParseError> parse(const roudi::ConfigFilePathString_t& path);
64 
65  protected:
66  static cxx::expected<TomlGatewayConfigParseError> validate(const cpptoml::table& parsedToml) noexcept;
67 
68  private:
69  static bool hasInvalidCharacter(const std::string& s) noexcept;
70 };
71 
72 } // namespace config
73 } // namespace iox
74 
75 #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:60
Definition: service_description.hpp:29