#include <aul_rpc_port.h>
#include <dlog.h>
+#include <algorithm>
+
#include "fdbroker-internal.h"
#ifdef LOG_TAG
return fd_list_;
}
+FdBroker::FdBroker(bool mock) : mock_(mock) {
+ FdBrokerManager::GetInst().Add(this);
+}
+
FdBroker::~FdBroker() {
Cancel();
}
void FdBroker::Cancel() {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
LOGI("FdBroker::Cancel!");
+ FdBrokerManager::GetInst().Remove(this);
+
if (cancellable_) {
LOGW("Cancel the send request");
g_cancellable_cancel(cancellable_);
GVariant *parameters, GDBusMethodInvocation *invocation,
gpointer user_data) {
FdBroker* broker = static_cast<FdBroker*>(user_data);
+ if (!FdBrokerManager::GetInst().Exist(broker)) {
+ LOGE("No such broker(%p)", broker);
+ return;
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(broker->mutex_);
int ret = -1;
char sender_appid[255];
int sender_pid;
const gchar *name_owner,
gpointer user_data) {
FdBroker* broker = static_cast<FdBroker*>(user_data);
+ if (!FdBrokerManager::GetInst().Exist(broker)) {
+ LOGE("No such broker(%p)", broker);
+ return;
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(broker->mutex_);
int pid = broker->GetSenderPid(connection, name_owner);
char owner_appid[255] = { 0, };
const gchar *name,
gpointer user_data) {
FdBroker* broker = static_cast<FdBroker*>(user_data);
+ if (!FdBrokerManager::GetInst().Exist(broker)) {
+ LOGE("No such broker(%p)", broker);
+ return;
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(broker->mutex_);
broker->watcher_->OnPortVanished(broker->watch_appid_,
broker->watch_port_name_);
}
void FdBroker::OnResultReceived(GObject* source_object,
GAsyncResult* res,
gpointer user_data) {
+ LOGW("OnResultReceived() : FdBroker(%p)", user_data);
GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(source_object);
GError* err = nullptr;
GDBusMessage* reply = g_dbus_connection_send_message_with_reply_finish(conn,
}
FdBroker* broker = static_cast<FdBroker*>(user_data);
- if (broker == nullptr) {
- LOGW("Null broker"); // LCOV_EXCL_LINE
- return; // LCOV_EXCL_LINE
+ if (!FdBrokerManager::GetInst().Exist(broker)) {
+ LOGE("No such FdBroker(%p)", broker);
+ return;
}
+
+ std::lock_guard<std::recursive_mutex> lock(broker->mutex_);
IEventWatcher* watcher = broker->watcher_;
if (err) {
LOGD("[Reply : %d]", ret);
}
+FdBrokerManager& FdBrokerManager::GetInst() {
+ static FdBrokerManager inst;
+ return inst;
+}
+
+void FdBrokerManager::Add(FdBroker* broker) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ brokers_.push_back(broker);
+}
+
+void FdBrokerManager::Remove(FdBroker* broker) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ brokers_.remove(broker);
+}
+
+bool FdBrokerManager::Exist(FdBroker* broker) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ auto iter = std::find(brokers_.begin(), brokers_.end(), broker);
+ if (iter != brokers_.end())
+ return true;
+
+ return false;
+}
+
} // namespace internal
} // namespace rpc_port
#include <gio/gunixfdlist.h>
#include <glib-unix.h>
-#include <string>
#include <map>
#include <memory>
+#include <mutex>
+#include <string>
+#include <thread>
+#include <list>
#include "ac-internal.h"
#include "rpc-port.h"
bool cancel = false) = 0;
};
- explicit FdBroker(bool mock = false) : mock_(mock) {}
+ explicit FdBroker(bool mock = false);
~FdBroker();
static void Dispose() {
std::string watch_appid_;
std::string watch_port_name_;
GCancellable* cancellable_ = nullptr;
+ mutable std::recursive_mutex mutex_;
+};
+
+class FdBrokerManager {
+ private:
+ FdBrokerManager() = default;
+ ~FdBrokerManager() = default;
+
+ public:
+ static FdBrokerManager& GetInst();
+ void Add(FdBroker* broker);
+ void Remove(FdBroker* broker);
+ bool Exist(FdBroker* broker);
+
+ private:
+ std::list<FdBroker*> brokers_;
+ mutable std::recursive_mutex mutex_;
};
} // namespace internal