int FdBroker::DBusMock::Watch(FdBroker::IEventWatcher* watcher,
const std::string& target_appid,
const std::string& port_name) {
- watcher->OnPortAppeared(target_appid, port_name);
+ watcher->OnPortAppeared();
return 0;
}
// LCOV_EXCL_STOP
(*fds)[0] = main_sock_pair.Detach(SocketPair::SENDER);
(*fds)[1] = delegate_sock_pair.Detach(SocketPair::SENDER);
- watcher_->OnPortConnected(watch_appid_, watch_port_name_);
+ watcher_->OnPortConnected();
return (*fds)[0];
// LCOV_EXCL_STOP
}
if (aul_app_get_appid_bypid(pid, owner_appid, sizeof(owner_appid)) < 0) {
// LCOV_EXCL_START
LOGE("aul_app_get_appid_bypid failed %d", pid);
- broker->watcher_->OnPortRejected(owner_appid,
- RPC_PORT_ERROR_IO_ERROR);
+ broker->watcher_->OnPortRejected(RPC_PORT_ERROR_IO_ERROR);
return;
// LCOV_EXCL_STOP
}
if (broker->watch_appid_ != owner_appid) {
// LCOV_EXCL_START
LOGE("invalid appid %s", owner_appid);
- broker->watcher_->OnPortRejected(owner_appid,
- RPC_PORT_ERROR_IO_ERROR);
+ broker->watcher_->OnPortRejected(RPC_PORT_ERROR_IO_ERROR);
return;
// LCOV_EXCL_STOP
}
- broker->watcher_->OnPortAppeared(broker->watch_appid_,
- broker->watch_port_name_);
+ broker->watcher_->OnPortAppeared();
}
void FdBroker::OnNameVanished(GDBusConnection *connection,
return;
}
- broker->watcher_->OnPortVanished(broker->watch_appid_,
- broker->watch_port_name_);
+ broker->watcher_->OnPortVanished();
}
int FdBroker::Watch(IEventWatcher* ev, const std::string& target_appid,
if (err) {
// LCOV_EXCL_START
- watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_,
- true);
+ watcher->OnPortDisconnected(true);
g_error_free(err);
if (broker->cancellable_) {
LOGW("Cancel the send request");
if (reply_body == nullptr) {
// LCOV_EXCL_START
LOGE("g_dbus_message_get_body() is failed");
- watcher->OnPortDisconnected(broker->watch_appid_, broker->watch_port_name_);
+ watcher->OnPortDisconnected();
g_object_unref(reply);
return;
// LCOV_EXCL_STOP
g_object_unref(reply);
if (ret != 0) {
LOGE("Access Denied[sender_appid : %s]", broker->watch_appid_.c_str());
- watcher->OnPortRejected(broker->watch_appid_,
- RPC_PORT_ERROR_PERMISSION_DENIED);
+ watcher->OnPortRejected(RPC_PORT_ERROR_PERMISSION_DENIED);
return;
}
- watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_);
+ watcher->OnPortConnected();
LOGD("[Reply : %d]", ret);
}
broker->conn_data_ = nullptr;
broker->Cancel();
auto* watcher = broker->watcher_;
- watcher->OnPortRejected(broker->watch_appid_, RPC_PORT_ERROR_IO_ERROR);
+ watcher->OnPortRejected(RPC_PORT_ERROR_IO_ERROR);
return G_SOURCE_REMOVE;
}
#define _GNU_SOURCE
#endif
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <aul_svc.h>
#include <dlog.h>
+#include <sys/socket.h>
+#include <sys/types.h>
#include "debug-port-internal.hh"
#include "log-private.hh"
return TRUE;
}
-void Proxy::OnPortRejected(const std::string& appid, int error) {
+void Proxy::OnPortRejected(int error) {
+ _W("[__OnPortRejected__] endpoint(%s), error(%d)",
+ target_appid_.c_str(), error);
if (listener_ == nullptr)
return;
IEventListener* listener = listener_;
listener_ = nullptr;
- listener->OnRejected(appid, error);
+ listener->OnRejected(target_appid_, error);
}
-void Proxy::OnPortAppeared(const std::string& appid,
- const std::string& port_name) {
- _D("endpoint(%s), port_name(%s)", appid.c_str(), port_name.c_str());
-
+void Proxy::OnPortAppeared() {
+ _D("endpoint(%s), port_name(%s)", target_appid_.c_str(), port_name_.c_str());
if (listener_ == nullptr)
return;
fds_[0] = 0;
fds_[1] = 0;
- int r = fd_broker_->Send(appid, port_name, &fds_);
+ int r = fd_broker_->Send(real_appid_, port_name_, &fds_);
if (r <= 0) {
// LCOV_EXCL_START
IEventListener* listener = listener_;
listener_ = nullptr;
if (r == -EILLEGALACCESS)
- listener->OnRejected(appid, RPC_PORT_ERROR_PERMISSION_DENIED);
+ listener->OnRejected(target_appid_, RPC_PORT_ERROR_PERMISSION_DENIED);
else
- listener->OnDisconnected(appid);
+ listener->OnDisconnected(target_appid_);
return;
// LCOV_EXCL_STOP
}
_W("[__OnPortAppeared__] fds[0]: %d, fds[1]: %d", fds_[0], fds_[1]);
}
-void Proxy::OnPortVanished(const std::string& appid,
- const std::string& port_name) {
+void Proxy::OnPortVanished() {
_W("[__OnPortVanished__] endpoint(%s), port_name(%s)",
- appid.c_str(), port_name.c_str());
+ target_appid_.c_str(), port_name_.c_str());
}
-void Proxy::OnPortConnected(const std::string& appid,
- const std::string& port_name) {
+void Proxy::OnPortConnected() {
_W("[__OnPortConnected__] endpoint(%s), port_name(%s)",
- appid.c_str(), port_name.c_str());
+ target_appid_.c_str(), port_name_.c_str());
if (!listener_) {
_W("listener is null"); // LCOV_EXCL_LINE
return; // LCOV_EXCL_LINE
}
- main_port_.reset(new ProxyPort(this, fds_[0], appid, false));
- delegate_port_.reset(new ProxyPort(this, fds_[1], appid));
- listener_->OnConnected(appid, main_port_.get());
- DebugPort::GetInst().AddSession(port_name, appid, fds_[0], fds_[1]);
+ main_port_.reset(new ProxyPort(this, fds_[0], target_appid_, false));
+ delegate_port_.reset(new ProxyPort(this, fds_[1], target_appid_));
+ listener_->OnConnected(target_appid_, main_port_.get());
+ DebugPort::GetInst().AddSession(port_name_, target_appid_, fds_[0], fds_[1]);
}
// LCOV_EXCL_START
-void Proxy::OnPortDisconnected(const std::string& appid,
- const std::string& port_name, bool cancel) {
+void Proxy::OnPortDisconnected(bool cancel) {
_W("[__OnPortDisconnected__] endporint(%s), port_name(%s)",
- appid.c_str(), port_name.c_str());
+ target_appid_.c_str(), port_name_.c_str());
if (cancel) {
close(fds_[0]);
IEventListener* listener = listener_;
listener_ = nullptr;
- listener->OnDisconnected(appid);
+ listener->OnDisconnected(target_appid_);
DebugPort::GetInst().RemoveSession(fds_[0]);
}
// LCOV_EXCL_STOP
listener_ = ev;
target_appid_ = std::move(appid);
port_name_ = std::move(port_name);
+ SetRealAppId(target_appid_);
- int r = fd_broker_->Watch(this, target_appid_, port_name_);
+ int r = fd_broker_->Watch(this, real_appid_, port_name_);
if (r < 0) {
// LCOV_EXCL_START
listener_ = nullptr;
listener_ = ev;
target_appid_ = std::move(appid);
port_name_ = std::move(port_name);
+ SetRealAppId(target_appid_);
- int ret = fd_broker_->Prepare(target_appid_, port_name_);
+ int ret = fd_broker_->Prepare(real_appid_, port_name_);
if (ret < 0) {
listener_ = nullptr;
if (ret == -EILLEGALACCESS)
fds_[0] = 0;
fds_[1] = 0;
- ret = fd_broker_->SendSync(target_appid_, port_name_, &fds_);
+ ret = fd_broker_->SendSync(real_appid_, port_name_, &fds_);
if (ret <= 0) {
listener_ = nullptr;
if (ret == -EILLEGALACCESS)
main_port_.reset(new ProxyPort(this, fds_[0], target_appid_, false));
delegate_port_.reset(new ProxyPort(this, fds_[1], target_appid_));
listener_->OnConnected(target_appid_, main_port_.get());
- DebugPort::GetInst().AddSession(port_name, appid, fds_[0], fds_[1]);
+ DebugPort::GetInst().AddSession(port_name, target_appid_, fds_[0], fds_[1]);
return RPC_PORT_ERROR_NONE;
}
// LCOV_EXCL_STOP
+void Proxy::SetRealAppId(const std::string& alias_appid) {
+ if (!real_appid_.empty())
+ return;
+
+ char* appid = nullptr;
+ int ret = aul_svc_get_appid_by_alias_appid(alias_appid.c_str(), &appid);
+ if (ret != AUL_SVC_RET_OK) {
+ real_appid_ = alias_appid;
+ return;
+ }
+
+ std::unique_ptr<char, decltype(std::free)*> appid_ptr(appid, std::free);
+ real_appid_ = std::string(appid);
+ _W("alias_appid(%s), real_appid(%s)", alias_appid.c_str(), appid);
+}
+
Proxy::ProxyPort::ProxyPort(Proxy* parent, int fd, const std::string& id,
bool receive) : Port(fd, id), parent_(parent) {
Watch(receive);
static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond,
gpointer data);
static gboolean DbusNameTimeout(gpointer user_data);
- void OnPortAppeared(const std::string& appid,
- const std::string& port_name) override;
- void OnPortVanished(const std::string& appid,
- const std::string& port_name) override;
- void OnPortRejected(const std::string& appid,
- int error) override;
- void OnPortConnected(const std::string& appid,
- const std::string& port_name) override;
- void OnPortDisconnected(const std::string& appid,
- const std::string& port_name,
- bool cancel = false) override;
+ void OnPortAppeared() override;
+ void OnPortVanished() override;
+ void OnPortRejected(int error) override;
+ void OnPortConnected() override;
+ void OnPortDisconnected(bool cancel = false) override;
+ void SetRealAppId(const std::string& alias_appid);
private:
std::string port_name_;
IEventListener* listener_ = nullptr;
std::shared_ptr<FdBroker> fd_broker_;
std::string target_appid_;
+ std::string real_appid_;
int fds_[2];
guint conn_timer_ = 0;
};