|
@@ -15,6 +15,7 @@
|
|
|
#include <atomic>
|
|
#include <atomic>
|
|
|
#include <condition_variable>
|
|
#include <condition_variable>
|
|
|
#include <coroutine>
|
|
#include <coroutine>
|
|
|
|
|
+#include <fstream>
|
|
|
#include <map>
|
|
#include <map>
|
|
|
#include <thread>
|
|
#include <thread>
|
|
|
|
|
|
|
@@ -85,6 +86,7 @@ namespace sophiar {
|
|
|
spin_lock mu;
|
|
spin_lock mu;
|
|
|
callback_token_type cb_token;
|
|
callback_token_type cb_token;
|
|
|
attach_token_type bind_token;
|
|
attach_token_type bind_token;
|
|
|
|
|
+ bool disposal = false;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
std::map<std::string, variable_store_info> variable_pool;
|
|
std::map<std::string, variable_store_info> variable_pool;
|
|
@@ -219,8 +221,15 @@ namespace sophiar {
|
|
|
|
|
|
|
|
std::any query_variable(const std::string &name) {
|
|
std::any query_variable(const std::string &name) {
|
|
|
auto store = get_variable_store(name);
|
|
auto store = get_variable_store(name);
|
|
|
- auto lock = std::lock_guard{store->mu};
|
|
|
|
|
- return store->value;
|
|
|
|
|
|
|
+ std::any ret;
|
|
|
|
|
+ {
|
|
|
|
|
+ auto lock = std::lock_guard{store->mu};
|
|
|
|
|
+ ret = store->value;
|
|
|
|
|
+ if (store->disposal) {
|
|
|
|
|
+ store->value = {};
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void update_variable(const std::string &name, const std::any &value) {
|
|
void update_variable(const std::string &name, const std::any &value) {
|
|
@@ -231,12 +240,13 @@ namespace sophiar {
|
|
|
LOOP_BASIC_VAR_TYPE(
|
|
LOOP_BASIC_VAR_TYPE(
|
|
|
{
|
|
{
|
|
|
using ValueType = decltype(real_ptr->value);
|
|
using ValueType = decltype(real_ptr->value);
|
|
|
|
|
+ using ObjType = std::remove_cvref_t<decltype(*real_ptr)>;
|
|
|
if (!value.has_value()) [[unlikely]] {
|
|
if (!value.has_value()) [[unlikely]] {
|
|
|
real_ptr = nullptr;
|
|
real_ptr = nullptr;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
if (real_ptr == nullptr) [[unlikely]] {
|
|
if (real_ptr == nullptr) [[unlikely]] {
|
|
|
- real_ptr = real_ptr->new_instance();
|
|
|
|
|
|
|
+ real_ptr = ObjType::new_instance();
|
|
|
}
|
|
}
|
|
|
real_ptr->value = std::any_cast<ValueType>(value);
|
|
real_ptr->value = std::any_cast<ValueType>(value);
|
|
|
return;
|
|
return;
|
|
@@ -244,6 +254,11 @@ namespace sophiar {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ void mark_variable_disposal(const std::string &name) {
|
|
|
|
|
+ auto store = get_variable_store(name);
|
|
|
|
|
+ store->disposal = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
local_connection::local_connection()
|
|
local_connection::local_connection()
|
|
@@ -287,4 +302,21 @@ namespace sophiar {
|
|
|
pimpl->update_variable(name, value);
|
|
pimpl->update_variable(name, value);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ void local_connection::mark_variable_disposal(const std::string &name) {
|
|
|
|
|
+ pimpl->mark_variable_disposal(name);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void run_sophiar(const std::string &config_path) {
|
|
|
|
|
+ auto config_file = std::ifstream{config_path};
|
|
|
|
|
+ assert(config_file.is_open());
|
|
|
|
|
+ auto config = nlohmann::json::parse(config_file);
|
|
|
|
|
+ auto ok = initialize(config);
|
|
|
|
|
+ assert(ok);
|
|
|
|
|
+ global_context->run();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void stop_sophiar() {
|
|
|
|
|
+ global_context->stop();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|