2 #include <swarmio/data/discovery/Schema.pb.h> 3 #include <swarmio/data/Variant.pb.h> 7 #include <g3log/g3log.hpp> 8 #include <g3log/logworker.hpp> 9 #include <libconfig.h++> 19 int main(
int argc,
const char *argv[])
25 auto worker = g3::LogWorker::createLogWorker();
27 initializeLogging(worker.get());
29 std::string configFilePath = SWARMROS_CONFIG_PATH;
30 for (
int i = 1; i < argc; ++i)
32 const char *current = argv[i];
33 if (current[0] ==
'-')
35 if (current[1] ==
'C')
38 configFilePath = current + 2;
40 else if (current[1] ==
'D' && current[2] ==
'\0')
50 LOG(FATAL) <<
"Command line argument " << i <<
" is unknown";
56 LOG(FATAL) <<
"Command line argument " << i <<
" cannot be processed";
62 libconfig::Config config;
63 std::unique_ptr<swarmio::Endpoint> endpoint;
66 config.readFile(configFilePath.c_str());
67 std::string type = (
const char *)config.lookup(
"endpoint.type");
71 auto zyreEndpoint = std::make_unique<swarmio::transport::zyre::ZyreEndpoint>(config.lookup(
"endpoint.name"), config.lookup(
"endpoint.deviceClass"));
72 zyreEndpoint->SetConfig(configFilePath);
73 endpoint = std::move(zyreEndpoint);
77 LOG(FATAL) <<
"Unknown endpoint type specified in configuration file.";
81 catch (
const libconfig::SettingTypeException &e)
83 LOG(FATAL) <<
"Invalid type for setting at " << e.getPath() <<
".";
86 catch (
const libconfig::SettingNotFoundException &e)
88 LOG(FATAL) <<
"Missing setting at " << e.getPath() <<
".";
91 catch (
const libconfig::FileIOException &e)
93 LOG(DBUG) << e.what();
94 LOG(FATAL) <<
"An exception has occurred while trying to read the configuration file.";
97 catch (
const libconfig::ParseException &e)
99 LOG(DBUG) << e.getError();
100 LOG(FATAL) <<
"An exception has occurred while trying to parse the configuration file (line " << e.getLine() <<
").";
105 LOG(DBUG) << e.
what();
106 LOG(FATAL) <<
"An exception has occurred while trying to initialize the endpoint.";
111 auto device = std::make_unique<bridge::Node>(endpoint.get());
116 if (config.exists(
"services"))
118 auto &services = config.lookup(
"services");
119 for (
int i = 0; i < services.getLength(); ++i)
121 auto &service = services[i];
122 std::string name = service.getName();
123 for (
int j = 0; j < service.getLength(); ++j)
125 auto &entry = service[j];
126 if (name ==
"publishedParameters")
128 device->PublishParameter(
129 entry.lookup(
"suffix"),
130 entry.lookup(
"message"),
131 entry.lookup(
"name"),
132 entry.lookup(
"path"),
135 else if (name ==
"bridgedParameters")
137 device->BridgeParameter(
138 entry.lookup(
"name"),
139 entry.lookup(
"path"),
142 else if (name ==
"telemetryTopics")
144 device->ForwardTelemetry(
145 entry.lookup(
"source"),
146 entry.lookup(
"message"),
147 entry.lookup(
"name"),
148 entry.lookup(
"status"));
150 else if (name ==
"incomingEvents")
152 device->PublishEvent(
153 entry.lookup(
"suffix"),
154 entry.lookup(
"message"),
155 entry.lookup(
"name"));
157 else if (name ==
"outgoingEvents")
159 device->ForwardEvent(
160 entry.lookup(
"source"),
161 entry.lookup(
"message"));
165 LOG(WARNING) <<
"Unknown service type: " << name;
172 catch (
const libconfig::SettingTypeException &e)
174 LOG(FATAL) <<
"Invalid type for setting at " << e.getPath() <<
".";
177 catch (
const libconfig::SettingNotFoundException &e)
179 LOG(FATAL) <<
"Missing setting at " << e.getPath() <<
".";
184 LOG(DBUG) << e.
what();
185 LOG(FATAL) <<
"An exception has occurred while trying to initialize the endpoint.";
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Exception class thrown by all library classes.
int main(int argc, const char *argv[])
void ReceiveLogMessage(g3::LogMessageMover logEntry)
Receives messages from g3log and forwards them to ROS.
const char * what() const noexceptoverride
Get the error message.
ROSCONSOLE_DECL bool set_logger_level(const std::string &name, levels::Level level)
#define ROSCONSOLE_DEFAULT_NAME