更新接口
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
#include "adminive/amis.hpp"
|
||||
#include "adminive/synchronized.hpp"
|
||||
#include "adminive/lock.hpp"
|
||||
#include "adminive/managed.hpp"
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
namespace adminive {
|
||||
@@ -50,10 +50,6 @@ template <Json_Type Json>
|
||||
Http_Response<Json> make_http_error(int status, std::string message) {
|
||||
return Http_Response<Json>{status, make_http_result<Json>(status, std::move(message), json_object<Json>())};
|
||||
}
|
||||
enum class Resource_Lock_Scope {
|
||||
local,
|
||||
root
|
||||
};
|
||||
template <class Model>
|
||||
struct Resource_Transaction {
|
||||
using Prepare_Function = std::function<void(const Model&, const Request_Context&)>;
|
||||
@@ -69,7 +65,7 @@ Resource_Transaction<Model> make_resource_transaction(Function&& function) {
|
||||
result.commit = std::forward<Function>(function);
|
||||
return result;
|
||||
}
|
||||
template <class T, Json_Type Json, Basic_Lock Lock = std::shared_mutex>
|
||||
template <class T, Json_Type Json, Basic_Lock Lock = std::mutex>
|
||||
requires Writable_Adapted_Object<T> && std::copy_constructible<Object_Model_Type<T>>
|
||||
class Resource_Service {
|
||||
public:
|
||||
@@ -88,8 +84,8 @@ public:
|
||||
configure_raw_access(value, *owned_lock_);
|
||||
}
|
||||
}
|
||||
template <Basic_Lock Field_Lock>
|
||||
explicit Resource_Service(Synchronized_Value<Object, Lock, Field_Lock>& value, std::string path, Transaction transaction = {}) : path_(std::move(path)), transaction_(std::move(transaction)) {
|
||||
template <structive::Synchronization_Policy Policy>
|
||||
explicit Resource_Service(Managed_Value<Object, Policy>& value, std::string path, Transaction transaction = {}) : path_(std::move(path)), transaction_(std::move(transaction)) {
|
||||
read_access_ = [&value](const Read_Function& function) {
|
||||
value.read([&](const Object& object) {
|
||||
function(object);
|
||||
@@ -101,20 +97,16 @@ public:
|
||||
});
|
||||
};
|
||||
}
|
||||
template <class Root, Basic_Lock Field_Lock, auto... Members>
|
||||
requires (!std::is_const_v<Root>) && std::same_as<typename Synchronized_Field<Root, Lock, Field_Lock, Members...>::value_type, Object>
|
||||
explicit Resource_Service(Synchronized_Field<Root, Lock, Field_Lock, Members...> value, std::string path, Transaction transaction = {}, Resource_Lock_Scope lock_scope = Resource_Lock_Scope::local) : path_(std::move(path)), transaction_(std::move(transaction)) {
|
||||
if(lock_scope == Resource_Lock_Scope::root) {
|
||||
configure_raw_access(detail::Synchronized_Access::value(value), detail::Synchronized_Access::mutex(value));
|
||||
return;
|
||||
}
|
||||
template <class Managed, std::size_t Root_Index, auto... Members>
|
||||
requires std::same_as<typename Managed_Field<Managed, Root_Index, Members...>::value_type, Object> && (!std::is_const_v<Managed>)
|
||||
explicit Resource_Service(Managed_Field<Managed, Root_Index, Members...> value, std::string path, Transaction transaction = {}) : path_(std::move(path)), transaction_(std::move(transaction)) {
|
||||
read_access_ = [value](const Read_Function& function) {
|
||||
value.object_read([&](const Object& object) {
|
||||
value.read([&](const Object& object) {
|
||||
function(object);
|
||||
});
|
||||
};
|
||||
write_access_ = [value](const Write_Function& function) mutable {
|
||||
value.object_write([&](Object& object) {
|
||||
value.write([&](Object& object) {
|
||||
function(object);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user