PDI 1.5.5

the PDI data interface

callbacks.h
1/*******************************************************************************
2 * Copyright (C) 2020 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of CEA nor the names of its contributors may be used to
13 * endorse or promote products derived from this software without specific
14 * prior written permission.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 ******************************************************************************/
24
25#ifndef PDI_CALLBACKS_H_
26#define PDI_CALLBACKS_H_
27
28#include <functional>
29#include <map>
30#include <list>
31#include <string>
32
33#include "pdi/pdi_fwd.h"
34#include "pdi/ref_any.h"
35
36namespace PDI {
37
38class PDI_EXPORT Callbacks
39{
40
42 Context& m_context;
43
49 std::list<std::function<void()>> m_init_callbacks;
50
56 std::list<std::function<void(const std::string&, Ref)>> m_data_callbacks;
57
63 std::multimap<std::string, std::function<void(const std::string&, Ref)>> m_named_data_callbacks;
64
70 std::list<std::function<void(const std::string&, Ref)>> m_data_remove_callbacks;
71
77 std::multimap<std::string, std::function<void(const std::string&, Ref)>> m_named_data_remove_callbacks;
78
84 std::list<std::function<void(const std::string&)>> m_event_callbacks;
85
91 std::multimap<std::string, std::function<void(const std::string&)>> m_named_event_callbacks;
92
98 std::list<std::function<void(const std::string&)>> m_empty_desc_access_callbacks;
99
105 std::multimap<std::string, std::function<void(const std::string&)>> m_named_empty_desc_access_callbacks;
106
107public:
108
110
117 std::function<void()> add_init_callback(const std::function<void()>& callback);
118
126 std::function<void()> add_data_callback(const std::function<void(const std::string&, Ref)>& callback, const std::string& name = {});
127
135 std::function<void()> add_data_remove_callback(const std::function<void(const std::string&, Ref)>& callback, const std::string& name = {});
136
144 std::function<void()> add_event_callback(const std::function<void(const std::string&)>& callback, const std::string& name = {});
145
153 std::function<void()> add_empty_desc_access_callback(const std::function<void(const std::string&)>& callback, const std::string& name = {});
154
157
162 void call_data_callbacks(const std::string& name, Ref ref) const;
163
168 void call_data_remove_callbacks(const std::string& name, Ref ref) const;
169
173 void call_event_callbacks(const std::string& name) const;
174
178 void call_empty_desc_access_callbacks(const std::string& name) const;
179
180};
181
182} // namespace PDI
183
184
185#endif //PDI_CALLBACKS_H_
Definition: callbacks.h:39
std::function< void()> add_init_callback(const std::function< void()> &callback)
Adds new init callback to context.
std::function< void()> add_data_callback(const std::function< void(const std::string &, Ref)> &callback, const std::string &name={})
Adds new data callback to context.
std::function< void()> add_data_remove_callback(const std::function< void(const std::string &, Ref)> &callback, const std::string &name={})
Adds new data callback to context.
std::function< void()> add_event_callback(const std::function< void(const std::string &)> &callback, const std::string &name={})
Adds new event callback to context.
void call_data_remove_callbacks(const std::string &name, Ref ref) const
Calls data remove callbacks.
void call_empty_desc_access_callbacks(const std::string &name) const
Calls empty desc callbacks.
Callbacks(Context &ctx)
void call_event_callbacks(const std::string &name) const
Calls event callbacks.
void call_data_callbacks(const std::string &name, Ref ref) const
Calls data callbacks.
std::function< void()> add_empty_desc_access_callback(const std::function< void(const std::string &)> &callback, const std::string &name={})
Adds new empty desc access callback to context.
void call_init_callbacks() const
Calls init callbacks.
Definition: context.h:45
A dynamically typed reference to data with automatic memory management and read/write locking semanti...
Definition: ref_any.h:273
Definition: array_datatype.h:38