int (*fds)[2]) {
std::string interface_name = GetInterfaceName(target_appid, port_name);
GDBusMessage *msg;
- GDBusMessage *reply;
- GError *err = nullptr;
- GVariant *reply_body;
SocketPair main_sock_pair(mock_);
SocketPair delegate_sock_pair(mock_);
FdList fd_list;
char sender_appid[255];
- int ret;
if (!mock_ && aul_app_get_appid_bypid(getpid(),
sender_appid, sizeof(sender_appid)) < 0) {
}
g_dbus_message_set_unix_fd_list(msg, fd_list.GetRaw());
- reply = g_dbus_connection_send_message_with_reply_sync(
+ g_dbus_connection_send_message_with_reply(
DBusConnectionManager::GetInst().GetConnection(),
- msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 5000, nullptr, nullptr, &err);
- if (reply == nullptr) {
- LOGE("No reply. error = %s", err->message);
- g_error_free(err);
- g_object_unref(msg);
- return -1;
- }
-
- reply_body = g_dbus_message_get_body(reply);
- if (reply_body == nullptr) {
- LOGE("g_dbus_message_get_body() is failed");
- g_object_unref(msg);
- return -1;
- }
-
- g_variant_get(reply_body, "(i)", &ret);
-
- if (ret != 0) {
- LOGE("Access Denied[sender_appid : %s]", sender_appid);
- g_object_unref(msg);
- g_object_unref(reply);
- return -EILLEGALACCESS;
- }
-
- LOGD("[Reply : %d]", ret);
+ msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ 5000, NULL, NULL, OnResultReceived, this);
+ g_object_unref(msg);
(*fds)[0] = main_sock_pair.Detach(SocketPair::SENDER);
(*fds)[1] = delegate_sock_pair.Detach(SocketPair::SENDER);
- g_object_unref(msg);
return (*fds)[0];
}
return 0;
}
+void FdBroker::OnResultReceived(GObject* source_object,
+ GAsyncResult* res,
+ gpointer user_data) {
+ FdBroker* broker = static_cast<FdBroker*>(user_data);
+ IEventWatcher* watcher = broker->watcher_;
+ GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(source_object);
+ GError *err = nullptr;
+ GDBusMessage* reply = g_dbus_connection_send_message_with_reply_finish(conn,
+ res, &err);
+ if (reply == nullptr) {
+ LOGE("No reply. err(%s)", err ? err->message : "Unknown");
+ watcher->OnPortRejected(broker->watch_appid_);
+ g_error_free(err);
+ return;
+ }
+
+ GVariant* reply_body = g_dbus_message_get_body(reply);
+ if (reply_body == nullptr) {
+ LOGE("g_dbus_message_get_body() is failed");
+ watcher->OnPortRejected(broker->watch_appid_);
+ g_object_unref(reply);
+ return;
+ }
+
+ int ret;
+ g_variant_get(reply_body, "(i)", &ret);
+ g_object_unref(reply);
+ if (ret != 0) {
+ LOGE("Access Denied[sender_appid : %s]", broker->watch_appid_.c_str());
+ watcher->OnPortRejected(broker->watch_appid_);
+ return;
+ }
+
+ watcher->OnPortConnected(broker->watch_appid_, broker->watch_port_name_);
+ LOGD("[Reply : %d]", ret);
+}
+
} // namespace internal
} // namespace rpc_port
virtual void OnPortVanished(const std::string& appid,
const std::string& port_name) = 0;
virtual void OnPortRejected(const std::string& appid) = 0;
+ virtual void OnPortConnected(const std::string& appid,
+ const std::string& port_name) = 0;
};
explicit FdBroker(bool mock = false) : mock_(mock) {}
static void OnNameVanished(GDBusConnection *connection,
const gchar *name,
gpointer user_data);
+ static void OnResultReceived(GObject* source_object,
+ GAsyncResult* res,
+ gpointer user_data);
private:
IEventListener* listener_ = nullptr;
LOGW("[__OnPortAppeared__] fds[0]: %d, fds[1]: %d", fds[0], fds[1]);
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());
}
void Proxy::OnPortVanished(const std::string& appid,
appid.c_str(), port_name.c_str());
}
+void Proxy::OnPortConnected(const std::string& appid,
+ const std::string& port_name) {
+ LOGW("[__OnPortConnected__] endpoint(%s), port_name(%s)",
+ appid.c_str(), port_name.c_str());
+
+ listener_->OnConnected(appid, main_port_.get());
+}
+
int Proxy::Connect(std::string appid, std::string port_name,
IEventListener* ev) {
if (ev == nullptr)