return dm;
}
+// LCOV_EXCL_START
void FdBroker::DBusConnectionManager::Dispose() {
if (!disposed_)
Fini();
}
+// LCOV_EXCL_STOP
GDBusConnection* FdBroker::DBusConnectionManager::GetConnection() {
return gdbus_conn_;
gdbus_conn_ = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
if (gdbus_conn_ == nullptr) {
+ // LCOV_EXCL_START
if (error != nullptr) {
LOGE("Failed to get dbus [%s]", error->message);
g_error_free(error);
}
return;
+ // LCOV_EXCL_STOP
}
disposed_ = false;
disposed_ = true;
}
+// LCOV_EXCL_START
FdBroker::DBusMock& FdBroker::DBusMock::GetInst() {
static DBusMock mock;
return mock;
}
+// LCOV_EXCL_STOP
+// LCOV_EXCL_START
int FdBroker::DBusMock::Send(const std::string& sender,
const std::string& port, int fds[2]) {
if (port == "wrong_port")
ports_[port]->OnFdReceived(sender, fds);
return 0;
}
+// LCOV_EXCL_STOP
+// LCOV_EXCL_START
int FdBroker::DBusMock::AddListener(const std::string& port,
FdBroker::IEventListener* listener) {
if (ports_.find(port) != ports_.end())
ports_[port] = listener;
return 0;
}
+// LCOV_EXCL_STOP
+// LCOV_EXCL_START
int FdBroker::DBusMock::Watch(FdBroker::IEventWatcher* watcher,
const std::string& target_appid,
const std::string& port_name) {
watcher->OnPortAppeared(target_appid, port_name);
return 0;
}
+// LCOV_EXCL_STOP
+// LCOV_EXCL_START
void FdBroker::DBusMock::Dispose() {
ports_.clear();
}
+// LCOV_EXCL_STOP
FdBroker::SocketPair::SocketPair(bool mock)
: mock_(mock) {
int FdBroker::SocketPair::Request(const std::string& target_appid,
const std::string& port_name) {
if (mock_) {
- return socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, socks_);
+ return socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, socks_); // LCOV_EXCL_LINE
}
if (aul_rpc_port_create_socket_pair(target_appid.c_str(),
port_name.c_str(), &socks_) != AUL_R_OK) {
- LOGE("error create socket pair");
- return -1;
+ LOGE("error create socket pair"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
return 0;
close(fd);
if (err != NULL) {
- LOGE("g_unix_fd_list_append [%s]", err->message);
- g_error_free(err);
- return -1;
+ LOGE("g_unix_fd_list_append [%s]", err->message); // LCOV_EXCL_LINE
+ g_error_free(err); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
return 0;
}
if (mock_) {
- DBusMock::GetInst().Dispose();
+ DBusMock::GetInst().Dispose(); // LCOV_EXCL_LINE
}
}
if (!mock_ && aul_app_get_appid_bypid(getpid(),
sender_appid, sizeof(sender_appid)) < 0) {
- LOGE("Can't get appid");
- return -1;
+ LOGE("Can't get appid"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
if (main_sock_pair.Request(target_appid, port_name) != 0)
return -1;
if (mock_) {
+ // LCOV_EXCL_START
int send_fds[2];
send_fds[0] = main_sock_pair.Detach(SocketPair::RECEIVER);
send_fds[1] = delegate_sock_pair.Detach(SocketPair::RECEIVER);
(*fds)[1] = delegate_sock_pair.Detach(SocketPair::SENDER);
watcher_->OnPortConnected(watch_appid_, watch_port_name_);
return (*fds)[0];
+ // LCOV_EXCL_STOP
}
if (fd_list.Add(main_sock_pair.Detach(SocketPair::RECEIVER)) != 0)
RPC_PORT_OBJECT_PATH,
interface_name.c_str(), "send_message");
if (!msg) {
- LOGE("Can't allocate new method call");
- return -1;
+ LOGE("Can't allocate new method call"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
if (cancellable_) {
- g_cancellable_cancel(cancellable_);
- g_object_unref(cancellable_);
+ g_cancellable_cancel(cancellable_); // LCOV_EXCL_LINE
+ g_object_unref(cancellable_); // LCOV_EXCL_LINE
}
cancellable_ = g_cancellable_new();
if (!cancellable_) {
- LOGE("Failed to create GCancellable");
- g_object_unref(msg);
- return -1;
+ LOGE("Failed to create GCancellable"); // LCOV_EXCL_LINE
+ g_object_unref(msg); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
g_dbus_message_set_unix_fd_list(msg, fd_list.GetRaw());
return (*fds)[0];
}
+// LCOV_EXCL_START
int FdBroker::SendSync(const std::string& target_appid,
const std::string& port_name,
int (*fds)[2]) {
return (*fds)[0];
}
+// LCOV_EXCL_STOP
void FdBroker::ReceiveMessage(const char* sender_appid,
GDBusMethodInvocation* invocation) {
fd_list = g_dbus_message_get_unix_fd_list(msg);
if (fd_list == nullptr)
- return;
+ return; // LCOV_EXCL_LINE
returned_fds = g_unix_fd_list_steal_fds(fd_list, &fd_len);
if (returned_fds == nullptr || fd_len != 2) {
- LOGE("fail to get fds. fd_len(%d)", fd_len);
- return;
+ LOGE("fail to get fds. fd_len(%d)", fd_len); // LCOV_EXCL_LINE
+ return; // LCOV_EXCL_LINE
}
listener_->OnFdReceived(sender_appid, returned_fds);
&error);
if (error) {
- LOGE("RequestName fail : %s", error->message);
- g_error_free(error);
- return -1;
+ LOGE("RequestName fail : %s", error->message); // LCOV_EXCL_LINE
+ g_error_free(error); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
if (result == nullptr) {
- LOGE("fail to get name NULL");
- return -1;
+ LOGE("fail to get name NULL"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
g_variant_get(result, "(u)", &owner_id);
if (owner_id == 0) {
- LOGE("Acquiring the own name is failed");
- g_variant_unref(result);
- return -1;
+ LOGE("Acquiring the own name is failed"); // LCOV_EXCL_LINE
+ g_variant_unref(result); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
LOGD("Acquiring the own name : %d", owner_id);
"/org/freedesktop/DBus", "org.freedesktop.DBus",
"GetConnectionUnixProcessID");
if (!msg) {
- LOGE("Can't allocate new method call");
- goto out;
+ LOGE("Can't allocate new method call"); // LCOV_EXCL_LINE
+ goto out; // LCOV_EXCL_LINE
}
g_dbus_message_set_body(msg, g_variant_new("(s)", sender));
G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
if (!reply) {
+ // LCOV_EXCL_START
if (err != NULL) {
LOGE("Failed to get pid [%s]", err->message);
g_error_free(err);
}
goto out;
+ // LCOV_EXCL_STOP
}
body = g_dbus_message_get_body(reply);
int FdBroker::Listen(IEventListener* ev, const std::string& port_name) {
if (listener_ != nullptr) {
- LOGE("listener_ is not NULL");
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ LOGE("listener_ is not NULL"); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_INVALID_PARAMETER; // LCOV_EXCL_LINE
}
if (ev == nullptr) {
- LOGE("ev is NULL");
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ LOGE("ev is NULL"); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_INVALID_PARAMETER; // LCOV_EXCL_LINE
}
if (mock_) {
+ // LCOV_EXCL_START
int ret = DBusMock::GetInst().AddListener(port_name, ev);
if (ret < 0)
return ret;
return RPC_PORT_ERROR_NONE;
+ // LCOV_EXCL_STOP
}
int ret = RegisterDbusInterface(port_name);
if (ret != 0) {
- LOGE("Failed to register dbus interface");
- return RPC_PORT_ERROR_IO_ERROR;
+ LOGE("Failed to register dbus interface"); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
}
listener_ = ev;
char owner_appid[255] = { 0, };
if (aul_app_get_appid_bypid(pid, owner_appid, sizeof(owner_appid)) < 0) {
- LOGE("aul_app_get_appid_bypid failed %d", pid);
- broker->watcher_->OnPortRejected(owner_appid);
- return;
+ LOGE("aul_app_get_appid_bypid failed %d", pid); // LCOV_EXCL_LINE
+ broker->watcher_->OnPortRejected(owner_appid); // LCOV_EXCL_LINE
+ return; // LCOV_EXCL_LINE
}
if (broker->watch_appid_ != owner_appid) {
- LOGE("invalid appid %s", owner_appid);
- broker->watcher_->OnPortRejected(owner_appid);
- return;
+ LOGE("invalid appid %s", owner_appid); // LCOV_EXCL_LINE
+ broker->watcher_->OnPortRejected(owner_appid); // LCOV_EXCL_LINE
+ return; // LCOV_EXCL_LINE
}
broker->watcher_->OnPortAppeared(broker->watch_appid_,
watch_port_name_ = port_name;
if (mock_) {
+ // LCOV_EXCL_START
ret = DBusMock::GetInst().Watch(ev, target_appid, port_name);
if (ret < 0)
return -1;
return 0;
+ // LCOV_EXCL_STOP
}
std::string interface_name = GetInterfaceName(target_appid, port_name);
if (watcher_id_ > 0) {
+ // LCOV_EXCL_START
g_bus_unwatch_name(watcher_id_);
LOGD("Retry to watch name. stub %s:%s",
target_appid.c_str(), port_name.c_str());
+ // LCOV_EXCL_STOP
}
watcher_id_ = g_bus_watch_name_on_connection(
this,
NULL);
if (watcher_id_ == 0) {
- LOGE("Failed to watch connection(%s)", interface_name.c_str());
- watcher_ = nullptr;
- return -1;
+ LOGE("Failed to watch connection(%s)", interface_name.c_str()); // LCOV_EXCL_LINE
+ watcher_ = nullptr; // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
return 0;
int ret = aul_rpc_port_prepare_stub(target_appid.c_str(),
port_name.c_str());
if (ret != AUL_R_OK) {
+ // LCOV_EXCL_START
LOGE("Failed to prepare stub %s:%s [ret : %d]",
target_appid.c_str(), port_name.c_str(), ret);
if (ret == AUL_R_EILLACC)
return -EILLEGALACCESS;
return ret;
+ // LCOV_EXCL_STOP
}
}
FdBroker* broker = static_cast<FdBroker*>(user_data);
if (broker == nullptr) {
- LOGW("Null broker");
- return;
+ LOGW("Null broker"); // LCOV_EXCL_LINE
+ return; // LCOV_EXCL_LINE
}
IEventWatcher* watcher = broker->watcher_;
if (err) {
+ // LCOV_EXCL_START
watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_,
true);
g_error_free(err);
broker->cancellable_ = nullptr;
}
return;
+ // LCOV_EXCL_STOP
}
if (reply == nullptr) {
- LOGW("Null reply");
- return;
+ LOGW("Null reply"); // LCOV_EXCL_LINE
+ return; // LCOV_EXCL_LINE
}
GVariant* reply_body = g_dbus_message_get_body(reply);
if (reply_body == nullptr) {
+ // LCOV_EXCL_START
LOGE("g_dbus_message_get_body() is failed");
watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_);
g_object_unref(reply);
return;
+ // LCOV_EXCL_STOP
}
int ret;
Proxy::~Proxy() {
LOGD("Proxy::~Proxy");
if (conn_timer_) {
- g_source_remove(conn_timer_);
- conn_timer_ = 0;
+ g_source_remove(conn_timer_); // LCOV_EXCL_LINE
+ conn_timer_ = 0; // LCOV_EXCL_LINE
}
}
fds_[1] = 0;
int r = fd_broker_.Send(appid, port_name, &fds_);
if (r <= 0) {
+ // LCOV_EXCL_START
IEventListener* listener = listener_;
listener_ = nullptr;
if (r == -EILLEGALACCESS)
else
listener->OnDisconnected(appid);
return;
+ // LCOV_EXCL_STOP
}
LOGW("[__OnPortAppeared__] fds[0]: %d, fds[1]: %d", fds_[0], fds_[1]);
LOGW("[__OnPortConnected__] endpoint(%s), port_name(%s)",
appid.c_str(), port_name.c_str());
if (!listener_) {
- LOGW("listener is null");
- return;
+ LOGW("listener is null"); // LCOV_EXCL_LINE
+ return; // LCOV_EXCL_LINE
}
main_port_.reset(new ProxyPort(this, fds_[0], appid, false));
listener_->OnConnected(appid, main_port_.get());
}
+// LCOV_EXCL_START
void Proxy::OnPortDisconnected(const std::string& appid,
const std::string& port_name, bool cancel) {
LOGW("[__OnPortDisconnected__] endporint(%s), port_name(%s)",
listener_ = nullptr;
listener->OnDisconnected(appid);
}
+// LCOV_EXCL_STOP
int Proxy::Connect(std::string appid, std::string port_name,
IEventListener* ev) {
return RPC_PORT_ERROR_INVALID_PARAMETER;
if (listener_ != nullptr) {
- LOGD("Already connected");
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ LOGD("Already connected"); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_INVALID_PARAMETER; // LCOV_EXCL_LINE
}
listener_ = ev;
port_name_ = std::move(port_name);
if (conn_timer_)
- g_source_remove(conn_timer_);
+ g_source_remove(conn_timer_); // LCOV_EXCL_LINE
conn_timer_ = g_timeout_add(10 * 1000, DbusNameTimeout, this);
int r = fd_broker_.Watch(this, target_appid_, port_name_);
if (r < 0) {
+ // LCOV_EXCL_START
g_source_remove(conn_timer_);
listener_ = nullptr;
if (r == -EILLEGALACCESS)
return RPC_PORT_ERROR_PERMISSION_DENIED;
return RPC_PORT_ERROR_IO_ERROR;
+ // LCOV_EXCL_STOP
}
return RPC_PORT_ERROR_NONE;
}
+// LCOV_EXCL_START
int Proxy::ConnectSync(std::string appid, std::string port_name,
IEventListener* ev) {
if (ev == nullptr)
return RPC_PORT_ERROR_NONE;
}
+// LCOV_EXCL_STOP
+// LCOV_EXCL_START
gboolean Proxy::DbusNameTimeout(gpointer user_data) {
Proxy* obj = static_cast<Proxy*>(user_data);
return G_SOURCE_REMOVE;
}
+// LCOV_EXCL_STOP
Proxy::ProxyPort::ProxyPort(Proxy* parent, int fd, const std::string& id,
bool receive) : Port(fd, id), parent_(parent) {
gioc_ = g_io_channel_unix_new(fd);
if (!gioc_) {
- LOGE("Error is %s", strerror_r(errno, buf, sizeof(buf)));
- return -1;
+ LOGE("Error is %s", strerror_r(errno, buf, sizeof(buf))); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
disconn_src_ = g_io_add_watch(gioc_,
(GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_NVAL),
Proxy::OnSocketDisconnected, parent_);
if (disconn_src_ == 0) {
+ // LCOV_EXCL_START
LOGE("Failed to add watch on socket");
g_io_channel_unref(gioc_);
gioc_ = nullptr;
return -1;
+ // LCOV_EXCL_STOP
}
if (!receive)
(GIOCondition)(G_IO_IN),
Proxy::OnDataReceived, parent_);
if (src_ == 0) {
+ // LCOV_EXCL_START
LOGE("Failed to add watch on socket");
g_source_remove(disconn_src_);
disconn_src_ = 0;
g_io_channel_unref(gioc_);
gioc_ = nullptr;
return -1;
+ // LCOV_EXCL_STOP
}
return 0;