feisty meow concerns codebase 2.140
safe_callback.h
Go to the documentation of this file.
1#ifndef SAFE_CALLBACK_CLASS
2#define SAFE_CALLBACK_CLASS
3
4/*****************************************************************************\
5* *
6* Name : safe_callback *
7* Author : Chris Koeritz *
8* *
9*******************************************************************************
10* Copyright (c) 2001-$now By Author. This program is free software; you can *
11* redistribute it and/or modify it under the terms of the GNU General Public *
12* License as published by the Free Software Foundation; either version 2 of *
13* the License or (at your option) any later version. This is online at: *
14* http://www.fsf.org/copyleft/gpl.html *
15* Please send any updates to: fred@gruntose.com *
16\*****************************************************************************/
17
18#include <basis/astring.h>
19#include <basis/mutex.h>
20#include <basis/contracts.h>
21
22namespace processes {
23
24// forward.
25class callback_data_block;
26class global_live_objects;
27
29
68{
69public:
72
73 void end_availability();
75
79 virtual ~safe_callback();
81
85 DEFINE_CLASS_NAME("safe_callback");
86
87 bool decoupled() const { return _decoupled; }
89
96
113protected:
114 virtual void real_callback(callback_data_block &new_data) = 0;
116
119private:
120 bool _decoupled;
121 basis::mutex *_callback_lock;
122 void begin_availability();
124
126public:
127 global_live_objects &_invocables();
129
131};
132
134
136
142{
143public:
144 virtual ~callback_data_block();
145};
146
148
149} //namespace.
150
151#endif
152
a simple place-holder that anonymizes the type passed to the callback.
A reasonably easy way to make callbacks safe from shutdown ordering issues.
DEFINE_CLASS_NAME("safe_callback")
global_live_objects & _invocables()
provides access to the program-wide list of healthy callback objects.
bool invoke_callback(callback_data_block &new_data)
this function is invoked by a user of the safe_callback derived object.
bool decoupled() const
if true, then end_availability() was already invoked on the object.
virtual void real_callback(callback_data_block &new_data)=0
derived classes implement this to provide their callback functionality.
void end_availability()
prepares to shut down this object.
virtual ~safe_callback()
actually destroys the object.
safe_callback()
construction signifies that the callback is now in operation.