bactria  0.0.1
The bactria library is a header-only C++14 library for profiling and tracing.
Context.hpp
Go to the documentation of this file.
1 /* Copyright 2021 Jan Stephan
2  *
3  * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
4  * the European Commission - subsequent versions of the EUPL (the “Licence”).
5  * You may not use this work except in compliance with the Licence.
6  * You may obtain a copy of the Licence at:
7  *
8  * http://ec.europa.eu/idabc/eupl.html
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the Licence is distributed on an “AS IS” basis, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * Licence permissions and limitations under the Licence.
14  */
15 
23 #pragma once
24 
26 #include <bactria/core/Plugin.hpp>
30 
31 #include <utility>
32 
33 namespace bactria
34 {
50  class Context final
51  {
52  public:
53  // The plugin handles are reference counted. Copying them around doesn't hurt.
54 
64  Context() = default;
65 
73  Context(Context const& other) noexcept = default;
74 
82  auto operator=(Context const& rhs) noexcept -> Context& = default;
83 
93  Context(Context&& other) noexcept
94  : m_metricsHandle{std::exchange(other.m_metricsHandle, plugin_handle_t{})}
95  , m_rangesHandle{std::exchange(other.m_rangesHandle, plugin_handle_t{})}
96  , m_reportsHandle{std::exchange(other.m_reportsHandle, plugin_handle_t{})}
97  {
98  }
99 
108  auto operator=(Context&& rhs) noexcept -> Context&
109  {
110  m_metricsHandle = std::exchange(rhs.m_metricsHandle, plugin_handle_t{});
111  m_rangesHandle = std::exchange(rhs.m_rangesHandle, plugin_handle_t{});
112  m_reportsHandle = std::exchange(rhs.m_reportsHandle, plugin_handle_t{});
113  return *this;
114  }
115 
126  {
127  /* At first glance, this seems wrong. However, on all supported platforms the plugin handle is reference
128  * counted (per process), so having multiple contexts loading / unloading the library is not a problem. */
130  unload_plugin(m_reportsHandle);
131 
133  unload_plugin(m_rangesHandle);
134 
136  unload_plugin(m_metricsHandle);
137  }
138 
139  private:
143  };
144 
146 } // namespace bactria
Plugin.hpp
bactria-internal handling of reports plugins.
Plugin.hpp
bactria-internal plugin handling.
bactria::metrics::plugin::activated
auto activated() -> bool
Checks for an active metrics plugin.
Definition: Plugin.hpp:58
bactria::Context::Context
Context()=default
The constructor.
bactria::Context::operator=
auto operator=(Context &&rhs) noexcept -> Context &
The move assignment operator.
Definition: Context.hpp:108
bactria::Context::Context
Context(Context &&other) noexcept
The move constructor.
Definition: Context.hpp:93
bactria::plugin_handle_t
system::plugin_handle_t plugin_handle_t
The platform-specific plugin handle type.
Definition: Plugin.hpp:41
bactria::Context::operator=
auto operator=(Context const &rhs) noexcept -> Context &=default
The copy assignment operator.
bactria::system::plugin_handle_t
void * plugin_handle_t
The POSIX-specific handle type.
Definition: POSIX.hpp:44
bactria::metrics::plugin::load
auto load() -> plugin_handle_t
Initializes the metrics plugin.
Definition: Plugin.hpp:199
bactria::unload_plugin
auto unload_plugin(plugin_handle_t handle) noexcept
Unloads the plugin.
Definition: Plugin.hpp:51
Plugin.hpp
bactria-internal handling of ranges plugins.
Plugin.hpp
bactria-internal handling of metrics plugins.
Activation.hpp
Plugin activation file.
bactria::Context
The context.
Definition: Context.hpp:50
bactria::Context::~Context
~Context()
The destructor.
Definition: Context.hpp:125