libswarmio/src/swarmio/tool/main.cpp
Go to the documentation of this file.
2 #include <swarmio/tool/Loop.h>
3 #include <czmq.h>
4 #include <g3log/g3log.hpp>
5 #include <g3log/logworker.hpp>
7 #include <memory>
8 #include <czmq.h>
9 
10 int main(int argc, const char* argv[])
11 {
12  // Initialize logging
13  auto worker = g3::LogWorker::createLogWorker();
14  auto buffer = std::make_unique<swarmio::tool::LogBuffer>();
15  auto buffer_ptr = buffer.get();
16  worker->addSink(std::move(buffer), &swarmio::tool::LogBuffer::ReceiveLogMessage);
17  initializeLogging(worker.get());
18 
19  // Wrap to trigger destructors before shutdown
20  {
21  // Create Zyre endpoint
22  char* hostname = zsys_hostname();
23  swarmio::transport::zyre::ZyreEndpoint endpoint(hostname, "tool");
24  zstr_free(&hostname);
25 
26  // Assign interface
27  if (argc == 2)
28  {
29  endpoint.SetInterface(argv[1]);
30  std::cout << "Selected interface: " << argv[1] << std::endl;
31  }
32 
33  // Print UUID
34  std::cout << "Local node started with UUID: " << endpoint.GetUUID() << std::endl;
35 
36  // Start endpoint
37  endpoint.Start();
38 
39  // Start loop
40  swarmio::tool::Loop loop(&endpoint, buffer_ptr);
41  loop.Run();
42 
43  // Stop endpoint
44  endpoint.Stop();
45  }
46 
47  // Shut down zsys manually to avoid assertion failure on Windows
48  zsys_shutdown();
49 
50  // All is well
51  return 0;
52 }
virtual void Stop() override
Send a termination signal and wait until the endpoint finished processing messages.
virtual const std::string & GetUUID() override
Get the UUID of the local node.
Definition: ZyreEndpoint.h:172
The command line interface for the tool.
Definition: Loop.h:19
void Run()
Run the command loop.
Definition: Loop.cpp:45
void SetInterface(const char *ifname)
Set the network interface to bind to.
int main(int argc, const char *argv[])
An Endpoint implementation using the Zyre protocol.
Definition: ZyreEndpoint.h:29
void ReceiveLogMessage(g3::LogMessageMover logEntry)
Receive log messages.
Definition: LogBuffer.h:33
virtual void Start() override
Start the background thread, announce the Zyre node and start processing messages.


swarmros
Author(s):
autogenerated on Fri Apr 3 2020 03:42:48