Allow service publication to be set in json
This commit is contained in:
@@ -170,3 +170,10 @@ If `false` or unset, WiVRn will use both TCP and UDP.
|
|||||||
"tcp_only": true
|
"tcp_only": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## `publish-service`
|
||||||
|
Default value: `avahi`
|
||||||
|
|
||||||
|
How to publish the service over the network, `avahi` or null.
|
||||||
|
|
||||||
|
If set to null, service will not be published and address has to be entered manually on the headset.
|
||||||
|
|||||||
@@ -50,6 +50,15 @@ NLOHMANN_JSON_SERIALIZE_ENUM(
|
|||||||
{av1, "AV1"},
|
{av1, "AV1"},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
NLOHMANN_JSON_SERIALIZE_ENUM(
|
||||||
|
service_publication,
|
||||||
|
{
|
||||||
|
{service_publication(-1), ""},
|
||||||
|
{service_publication::none, nullptr},
|
||||||
|
{service_publication::none, "none"},
|
||||||
|
{service_publication::avahi, "avahi"},
|
||||||
|
})
|
||||||
|
|
||||||
void configuration::set_config_file(const std::filesystem::path & path)
|
void configuration::set_config_file(const std::filesystem::path & path)
|
||||||
{
|
{
|
||||||
config_file = path;
|
config_file = path;
|
||||||
@@ -93,44 +102,47 @@ configuration configuration::read_user_configuration()
|
|||||||
{
|
{
|
||||||
auto json = nlohmann::json::parse(file);
|
auto json = nlohmann::json::parse(file);
|
||||||
|
|
||||||
if (json.contains("scale"))
|
if (auto it = json.find("scale"); it != json.end())
|
||||||
{
|
{
|
||||||
if (json["scale"].is_number())
|
if (it->is_number())
|
||||||
result.scale = std::array<double, 2>{json["scale"], json["scale"]};
|
result.scale = std::array<double, 2>{*it, *it};
|
||||||
else
|
else
|
||||||
result.scale = json["scale"];
|
result.scale = *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.contains("bitrate"))
|
if (auto it = json.find("bitrate"); it != json.end())
|
||||||
{
|
result.bitrate = *it;
|
||||||
result.bitrate = json["bitrate"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json.contains("encoders"))
|
if (auto it = json.find("encoders"); it != json.end())
|
||||||
{
|
{
|
||||||
for (const auto & encoder: json["encoders"])
|
for (const auto & encoder: *it)
|
||||||
result.encoders.push_back(parse_encoder(encoder));
|
result.encoders.push_back(parse_encoder(encoder));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.contains("encoder-passthrough"))
|
if (auto it = json.find("encoder-passthrough"); it != json.end())
|
||||||
result.encoder_passthrough = parse_encoder(json["encoder-passthrough"]);
|
result.encoder_passthrough = parse_encoder(*it);
|
||||||
|
|
||||||
if (json.contains("application"))
|
if (auto it = json.find("application"); it != json.end())
|
||||||
{
|
{
|
||||||
if (json["application"].is_string())
|
if (it->is_string())
|
||||||
result.application.push_back(json["application"]);
|
result.application.push_back(*it);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (const auto & i: json["application"])
|
for (const auto & i: *it)
|
||||||
{
|
|
||||||
result.application.push_back(i);
|
result.application.push_back(i);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.contains("tcp_only"))
|
if (auto it = json.find("tcp-only"); it != json.end())
|
||||||
|
result.tcp_only = *it;
|
||||||
|
else if (auto it = json.find("tcp_only"); it != json.end())
|
||||||
|
result.tcp_only = *it;
|
||||||
|
|
||||||
|
if (auto it = json.find("publish-service"); it != json.end())
|
||||||
{
|
{
|
||||||
result.tcp_only = json["tcp_only"];
|
result.publication = *it;
|
||||||
|
if (result.publication == service_publication(-1))
|
||||||
|
throw std::runtime_error("invalid service publication " + it->get<std::string>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception & e)
|
catch (const std::exception & e)
|
||||||
|
|||||||
@@ -29,6 +29,13 @@
|
|||||||
|
|
||||||
namespace wivrn
|
namespace wivrn
|
||||||
{
|
{
|
||||||
|
|
||||||
|
enum class service_publication
|
||||||
|
{
|
||||||
|
none,
|
||||||
|
avahi,
|
||||||
|
};
|
||||||
|
|
||||||
struct configuration
|
struct configuration
|
||||||
{
|
{
|
||||||
struct encoder
|
struct encoder
|
||||||
@@ -50,6 +57,7 @@ struct configuration
|
|||||||
std::optional<std::array<double, 2>> scale;
|
std::optional<std::array<double, 2>> scale;
|
||||||
std::vector<std::string> application;
|
std::vector<std::string> application;
|
||||||
bool tcp_only = false;
|
bool tcp_only = false;
|
||||||
|
service_publication publication = service_publication::avahi;
|
||||||
|
|
||||||
static void set_config_file(const std::filesystem::path &);
|
static void set_config_file(const std::filesystem::path &);
|
||||||
static const std::filesystem::path & get_config_file();
|
static const std::filesystem::path & get_config_file();
|
||||||
|
|||||||
+24
-14
@@ -205,7 +205,7 @@ pid_t app_pid;
|
|||||||
bool quitting_main_loop;
|
bool quitting_main_loop;
|
||||||
bool do_fork;
|
bool do_fork;
|
||||||
bool do_active_runtime;
|
bool do_active_runtime;
|
||||||
bool avahi_publish;
|
wivrn::service_publication publication;
|
||||||
|
|
||||||
guint listener_watch;
|
guint listener_watch;
|
||||||
|
|
||||||
@@ -384,19 +384,25 @@ void stop_listening()
|
|||||||
|
|
||||||
void start_publishing()
|
void start_publishing()
|
||||||
{
|
{
|
||||||
if (not avahi_publish)
|
switch (publication)
|
||||||
return;
|
{
|
||||||
if (publisher)
|
case wivrn::service_publication::none:
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char protocol_string[17];
|
case wivrn::service_publication::avahi: {
|
||||||
sprintf(protocol_string, "%016" PRIx64, wivrn::protocol_version);
|
if (publisher)
|
||||||
std::map<std::string, std::string> TXT = {
|
return;
|
||||||
{"protocol", protocol_string},
|
|
||||||
{"version", wivrn::git_version},
|
char protocol_string[17];
|
||||||
{"cookie", server_cookie()},
|
sprintf(protocol_string, "%016" PRIx64, wivrn::protocol_version);
|
||||||
};
|
std::map<std::string, std::string> TXT = {
|
||||||
publisher.emplace(poll_api, hostname(), "_wivrn._tcp", wivrn::default_port, TXT);
|
{"protocol", protocol_string},
|
||||||
|
{"version", wivrn::git_version},
|
||||||
|
{"cookie", server_cookie()},
|
||||||
|
};
|
||||||
|
publisher.emplace(poll_api, hostname(), "_wivrn._tcp", wivrn::default_port, TXT);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop_publishing()
|
void stop_publishing()
|
||||||
@@ -985,13 +991,17 @@ int main(int argc, char * argv[])
|
|||||||
|
|
||||||
do_active_runtime = not *no_active_runtime;
|
do_active_runtime = not *no_active_runtime;
|
||||||
do_fork = not *no_fork;
|
do_fork = not *no_fork;
|
||||||
avahi_publish = not *no_publish;
|
|
||||||
if (*no_encrypt)
|
if (*no_encrypt)
|
||||||
enc_state = wivrn_connection::encryption_state::disabled;
|
enc_state = wivrn_connection::encryption_state::disabled;
|
||||||
|
|
||||||
if (not config_file.empty())
|
if (not config_file.empty())
|
||||||
configuration::set_config_file(config_file);
|
configuration::set_config_file(config_file);
|
||||||
|
|
||||||
|
if (*no_publish)
|
||||||
|
publication = wivrn::service_publication::none;
|
||||||
|
else
|
||||||
|
publication = configuration::read_user_configuration().publication;
|
||||||
|
|
||||||
#if WIVRN_USE_SYSTEMD
|
#if WIVRN_USE_SYSTEMD
|
||||||
if (*app_flag)
|
if (*app_flag)
|
||||||
return exec_application(configuration::read_user_configuration());
|
return exec_application(configuration::read_user_configuration());
|
||||||
|
|||||||
Reference in New Issue
Block a user