19 #ifndef INCLUDE_RCF_FUTURE_HPP 20 #define INCLUDE_RCF_FUTURE_HPP 23 #include <RCF/Marshal.hpp> 30 virtual ~I_Future() {}
31 virtual void setClientStub(ClientStub *pClientStub) = 0;
59 Future(T *pt) : mStatePtr(
new State(pt))
64 pClientStub->enrol(mStatePtr.get());
68 Future(
const T &t) : mStatePtr( new State(t))
73 return mStatePtr->operator T&();
79 return mStatePtr->operator T&();
84 mStatePtr = rhs.mStatePtr;
102 return mStatePtr->ready();
106 void wait(std::uint32_t timeoutMs = 0)
108 mStatePtr->wait(timeoutMs);
125 return mStatePtr->getClientStub();
129 std::unique_ptr<Exception> getAsyncException()
139 class State :
public I_Future, Noncopyable
162 unregisterFromCandidates();
173 if (!mpClientStub->ready())
175 mpClientStub->waitForReady();
178 std::unique_ptr<Exception> ePtr =
179 mpClientStub->getAsyncException();
187 T *pt = mpt ? mpt : mtPtr.get();
189 Lock lock(gCandidatesMutex());
190 gCandidates().add(pt,
this);
198 mpClientStub = pClientStub;
201 void setClientStub(
ClientStub *pClientStub, T * pt)
203 unregisterFromCandidates();
205 mpClientStub = pClientStub;
213 std::unique_ptr<T> mtPtr;
220 return mpClientStub->
ready();
223 void wait(std::uint32_t timeoutMs = 0)
235 return *mpClientStub;
238 void unregisterFromCandidates()
240 T *pt = mpt ? mpt : mtPtr.get();
241 Lock lock(gCandidatesMutex());
242 I_Future * pFuture = gCandidates().find(pt);
245 gCandidates().erase(pt);
251 std::shared_ptr<State> mStatePtr;
262 const std::string & mMsg;
266 class RCF_EXPORT FutureConverterBase
275 const char * szArity);
277 FutureConverterBase(
const FutureConverterBase& rhs);
278 FutureConverterBase &operator=(
const FutureConverterBase &rhs);
281 void callSync()
const;
282 void callAsync()
const;
287 const char * mSzFunc;
288 const char * mSzArity;
305 const char * szFunc =
"",
306 const char * szArity =
"") :
307 FutureConverterBase(clientStub, fnId, rcs, szFunc, szArity),
313 FutureConverterBase(rhs),
320 FutureConverterBase::operator=(rhs);
336 mpClientStub->clearParameters();
344 mpClientStub->setAsync(
true);
345 future.mStatePtr->setClientStub(mpClientStub, mpT);
356 if (!mpClientStub->getAsync())
358 mpClientStub->clearParameters();
367 template<
typename T,
typename U>
370 return fi.operator T() == u;
373 template<
typename T,
typename U>
376 return u == fi.operator T();
382 #endif // INCLUDE_RCF_FUTURE_HPP bool ready()
Tests whether the result of an asynchronous call is ready.
Definition: Future.hpp:100
Controls the client side of a RCF connection.
Definition: ClientStub.hpp:82
void waitForReady(std::uint32_t timeoutMs=0)
Waits until an asynchronous call is ready.
Future()
Constructs a new Future instance.
Definition: Future.hpp:56
void cancel()
Cancels an asynchronous call.
std::unique_ptr< Exception > getAsyncException()
Retrieves an asynchronous exception.
void wait(std::uint32_t timeoutMs=0)
Waits for up to timeoutMs ms, for the result of an asynchronous call to become ready.
Definition: Future.hpp:106
RemoteCallMode
Remote call mode.
Definition: Enums.hpp:141
Provides the ability for remote calls to be executed asynchronously.
Definition: Future.hpp:51
void cancel()
Cancels an asynchronous call.
Definition: Future.hpp:112
T & operator*()
Dereferences this Future instance. If the remote call is still in progress, this function will block ...
Definition: Future.hpp:77
Utility class used by RCF to determine whether a remote call should be performed synchronously or asy...
Definition: Future.hpp:35
bool ready()
Returns true if an asynchronous call is ready.
void clear()
Clears this Future instance.
Definition: Future.hpp:118
Definition: AmiIoHandler.hpp:24
Future(const T &t)
Constructs a new Future instance, holding a copy of t.
Definition: Future.hpp:68