rotor
Event loop friendly C++ actor micro-framework
Loading...
Searching...
No Matches
resources.h
1#pragma once
2
3//
4// Copyright (c) 2019-2023 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "plugin_base.h"
10#include <vector>
11
12#if defined(_MSC_VER)
13#pragma warning(push)
14#pragma warning(disable : 4251)
15#endif
16
17namespace rotor::plugin {
18
19using resource_id_t = std::size_t;
20
39struct ROTOR_API resources_plugin_t : public plugin_base_t {
41
43 static const std::type_index class_identity;
44
45 const std::type_index &identity() const noexcept override;
46
47 void activate(actor_base_t *actor) noexcept override;
48 bool handle_init(message::init_request_t *message) noexcept override;
49 bool handle_shutdown(message::shutdown_request_t *message) noexcept override;
50
56 virtual void acquire(resource_id_t = 0) noexcept;
57
64 virtual bool release(resource_id_t = 0) noexcept;
65
71 virtual std::uint32_t has(resource_id_t = 0) noexcept;
72
74 virtual bool has_any() noexcept;
75
77 template <typename T> auto &access() noexcept;
78
79 private:
80 using Resources = std::vector<std::uint32_t>;
81 Resources resources;
82 bool configured = false;
83};
84
85} // namespace rotor::plugin
86
87#if defined(_MSC_VER)
88#pragma warning(pop)
89#endif
namespace for rotor core messages (which just transform payloads)
Definition messages.hpp:317
universal primitive of concurrent computation
Definition actor_base.h:47
plugin_base_t()=default
default plugin ctor
actor_base_t * actor
non-owning actor pointer
Definition plugin_base.h:179
"lock" for external resources
Definition resources.h:39
virtual bool release(resource_id_t=0) noexcept
decrements the resource counter (aka unlocks)
static const std::type_index class_identity
Definition resources.h:43
bool handle_shutdown(message::shutdown_request_t *message) noexcept override
polls plugin, whether it is done with shutdown
const std::type_index & identity() const noexcept override
returns pointer, which uniquely identifiess plugin type
virtual void acquire(resource_id_t=0) noexcept
increments the resource counter (aka locks)
plugin_base_t()=default
default plugin ctor
bool handle_init(message::init_request_t *message) noexcept override
polls plugin, whether it is done with initialization
virtual bool has_any() noexcept
returns true if there is any resource is locked
virtual std::uint32_t has(resource_id_t=0) noexcept
returns counter value for resource_id
auto & access() noexcept
generic non-public fields accessor
void activate(actor_base_t *actor) noexcept override
invoked by actor upon initialization.