29int main(
int const argc,
char* argv[]) {
33 std::vector<std::string> args;
34 for (
int i = 1; i < argc; i++) {
35 args.emplace_back(argv[i]);
39 if (args.size() < 2) {
40 std::cout <<
"Error: expected at least an argument which specifies the service type and an argument which "
41 "specifies the port number (example: _test._tcp 1234 key1=value1 key2=value2)"
49 port_number = std::stoi(args[1]);
50 }
catch (
const std::exception& e) {
51 std::cout <<
"Invalid port number: " << e.what() << std::endl;
57 for (
auto it = args.begin() + 2; it != args.end(); ++it) {
61 boost::asio::io_context io_context;
65 if (advertiser ==
nullptr) {
66 RAV_LOG_ERROR(
"Error: no dnssd advertiser implementation available for this platform");
70 advertiser->on_error = [](
const auto& error_message) {
73 advertiser->on_name_conflict = [](
const auto* reg_type,
const auto* name) {
77 const auto service_id =
78 advertiser->register_service(args[0],
"Test service",
nullptr,
static_cast<uint16_t
>(port_number), txt_record,
true,
true);
80 std::thread io_context_thread([&io_context] {
84 RAV_LOG_INFO(
"Enter key=value to update the TXT record, or q to exit...");
88 std::getline(std::cin, cmd);
89 if (cmd ==
"q" || cmd ==
"Q") {
93 if (cmd ==
"r" || cmd ==
"R") {
94 advertiser->unregister_service(service_id);
100 boost::asio::post(io_context, [=, &advertiser] {
101 advertiser->update_txt_record(service_id, txt_record);
105 }
catch (
const std::exception& e) {
111 io_context_thread.join();
113 std::cout <<
"Exit" << std::endl;