From: Sangwan Kwon Date: Thu, 28 Nov 2019 07:55:08 +0000 (+0900) Subject: Fix to use vist exception X-Git-Tag: submit/tizen/20200810.073515~143 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9f8e63df2b59f94de8e94f27e3415122ce2ca120;p=platform%2Fcore%2Fsecurity%2Fvist.git Fix to use vist exception Signed-off-by: Sangwan Kwon --- diff --git a/src/vist/event/eventfd.cpp b/src/vist/event/eventfd.cpp index 3e27692..a211bb3 100644 --- a/src/vist/event/eventfd.cpp +++ b/src/vist/event/eventfd.cpp @@ -22,11 +22,12 @@ #include "eventfd.hpp" +#include + #include #include #include -#include namespace vist { namespace event { @@ -35,7 +36,7 @@ EventFD::EventFD(unsigned int initval, int flags) : fd(::eventfd(initval, flags)) { if (this->fd == -1) - throw std::runtime_error("Failed to create eventfd."); + THROW(ErrCode::RuntimeError) << "Failed to create eventfd."; } EventFD::~EventFD() @@ -47,14 +48,14 @@ void EventFD::send(void) { const std::uint64_t val = 1; if (::write(this->fd, &val, sizeof(val)) == -1) - throw std::runtime_error("Failed to write to eventfd."); + THROW(ErrCode::RuntimeError) << "Failed to write to eventfd."; } void EventFD::receive(void) { std::uint64_t val; if (::read(this->fd, &val, sizeof(val)) == -1) - throw std::runtime_error("Failed to read from eventfd."); + THROW(ErrCode::RuntimeError) << "Failed to read from eventfd."; } int EventFD::getFd(void) const noexcept diff --git a/src/vist/event/mainloop.cpp b/src/vist/event/mainloop.cpp index 991ceb8..4e72104 100644 --- a/src/vist/event/mainloop.cpp +++ b/src/vist/event/mainloop.cpp @@ -22,6 +22,7 @@ #include "mainloop.hpp" #include +#include #include #include @@ -36,7 +37,7 @@ Mainloop::Mainloop() : stopped(false) { if (epollFd == -1) - throw std::runtime_error("Failed to create epoll instance."); + THROW(ErrCode::RuntimeError) << "Failed to create epoll instance."; } Mainloop::~Mainloop() @@ -49,7 +50,7 @@ void Mainloop::addHandler(const int fd, OnEvent&& onEvent, OnError&& onError) std::lock_guard lock(mutex); if (this->listener.find(fd) != this->listener.end()) - throw std::runtime_error("Event is already registered."); + THROW(ErrCode::RuntimeError) << "Event is already registered."; ::epoll_event event; std::memset(&event, 0, sizeof(epoll_event)); @@ -58,7 +59,7 @@ void Mainloop::addHandler(const int fd, OnEvent&& onEvent, OnError&& onError) event.data.fd = fd; if (::epoll_ctl(this->epollFd, EPOLL_CTL_ADD, fd, &event) == -1) - throw std::runtime_error("Failed to add event source."); + THROW(ErrCode::RuntimeError) << "Failed to add event source."; auto onEventPtr = std::make_shared(onEvent); auto onErrorPtr = (onError != nullptr) ? std::make_shared(onError) : nullptr; diff --git a/src/vist/klass/functor.hpp b/src/vist/klass/functor.hpp index c9872fc..63cd9db 100644 --- a/src/vist/klass/functor.hpp +++ b/src/vist/klass/functor.hpp @@ -22,11 +22,11 @@ #pragma once #include +#include #include #include #include -#include #include namespace vist { @@ -139,7 +139,7 @@ template Functor make_functor(std::shared_ptr instance, R (K::* member)(Ps...)) { if (instance == nullptr) - throw std::invalid_argument("Instance can't be nullptr."); + THROW(ErrCode::LogicError) << "Instance can't be nullptr."; return Functor(instance, make_function(member)); } @@ -149,7 +149,7 @@ std::shared_ptr> make_functor_ptr(K* instance, R (K::* member)(Ps...)) { if (instance == nullptr) - throw std::invalid_argument("Instance can't be nullptr."); + THROW(ErrCode::LogicError) << "Instance can't be nullptr."; std::shared_ptr smartPtr(instance); return std::make_shared>(smartPtr, make_function(member)); @@ -160,7 +160,7 @@ std::shared_ptr> make_functor_ptr(std::shared_ptr instan R (K::* member)(Ps...)) { if (instance == nullptr) - throw std::invalid_argument("Instance can't be nullptr."); + THROW(ErrCode::LogicError) << "Instance can't be nullptr."; return std::make_shared>(instance, make_function(member)); } diff --git a/src/vist/rmi/server.cpp b/src/vist/rmi/server.cpp index 269fa9c..0206260 100644 --- a/src/vist/rmi/server.cpp +++ b/src/vist/rmi/server.cpp @@ -22,6 +22,7 @@ #include "server.hpp" +#include #include #include @@ -62,7 +63,7 @@ void Server::listen(const std::string& socketPath) void Server::onAccept(std::shared_ptr&& connection) { if (connection == nullptr) - throw std::invalid_argument("Wrong connection."); + THROW(ErrCode::LogicError) << "Wrong connection."; auto onRead = [this, connection]() { std::shared_ptr conn; @@ -71,7 +72,7 @@ void Server::onAccept(std::shared_ptr&& connection) auto iter = this->connectionMap.find(connection->getFd()); if (iter == this->connectionMap.end()) - throw std::runtime_error("Faild to find connection."); + THROW(ErrCode::RuntimeError) << "Faild to find connection."; conn = iter->second; @@ -98,14 +99,14 @@ void Server::onAccept(std::shared_ptr&& connection) void Server::onClose(const std::shared_ptr& connection) { if (connection == nullptr) - throw std::invalid_argument("Wrong connection."); + THROW(ErrCode::LogicError) << "Wrong connection."; { std::lock_guard lock(this->connectionMutex); auto iter = this->connectionMap.find(connection->getFd()); if (iter == this->connectionMap.end()) - throw std::runtime_error("Faild to find connection."); + THROW(ErrCode::RuntimeError) << "Faild to find connection."; this->mainloop.removeHandler(iter->first); INFO(VIST) << "Connection is closed. fd: " << iter->first; @@ -123,7 +124,7 @@ void Server::dispatch(const std::shared_ptr& connection) auto iter = this->functorMap.find(funcName); if (iter == this->functorMap.end()) - throw std::runtime_error("Faild to find function."); + THROW(ErrCode::RuntimeError) << "Faild to find function."; DEBUG(VIST) << "Remote method invokation: " << funcName; diff --git a/src/vist/sdk/policy-model.hpp b/src/vist/sdk/policy-model.hpp index 20a5229..7ecd69e 100644 --- a/src/vist/sdk/policy-model.hpp +++ b/src/vist/sdk/policy-model.hpp @@ -16,10 +16,11 @@ #pragma once +#include #include -#include #include +#include namespace vist { namespace policy { @@ -51,7 +52,7 @@ public: inline const PolicyValue& get() const { if (!ready) - throw std::runtime_error("Policy value should be set once before use."); + THROW(ErrCode::RuntimeError) << "Policy value should be set once before use."; return current; } diff --git a/src/vist/transport/socket.cpp b/src/vist/transport/socket.cpp index cb7bbc4..4040232 100644 --- a/src/vist/transport/socket.cpp +++ b/src/vist/transport/socket.cpp @@ -38,7 +38,7 @@ namespace { void set_cloexec(int fd) { if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) - throw std::runtime_error("Failed to set CLOSEXEC."); + THROW(ErrCode::RuntimeError) << "Failed to set CLOSEXEC."; } } // anonymous namespace @@ -50,11 +50,11 @@ Socket::Socket(int fd) noexcept : fd(fd) Socket::Socket(const std::string& path) { if (path.size() >= sizeof(::sockaddr_un::sun_path)) - throw std::invalid_argument("Socket path size is wrong."); + THROW(ErrCode::LogicError) << "Socket path size is wrong."; int fd = ::socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) - throw std::runtime_error("Failed to create socket."); + THROW(ErrCode::RuntimeError) << "Failed to create socket."; set_cloexec(fd); @@ -68,16 +68,16 @@ Socket::Socket(const std::string& path) struct stat buf; if (::stat(path.c_str(), &buf) == 0) if (::unlink(path.c_str()) == -1) - throw std::runtime_error("Failed to remove exist socket."); + THROW(ErrCode::RuntimeError) << "Failed to remove exist socket."; if (::bind(fd, reinterpret_cast<::sockaddr*>(&addr), sizeof(::sockaddr_un)) == -1) { ::close(fd); - throw std::runtime_error("Failed to bind."); + THROW(ErrCode::RuntimeError) << "Failed to bind."; } if (::listen(fd, MAX_BACKLOG_SIZE) == -1) { ::close(fd); - throw std::runtime_error("Failed to liten."); + THROW(ErrCode::RuntimeError) << "Failed to listen."; } this->fd = fd; @@ -109,7 +109,7 @@ Socket Socket::accept(void) const { int fd = ::accept(this->fd, nullptr, nullptr); if (fd == -1) - throw std::runtime_error("Failed to accept."); + THROW(ErrCode::RuntimeError) << "Failed to accept."; set_cloexec(fd); @@ -119,11 +119,11 @@ Socket Socket::accept(void) const Socket Socket::connect(const std::string& path) { if (path.size() >= sizeof(::sockaddr_un::sun_path)) - throw std::invalid_argument("Socket path size is wrong."); + THROW(ErrCode::LogicError) << "Socket path size is wrong."; int fd = ::socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) - throw std::runtime_error("Failed to create socket."); + THROW(ErrCode::RuntimeError) << "Failed to create socket."; set_cloexec(fd); @@ -136,7 +136,7 @@ Socket Socket::connect(const std::string& path) if (::connect(fd, reinterpret_cast<::sockaddr*>(&addr), sizeof(sockaddr_un)) == -1) { ::close(fd); - throw std::runtime_error("Failed to connect."); + THROW(ErrCode::RuntimeError) << "Failed to connect."; } return Socket(fd); diff --git a/src/vist/transport/socket.hpp b/src/vist/transport/socket.hpp index 69069f4..0f0d53b 100644 --- a/src/vist/transport/socket.hpp +++ b/src/vist/transport/socket.hpp @@ -22,11 +22,12 @@ #pragma once +#include + #include #include #include -#include #include namespace vist { @@ -73,7 +74,7 @@ void Socket::send(const T *buffer, const std::size_t size) const else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) continue; else - std::runtime_error("Failed to write."); + THROW(ErrCode::RuntimeError) << "Failed to write to socket."; } }