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 {
40 using plugin_base_t::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
universal primitive of concurrent computation
Definition actor_base.h:47
base class for all actor plugins
Definition plugin_base.h:23
"lock" for external resources
Definition resources.h:39
static const std::type_index class_identity
Definition resources.h:43
const std::type_index & identity() const noexcept override
returns pointer, which uniquely identifiess plugin type