-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.cpp
More file actions
189 lines (150 loc) · 4.72 KB
/
Copy pathmain.cpp
File metadata and controls
189 lines (150 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "log/DSLog.h"
#include "version/config.h"
#include <fastdds/dds/log/StdoutErrConsumer.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include "DiscoveryServerManager.h"
#include "arguments.h"
using namespace eprosima;
using namespace fastdds;
using namespace fastdds::rtps;
using namespace discovery_server;
using namespace std;
int main(
int argc,
char* argv[])
{
// Clear all the consumers.
Log::ClearConsumers();
// Initialize loging
#if LOG_LEVEL_INFO
Log::SetVerbosity(Log::Kind::Info);
#elif LOG_LEVEL_WARN
Log::SetVerbosity(Log::Kind::Warning);
#elif LOG_LEVEL_ERROR
Log::SetVerbosity(Log::Kind::Error);
#else
Log::SetVerbosity(Log::Kind::Error);
#endif // if LOG_LEVEL_INFO
// Create a StdoutErrConsumer consumer that logs entries to stderr only when the Log::Kind is equal to WARNING
// This allows the test validate the output of the executions
std::unique_ptr<eprosima::fastdds::dds::StdoutErrConsumer> stdouterr_consumer(
new eprosima::fastdds::dds::StdoutErrConsumer());
stdouterr_consumer->stderr_threshold(Log::Kind::Warning);
// Register the consumer
Log::RegisterConsumer(std::move(stdouterr_consumer));
// skip program name argv[0] if present
argc -= (argc > 0);
argv += (argc > 0);
option::Stats stats(usage, argc, argv);
vector<option::Option> options(stats.options_max);
vector<option::Option> buffer(stats.buffer_max);
option::Parser parse(usage, argc, argv, &options[0], &buffer[0]);
// check the command line options
if (parse.error())
{
return 1;
}
// no arguments beyond options
int noopts = parse.nonOptionsCount();
if ( noopts )
{
string sep( noopts == 1 ? "argument: " : "arguments: " );
cout << "Unknown ";
while ( noopts-- )
{
cout << sep << parse.nonOption(noopts);
sep = ", ";
}
endl(cout);
return 1;
}
// show help if asked to
if (options[HELP] || argc == 0)
{
option::printUsage(std::cout, usage);
return 0;
}
// Load config file path from arg
option::Option* pOp = options[CONFIG_FILE];
if ( nullptr == pOp )
{
cout << "Specify configuration file is mandatory: use -c or --config-file option." << endl;
return 1;
}
else if ( pOp->count() != 1)
{
cout << "Only one configuration file can be specified." << endl;
return 1;
}
int return_code = 0;
std::string path_to_config = pOp->arg;
// Load Default XML files
DomainParticipantFactory::get_instance()->load_profiles();
// Load properties file path from arg
pOp = options[PROPERTIES_FILE];
std::string path_to_properties;
if ( nullptr != pOp )
{
if ( pOp->count() != 1)
{
cout << "Only one properties file can be specified." << endl;
return 1;
}
path_to_properties = pOp->arg;
}
// Create DiscoveryServerManager
DiscoveryServerManager manager(path_to_config, path_to_properties, options[SHM]);
if (!manager.correctly_created())
{
return_code = 1;
}
// Load output file path
option::Option* pOp_of = options[OUTPUT_FILE];
if ( nullptr != pOp_of )
{
manager.output_file(pOp_of->arg);
}
// Follow the config file instructions
manager.runEvents(std::cin, std::cout);
// Check the snapshots read
if (manager.shouldValidate())
{
if (!manager.validateAllSnapshots())
{
LOG_ERROR("Discovery Server error: several snapshots show info leakage");
return_code = -1; // report CTest the test fail
}
else
{
std::cout << manager.successMessage() << std::endl;
}
}
Log::Flush();
manager.onTerminate();
return return_code;
}
/*static*/
option::ArgStatus Arg::check_inp(
const option::Option& option,
bool /* msg */)
{
// the argument is required
if ( nullptr != option.arg )
{
return option::ARG_OK;
}
return option::ARG_ILLEGAL;
}