Define enum for exit codes
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace wivrn_exit_code
|
||||
{
|
||||
enum
|
||||
{
|
||||
success = EXIT_SUCCESS,
|
||||
unknown_error = EXIT_FAILURE,
|
||||
cannot_create_pipe,
|
||||
cannot_create_socketpair,
|
||||
cannot_connect_to_avahi,
|
||||
};
|
||||
}
|
||||
+16
-14
@@ -9,21 +9,23 @@
|
||||
#include <avahi-common/strlst.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
const std::error_category & avahi_error_category()
|
||||
{
|
||||
struct : std::error_category
|
||||
{
|
||||
const char * name() const noexcept override
|
||||
static struct : std::error_category
|
||||
{
|
||||
return "avahi";
|
||||
}
|
||||
const char * name() const noexcept override
|
||||
{
|
||||
return "avahi";
|
||||
}
|
||||
|
||||
std::string message(int condition) const override
|
||||
{
|
||||
return avahi_strerror(condition);
|
||||
}
|
||||
} avahi_error_category;
|
||||
} // namespace
|
||||
std::string message(int condition) const override
|
||||
{
|
||||
return avahi_strerror(condition);
|
||||
}
|
||||
} _avahi_error_category;
|
||||
|
||||
return _avahi_error_category;
|
||||
}
|
||||
|
||||
void avahi_publisher::alt_name()
|
||||
{
|
||||
@@ -40,7 +42,7 @@ void avahi_publisher::create_service(AvahiClient * client)
|
||||
if (!entry_group)
|
||||
{
|
||||
throw std::system_error(avahi_client_errno(client),
|
||||
avahi_error_category,
|
||||
avahi_error_category(),
|
||||
"Cannot create entry group, ensure disable-user-service-publishing is unset in avahi daemon config");
|
||||
}
|
||||
}
|
||||
@@ -148,7 +150,7 @@ avahi_publisher::avahi_publisher(const AvahiPoll * poll_api, const std::string &
|
||||
&error);
|
||||
|
||||
if (!avahi_client)
|
||||
throw std::system_error(error, avahi_error_category, "Cannot create avahi client");
|
||||
throw std::system_error(error, avahi_error_category(), "Cannot create avahi client");
|
||||
}
|
||||
|
||||
avahi_publisher::~avahi_publisher()
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
#include <avahi-common/watch.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <vector>
|
||||
|
||||
const std::error_category & avahi_error_category();
|
||||
|
||||
class avahi_publisher
|
||||
{
|
||||
AvahiEntryGroup * entry_group{};
|
||||
|
||||
+11
-4
@@ -11,6 +11,7 @@
|
||||
#include "active_runtime.h"
|
||||
#include "avahi_publisher.h"
|
||||
#include "driver/configuration.h"
|
||||
#include "exit_codes.h"
|
||||
#include "hostname.h"
|
||||
#include "start_application.h"
|
||||
#include "version.h"
|
||||
@@ -616,7 +617,7 @@ int inner_main(int argc, char * argv[], bool show_instructions)
|
||||
if (pipe(stdin_pipe_fds) < 0)
|
||||
{
|
||||
perror("pipe");
|
||||
return EXIT_FAILURE;
|
||||
return wivrn_exit_code::cannot_create_pipe;
|
||||
}
|
||||
fcntl(stdin_pipe_fds[0], F_SETFD, FD_CLOEXEC);
|
||||
fcntl(stdin_pipe_fds[1], F_SETFD, FD_CLOEXEC);
|
||||
@@ -625,7 +626,7 @@ int inner_main(int argc, char * argv[], bool show_instructions)
|
||||
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, control_pipe_fds) < 0)
|
||||
{
|
||||
perror("socketpair");
|
||||
return EXIT_FAILURE;
|
||||
return wivrn_exit_code::cannot_create_socketpair;
|
||||
}
|
||||
fcntl(control_pipe_fds[0], F_SETFD, FD_CLOEXEC);
|
||||
fcntl(control_pipe_fds[1], F_SETFD, FD_CLOEXEC);
|
||||
@@ -672,7 +673,7 @@ int inner_main(int argc, char * argv[], bool show_instructions)
|
||||
std::filesystem::remove(socket_path(), ec);
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return wivrn_exit_code::success;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
@@ -701,9 +702,15 @@ int main(int argc, char * argv[])
|
||||
{
|
||||
return inner_main(argc, argv, not *no_instructions);
|
||||
}
|
||||
catch (std::system_error & e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
if (e.code().category() == avahi_error_category())
|
||||
return wivrn_exit_code::cannot_connect_to_avahi;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
return wivrn_exit_code::unknown_error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user