29 #ifndef Pt_Remoting_RemoteProcedure_h
30 #define Pt_Remoting_RemoteProcedure_h
32 #include <Pt/Remoting/Api.h>
33 #include <Pt/Remoting/Client.h>
34 #include <Pt/SerializationContext.h>
35 #include <Pt/NonCopyable.h>
36 #include <Pt/Signal.h>
37 #include <Pt/String.h>
51 RemoteCall(
Client& client,
const std::string& name);
53 RemoteCall(
Client& client,
const char* name);
55 virtual ~RemoteCall();
64 {
return _client->isFailed(); }
73 virtual void onReady() = 0;
75 virtual void onReset() = 0;
77 virtual void onClear() = 0;
92 explicit Result(RemoteCall* call = 0)
96 _result =
new (_mem) R;
104 void init(RemoteCall* call)
113 return _call->isFailed();
137 _result =
new (_mem) R;
142 char _mem[
sizeof(R) ];
148 template <
typename R>
149 class RemoteProcedureBase :
public RemoteCall
152 RemoteProcedureBase(Client& client,
const std::string& name)
153 : RemoteCall(client, name)
160 ~RemoteProcedureBase()
163 _r->~BasicComposer<R>();
171 const Result<R>& result()
const
176 Signal< const Result<R>& >& finished()
177 {
return _finished; }
181 { _finished.send(_result); }
183 BasicComposer<R>& beginResult()
187 _r->~BasicComposer<R>();
191 _r =
new (_mem) BasicComposer<R>( &client().context() );
192 _r->begin( result().value() );
196 virtual void onReset()
200 _r->~BasicComposer<R>();
205 virtual void onClear()
212 Signal< const Result<R>& > _finished;
214 char _mem[
sizeof(BasicComposer<R>) ];
215 BasicComposer<R>* _r;
219 template <
typename A>
223 RemoteArgument(SerializationContext* )
230 _decomposer->~BasicDecomposer<A>();
233 void begin(
const A& a,
const char* name, SerializationContext& ctx)
237 _decomposer->~BasicDecomposer<A>();
241 _decomposer =
new (_mem) BasicDecomposer<A>(&ctx);
242 _decomposer->begin(a, name);
245 void clear(SerializationContext* )
249 _decomposer->~BasicDecomposer<A>();
255 BasicDecomposer<A>* decomposer()
256 {
return reinterpret_cast<BasicDecomposer<A>*
>(_mem); }
259 char _mem[
sizeof(BasicDecomposer<A>) ];
260 BasicDecomposer<A>* _decomposer;
267 #include <Pt/Remoting/RemoteProcedure.tpp>
269 #endif // Pt_Remoting_RemoteProcedure_h
Result(RemoteCall *call=0)
Constructor.
Definition: RemoteProcedure.h:92
Protects derived classes from being copied.
Definition: NonCopyable.h:54
Result of a remote procedure call.
Definition: RemoteProcedure.h:87
bool isFailed() const
Indicates if the procedure has failed.
Definition: RemoteProcedure.h:111
Unicode capable basic_string.
Definition: String.h:42
A client for remote procedure calls.
Definition: Client.h:47
R & value()
The return value.
Definition: RemoteProcedure.h:118