30namespace RobotRaconteur
51class Callback :
private boost::noncopyable
55 std::string m_MemberName;
58 Callback(boost::string_ref name) { m_MemberName = RR_MOVE(name.to_string()); }
60 virtual ~Callback() {}
122 virtual void Shutdown() {}
126class CallbackClient :
public Callback<T>
129 CallbackClient(boost::string_ref name) : Callback<T>(name) {}
131 RR_OVIRTUAL ~CallbackClient() RR_OVERRIDE {}
135 boost::mutex function_lock;
140 boost::mutex::scoped_lock lock(function_lock);
142 throw InvalidOperationException(
"Callback function not set");
145 RR_OVIRTUAL
void SetFunction(T value) RR_OVERRIDE
147 boost::mutex::scoped_lock lock(function_lock);
151 RR_OVIRTUAL T GetClientFunction(
const RR_SHARED_PTR<Endpoint>& e) RR_OVERRIDE
154 throw InvalidOperationException(
"Invalid for client side of callback");
157 RR_OVIRTUAL T GetClientFunction(uint32_t e) RR_OVERRIDE
160 throw InvalidOperationException(
"Invalid for client side of callback");
163 RR_OVIRTUAL
void Shutdown() RR_OVERRIDE
165 boost::mutex::scoped_lock lock(function_lock);
170class ROBOTRACONTEUR_CORE_API ServiceSkel;
172class ROBOTRACONTEUR_CORE_API CallbackServerBase
176 virtual ~CallbackServerBase() {}
179 RR_WEAK_PTR<ServiceSkel> skel;
181 virtual RR_SHARED_PTR<void> GetClientFunction_internal(uint32_t e);
183 virtual std::string GetMemberName() = 0;
187class CallbackServer :
public Callback<T>,
public CallbackServerBase
190 CallbackServer(boost::string_ref name,
const RR_SHARED_PTR<ServiceSkel>& skel) : Callback<T>(name)
195 RR_OVIRTUAL ~CallbackServer() RR_OVERRIDE {}
197 RR_OVIRTUAL T
GetFunction() RR_OVERRIDE {
throw InvalidOperationException(
"Invalid for server side of callback"); }
198 RR_OVIRTUAL
void SetFunction(T value) RR_OVERRIDE
201 throw InvalidOperationException(
"Invalid for server side of callback");
204 RR_OVIRTUAL T GetClientFunction(
const RR_SHARED_PTR<Endpoint>& e) RR_OVERRIDE
207 return GetClientFunction(e->GetLocalEndpoint());
210 RR_OVIRTUAL T GetClientFunction(uint32_t e) RR_OVERRIDE
212 RR_SHARED_PTR<ServiceSkel> s = skel.lock();
214 throw InvalidOperationException(
"Callback server has been closed");
215 return *RR_STATIC_POINTER_CAST<T>(s->GetCallbackFunction(e, GetMemberName()));
220 RR_OVIRTUAL
void Shutdown() RR_OVERRIDE {}
223#ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
boost::shared_ptr< Callback< T > > CallbackPtr
Convenience alias for Callback shared_ptr.
Definition CallbackMember.h:226
boost::shared_ptr< const Callback< T > > CallbackConstPtr
Convenience alias for Callback const shared_ptr.
Definition CallbackMember.h:229
callback member type interface
Definition CallbackMember.h:52
virtual void SetFunction(T value)=0
Set the callback function reference on the client side.
virtual T GetClientFunction(uint32_t endpoint)=0
Get the proxy function to call the callback for the specified client on the service side.
virtual T GetClientFunction(const boost::shared_ptr< Endpoint > &endpoint)=0
Get the proxy function to call the callback for the specified client on the service side.
virtual T GetFunction()=0
Get the currently configured callback function on client side.
virtual std::string GetMemberName()
Get the member name of the callback.
Definition CallbackMember.h:120