YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Server.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
8
9#include <yarp/os/Bottle.h>
10#include <yarp/os/Contact.h>
11#include <yarp/os/Port.h>
12#include <yarp/os/Property.h>
13#include <yarp/os/SystemClock.h>
14#include <yarp/os/Log.h>
15#include <yarp/os/LogStream.h>
21
22#include <cstdio>
23#include <cmath>
24
27using yarp::os::Port;
34
35YARP_SERVERSQL_LOG_COMPONENT(SERVER, "yarp.serversql.Server")
36
37
38int yarp::serversql::Server::run(int argc, char** argv)
39{
40 Property options;
41 options.fromCommand(argc, argv, false);
42
43 bool verbose = options.check("verbose");
44 bool silent = options.check("silent");
45
46 if (verbose) {
48 } else if (silent) {
50 }
51
52 yCInfo(SERVER, R"===(
53 ==========================
54 | __ __ ___ ____ ____ |
55 | \ \/ // || _ \ | _ \ |
56 | \ // /| || |/ / | |/ / |
57 | / // ___ || _ \ | _/ |
58 | /_//_/ |_||_| \_\|_| |
59 | |
60 ==========================)===");
62
63 if (options.check("help")) {
64 yCInfo(SERVER, "Welcome to the YARP name server.\n");
65 yCInfo(SERVER, " --write Write IP address and socket on the configuration file.\n");
66 yCInfo(SERVER, " --config filename.conf Load options from a file.\n");
67 yCInfo(SERVER, " --portdb ports.db Store port information in named database.\n");
68 yCInfo(SERVER, " Must not be on an NFS file system.\n");
69 yCInfo(SERVER, " Set to :memory: to store in memory (faster).\n");
70 yCInfo(SERVER, " --subdb subs.db Store subscription information in named database.\n");
71 yCInfo(SERVER, " Must not be on an NFS file system.\n");
72 yCInfo(SERVER, " Set to :memory: to store in memory (faster).\n");
73 yCInfo(SERVER, " --ip IP.AD.DR.ESS Set IP address of server.\n");
74 yCInfo(SERVER, " --socket NNNNN Set port number of server.\n");
75 yCInfo(SERVER, " --web dir Serve web resources from given directory.\n");
76 yCInfo(SERVER, " --no-web-cache Reload pages from file for each request.\n");
77 yCInfo(SERVER, " --silent Start in silent mode.\n");
78 //this->stop();
79
80 return 0;
81 } else {
82 yCInfo(SERVER, "Call with --help for information on available options\n");
83 }
84
86 if (!nc.open(options)) {
87 return 1;
88 }
89
90 bool ok = false;
91 NameServerManager name(nc);
92 BootstrapServer fallback(name);
93 Port server;
94 Bottle cmd;
95 Bottle reply;
96 double messageCounter(0);
97 double pollingRate(.1);
98
99 name.setPort(server);
100 server.setReaderCreator(name);
101
102 ok = server.open(nc.where(),false);
103 if (!ok) {
104 yCError(SERVER, "Name server failed to open\n");
105 return 1;
106 }
107
108 fallback.start();
109
110
111 // Repeat registrations for the server and fallback server -
112 // these registrations are more complete.
113 yCInfo(SERVER, "Registering name server with itself");
114 nc.preregister(nc.where());
115 nc.preregister(fallback.where());
116 nc.goPublic();
117
118 //Setting nameserver property
119 cmd.addString("set");
120 cmd.addString(server.getName());
121 cmd.addString("nameserver");
122 cmd.addString("true");
123
124 NameClient::getNameClient().send(cmd, reply);
125
126 yCInfo(SERVER, "Name server can be browsed at http:/%s",
127 nc.where().toURI(false).c_str());
128 yCInfo(SERVER, "Ok. Ready!");
129
130 while(!shouldStop) {
131 messageCounter += pollingRate;
132 SystemClock::delaySystem(pollingRate);
133 double dummy;
134
135 if(std::modf(messageCounter / 600.0, &dummy) < .00001) {
136 yCInfo(SERVER, "Name server running happily");
137 }
138 }
139
140 yCInfo(SERVER, "closing yarp server");
141 server.close();
142 return 0;
143}
const yarp::os::LogComponent & SERVER()
Definition Server.cpp:35
Multicast and file-based mechanisms for finding the name server.
Manage the name server.
void setPort(yarp::os::Port &port)
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition Bottle.cpp:176
Represents how to reach a part of a YARP network.
Definition Contact.h:33
std::string toURI(bool includeCarrier=true) const
Get a representation of the Contact as a URI.
Definition Contact.cpp:313
virtual std::string getName() const
Get name of port.
@ DebugType
Definition Log.h:93
@ WarningType
Definition Log.h:95
A mini-server for network communication.
Definition Port.h:46
void setReaderCreator(PortReaderCreator &creator)
Set a creator for readers for port data.
Definition Port.cpp:484
void close() override
Stop port activity.
Definition Port.cpp:330
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A class for storing options and configuration information.
Definition Property.h:32
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
static void delaySystem(double seconds)
Client for YARP name server.
Definition NameClient.h:32
static NameClient & getNameClient()
Get an instance of the name client.
bool open(yarp::os::Searchable &options)
void preregister(const yarp::os::Contact &c)
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_SERVERSQL_LOG_COMPONENT(name, name_string)
void setMinumumLogType(yarp::os::Log::LogType minumumLogType)
The main, catch-all namespace for YARP.
Definition dirs.h:16