Ice 3.7 C++11 API Reference
Loading...
Searching...
No Matches
ObserverHelper.h
Go to the documentation of this file.
1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#ifndef ICE_OBSERVERHELPER_H
6#define ICE_OBSERVERHELPER_H
7
9#include <Ice/ProxyF.h>
10#include <Ice/InstanceF.h>
11
12namespace IceInternal
13{
14
15template<typename T = Ice::Instrumentation::Observer> class ObserverHelperT
16{
17public:
18
19#ifdef ICE_CPP11_MAPPING
20 using TPtr = ::std::shared_ptr<T>;
21#else
22 typedef IceInternal::Handle<T> TPtr;
23#endif
24
25 ObserverHelperT()
26 {
27 }
28
29 ~ObserverHelperT()
30 {
31 if(_observer)
32 {
33 _observer->detach();
34 }
35 }
36
37 operator bool() const
38 {
39 return _observer != ICE_NULLPTR;
40 }
41
42 T* operator->() const
43 {
44 return _observer.get();
45 }
46
47 void
48 attach(const TPtr& o)
49 {
50 //
51 // Don't detach the existing observer. The observer is being
52 // replaced and the observed object is still being observed!
53 //
54 // if(_observer)
55 // {
56 // _observer->detach();
57 // }
58 _observer = o;
59 if(_observer)
60 {
61 _observer->attach();
62 }
63 }
64
65#ifdef ICE_CPP11_MAPPING
66 TPtr get() const
67 {
68 return _observer;
69 }
70#else
71 T* get() const
72 {
73 return _observer.get();
74 }
75#endif
76 void adopt(ObserverHelperT& other)
77 {
78 _observer = other._observer;
79 other._observer = 0;
80 }
81
82 void detach()
83 {
84 if(_observer)
85 {
86 _observer->detach();
87 _observer = 0;
88 }
89 }
90
91 void failed(const std::string& reason)
92 {
93 if(_observer)
94 {
95 _observer->failed(reason);
96 }
97 }
98
99protected:
100
101 TPtr _observer;
102};
103
104class ICE_API DispatchObserver : public ObserverHelperT<Ice::Instrumentation::DispatchObserver>
105{
106public:
107
108 void userException()
109 {
110 if(_observer)
111 {
112 _observer->userException();
113 }
114 }
115
116 void reply(Ice::Int size)
117 {
118 if(_observer)
119 {
120 _observer->reply(size);
121 }
122 }
123};
124
125class ICE_API InvocationObserver : public ObserverHelperT<Ice::Instrumentation::InvocationObserver>
126{
127public:
128
129 InvocationObserver(const Ice::ObjectPrxPtr&, const std::string&, const Ice::Context&);
130 InvocationObserver(Instance*, const std::string&);
131 InvocationObserver()
132 {
133 }
134
135 void attach(const Ice::ObjectPrxPtr&, const std::string&, const Ice::Context&);
136 void attach(Instance*, const std::string&);
137
138 void retried()
139 {
140 if(_observer)
141 {
142 _observer->retried();
143 }
144 }
145
146 ::Ice::Instrumentation::ChildInvocationObserverPtr
147 getRemoteObserver(const Ice::ConnectionInfoPtr& con, const Ice::EndpointPtr& endpt, int requestId, int size)
148 {
149 if(_observer)
150 {
151 return _observer->getRemoteObserver(con, endpt, requestId, size);
152 }
153 return ICE_NULLPTR;
154 }
155
156 ::Ice::Instrumentation::ChildInvocationObserverPtr
157 getCollocatedObserver(const Ice::ObjectAdapterPtr& adapter, int requestId, int size)
158 {
159 if(_observer)
160 {
161 return _observer->getCollocatedObserver(adapter, requestId, size);
162 }
163 return ICE_NULLPTR;
164 }
165
166 void
167 userException()
168 {
169 if(_observer)
170 {
171 _observer->userException();
172 }
173 }
174
175private:
176
177 using ObserverHelperT<Ice::Instrumentation::InvocationObserver>::attach;
178};
179
180}
181
182#endif
#define ICE_API
Definition Config.h:197
#define ICE_NULLPTR
Definition Config.h:362
int Int
The mapping for the Slice int type.
Definition Config.h:54
::std::map<::std::string, ::std::string > Context
A request context.
Definition Current.h:68