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
|
||||
}
|
||||
```
|
||||
|
||||
## `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"},
|
||||
})
|
||||
|
||||
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)
|
||||
{
|
||||
config_file = path;
|
||||
@@ -93,44 +102,47 @@ configuration configuration::read_user_configuration()
|
||||
{
|
||||
auto json = nlohmann::json::parse(file);
|
||||
|
||||
if (json.contains("scale"))
|
||||
if (auto it = json.find("scale"); it != json.end())
|
||||
{
|
||||
if (json["scale"].is_number())
|
||||
result.scale = std::array<double, 2>{json["scale"], json["scale"]};
|
||||
if (it->is_number())
|
||||
result.scale = std::array<double, 2>{*it, *it};
|
||||
else
|
||||
result.scale = json["scale"];
|
||||
result.scale = *it;
|
||||
}
|
||||
|
||||
if (json.contains("bitrate"))
|
||||
{
|
||||
result.bitrate = json["bitrate"];
|
||||
}
|
||||
if (auto it = json.find("bitrate"); it != json.end())
|
||||
result.bitrate = *it;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
if (json.contains("encoder-passthrough"))
|
||||
result.encoder_passthrough = parse_encoder(json["encoder-passthrough"]);
|
||||
if (auto it = json.find("encoder-passthrough"); it != json.end())
|
||||
result.encoder_passthrough = parse_encoder(*it);
|
||||
|
||||
if (json.contains("application"))
|
||||
if (auto it = json.find("application"); it != json.end())
|
||||
{
|
||||
if (json["application"].is_string())
|
||||
result.application.push_back(json["application"]);
|
||||
if (it->is_string())
|
||||
result.application.push_back(*it);
|
||||
else
|
||||
{
|
||||
for (const auto & i: json["application"])
|
||||
{
|
||||
for (const auto & i: *it)
|
||||
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)
|
||||
|
||||
@@ -29,6 +29,13 @@
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
enum class service_publication
|
||||
{
|
||||
none,
|
||||
avahi,
|
||||
};
|
||||
|
||||
struct configuration
|
||||
{
|
||||
struct encoder
|
||||
@@ -50,6 +57,7 @@ struct configuration
|
||||
std::optional<std::array<double, 2>> scale;
|
||||
std::vector<std::string> application;
|
||||
bool tcp_only = false;
|
||||
service_publication publication = service_publication::avahi;
|
||||
|
||||
static void set_config_file(const std::filesystem::path &);
|
||||
static const std::filesystem::path & get_config_file();
|
||||
|
||||
+24
-14
@@ -205,7 +205,7 @@ pid_t app_pid;
|
||||
bool quitting_main_loop;
|
||||
bool do_fork;
|
||||
bool do_active_runtime;
|
||||
bool avahi_publish;
|
||||
wivrn::service_publication publication;
|
||||
|
||||
guint listener_watch;
|
||||
|
||||
@@ -384,19 +384,25 @@ void stop_listening()
|
||||
|
||||
void start_publishing()
|
||||
{
|
||||
if (not avahi_publish)
|
||||
return;
|
||||
if (publisher)
|
||||
return;
|
||||
switch (publication)
|
||||
{
|
||||
case wivrn::service_publication::none:
|
||||
return;
|
||||
|
||||
char protocol_string[17];
|
||||
sprintf(protocol_string, "%016" PRIx64, wivrn::protocol_version);
|
||||
std::map<std::string, std::string> TXT = {
|
||||
{"protocol", protocol_string},
|
||||
{"version", wivrn::git_version},
|
||||
{"cookie", server_cookie()},
|
||||
};
|
||||
publisher.emplace(poll_api, hostname(), "_wivrn._tcp", wivrn::default_port, TXT);
|
||||
case wivrn::service_publication::avahi: {
|
||||
if (publisher)
|
||||
return;
|
||||
|
||||
char protocol_string[17];
|
||||
sprintf(protocol_string, "%016" PRIx64, wivrn::protocol_version);
|
||||
std::map<std::string, std::string> 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()
|
||||
@@ -985,13 +991,17 @@ int main(int argc, char * argv[])
|
||||
|
||||
do_active_runtime = not *no_active_runtime;
|
||||
do_fork = not *no_fork;
|
||||
avahi_publish = not *no_publish;
|
||||
if (*no_encrypt)
|
||||
enc_state = wivrn_connection::encryption_state::disabled;
|
||||
|
||||
if (not config_file.empty())
|
||||
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 (*app_flag)
|
||||
return exec_application(configuration::read_user_configuration());
|
||||
|
||||
Reference in New Issue
Block a user