return endpoint_;
}
+ void Disable() {
+ disabled_ = true;
+ }
+
+ bool IsDisabled() const {
+ return disabled_;
+ }
+
void Invoke(aul_app_com_result_e result, bundle* envelope) {
- if (cb_)
+ if (!disabled_ && cb_)
cb_(endpoint_.c_str(), result, envelope, user_data_);
}
private:
+ bool disabled_ = false;
std::string endpoint_;
app_com_cb cb_;
void* user_data_;
bool ExistConnection(const std::string& endpoint) {
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto& conn : conns_) {
- if (conn->GetEndpoint() == endpoint)
+ if (conn->GetEndpoint() == endpoint && !conn->IsDisabled())
return true;
}
bool ExistConnection(AppComConnection* conn) {
std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (conn->IsDisabled())
+ return false;
+
for (auto& i : conns_) {
if (i.get() == conn)
return true;
return false;
}
+ std::recursive_mutex& GetMutex() const {
+ return mutex_;
+ }
+
private:
std::list<std::unique_ptr<AppComConnection>> conns_;
mutable std::recursive_mutex mutex_;
return AUL_R_EINVAL;
}
+ std::lock_guard<std::recursive_mutex> lock(context.GetMutex());
+ conn->Disable();
std::string endpoint = conn->GetEndpoint();
- context.RemoveConnection(conn);
+ g_idle_add_full(G_PRIORITY_HIGH, [](gpointer user_data) -> gboolean {
+ auto* conn = static_cast<AppComConnection*>(user_data);
+ context.RemoveConnection(conn);
+ return G_SOURCE_REMOVE;
+ }, connection, nullptr);
if (context.ExistConnection(endpoint))
return AUL_R_OK;