| 141 | } |
| 142 | |
| 143 | int run(int argc, ACE_TCHAR* argv[]) |
| 144 | { |
| 145 | DDS::DomainParticipantFactory_var factory{TheParticipantFactoryWithArgs(argc, argv)}; |
| 146 | if (!factory) { |
| 147 | ACE_ERROR((LM_ERROR, "ERROR: Failed to get participant factory\n")); |
| 148 | return EXIT_FAILURE; |
| 149 | } |
| 150 | |
| 151 | DDS::DomainId_t domain{0}; |
| 152 | RelayConfig config; |
| 153 | |
| 154 | ACE_Argv_Type_Converter atc{argc, argv}; |
| 155 | ACE_Arg_Shifter_T<char> args{atc.get_argc(), atc.get_ASCII_argv()}; |
| 156 | for (args.ignore_arg(); args.is_anything_left(); args.consume_arg()) { |
| 157 | const char* arg{nullptr}; |
| 158 | if ((arg = args.get_the_parameter("-Domain"))) { |
| 159 | domain = std::atoi(arg); |
| 160 | } else if ((arg = args.get_the_parameter("-RelayId"))) { |
| 161 | config.relay_id(arg); |
| 162 | } else if ((arg = args.get_the_parameter("-Set"))) { |
| 163 | const std::string arg_str{arg}; |
| 164 | const auto pos{arg_str.find_first_of('=')}; |
| 165 | if (pos && pos != std::string::npos) { |
| 166 | const auto key{OpenDDS::DCPS::ConfigPair::canonicalize(arg_str.substr(0, pos))}; |
| 167 | config.config()[key] = arg_str.substr(pos + 1); |
| 168 | if (key.substr(0, sizeof(prefix) - 1) != prefix) { |
| 169 | show_all = true; |
| 170 | } |
| 171 | } else { |
| 172 | throw std::runtime_error{"Argument to -Set must be NAME=Value: " + arg_str}; |
| 173 | } |
| 174 | } else if (args.cur_arg_strncasecmp("-ShowAll") == 0) { |
| 175 | show_all = true; |
| 176 | } else if (args.cur_arg_strncasecmp("-KeepRunning") == 0) { |
| 177 | keep_running = true; |
| 178 | } else { |
| 179 | ACE_ERROR((LM_ERROR, "ERROR: Invalid argument: %C\n", args.get_current())); |
| 180 | return EXIT_FAILURE; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | if (keep_running || config.relay_id().empty()) { |
| 185 | std::cerr << "Running until Ctrl-C" << std::endl; |
| 186 | } |
| 187 | |
| 188 | DDS::DomainParticipantQos participant_qos; |
| 189 | factory->get_default_participant_qos(participant_qos); |
| 190 | { |
| 191 | const auto idx{participant_qos.property.value.length()}; |
| 192 | participant_qos.property.value.length(idx + 1); |
| 193 | const DDS::Property_t p{OpenDDS::RTPS::RTPS_REFLECT_HEARTBEAT_COUNT, "true", false}; |
| 194 | participant_qos.property.value[idx] = p; |
| 195 | } |
| 196 | DDS::DomainParticipant_var participant{factory->create_participant(domain, participant_qos, nullptr, 0)}; |
| 197 | if (!participant) { |
| 198 | ACE_ERROR((LM_ERROR, "ERROR: Failed to create relay participant\n")); |
| 199 | return EXIT_FAILURE; |
| 200 | } |
no test coverage detected