RTI Routing Service Version 7.2.0
ShutdownHookForwarder.hpp
1/*
2 * (c) Copyright, Real-Time Innovations, 2017.
3 * All rights reserved.
4 *
5 * No duplications, whole or partial, manual or electronic, may be made
6 * without express written permission. Any such copies, or
7 * revisions thereof, must display this notice unaltered.
8 * This code contains trade secrets of Real-Time Innovations, Inc.
9 */
10
11#ifndef RTI_ROUTING_SHUTDOWN_HOOK_HPP_
12#define RTI_ROUTING_SHUTDOWN_HOOK_HPP_
13
14
15#include "routingservice/routingservice_service.h"
16
17namespace rti { namespace routing { namespace detail {
18
19class AbstractShutdownHookForwarder {
20public:
21
22 AbstractShutdownHookForwarder()
23 {
24 native_.on_shutdown = on_shutdown_forwarder;
25 native_.shutdown_hook_data = this;
26 }
27
28 virtual ~AbstractShutdownHookForwarder()
29 {
30 }
31
32 virtual void on_shutdown()
33 {
34 }
35
36 static void on_shutdown_forwarder(void *hook_data)
37 {
38 AbstractShutdownHookForwarder *self =
39 static_cast<AbstractShutdownHookForwarder*>(hook_data);
40 try {
41 self->on_shutdown();
42 } catch(...) {}
43 }
44
45
46 const RTI_RoutingServiceRemoteShutdownHook* native() const
47 {
48 return &native_;
49 }
50
51private:
52 RTI_RoutingServiceRemoteShutdownHook native_;
53};
54
55template<typename HookFunc>
56class ShutdownHookForwarder : public AbstractShutdownHookForwarder {
57public:
58 ShutdownHookForwarder(HookFunc& shutdown_hook)
59 : shutdown_hook_(shutdown_hook)
60 {
61
62 }
63
64 void on_shutdown()
65 {
66 shutdown_hook_();
67 };
68
69private:
70 HookFunc& shutdown_hook_;
71};
72
73}
74
75} }
76
77
78#endif /* RTI_ROUTING_SHUTDOWN_HOOK_HPP_ */
79