18 #ifndef INCLUDE_RCF_FUTURE_HPP 19 #define INCLUDE_RCF_FUTURE_HPP 22 #include <RCF/Marshal.hpp> 29 virtual ~I_Future() {}
30 virtual void setClientStub(ClientStub *pClientStub) = 0;
58 Future(T *pt) : mStatePtr(
new State(pt))
63 pClientStub->enrol(mStatePtr.get());
67 Future(
const T &t) : mStatePtr( new State(t))
72 return mStatePtr->operator T&();
78 return mStatePtr->operator T&();
83 mStatePtr = rhs.mStatePtr;
101 return mStatePtr->ready();
105 void wait(std::uint32_t timeoutMs = 0)
107 mStatePtr->wait(timeoutMs);
124 return mStatePtr->getClientStub();
128 std::unique_ptr<Exception> getAsyncException()
138 class State :
public I_Future, Noncopyable
161 unregisterFromCandidates();
172 if (!mpClientStub->ready())
174 mpClientStub->waitForReady();
177 std::unique_ptr<Exception> ePtr =
178 mpClientStub->getAsyncException();
186 T *pt = mpt ? mpt : mtPtr.get();
188 Lock lock(gCandidatesMutex());
189 gCandidates().add(pt,
this);
197 mpClientStub = pClientStub;
200 void setClientStub(
ClientStub *pClientStub, T * pt)
202 unregisterFromCandidates();
204 mpClientStub = pClientStub;
212 std::unique_ptr<T> mtPtr;
219 return mpClientStub->
ready();
222 void wait(std::uint32_t timeoutMs = 0)
234 return *mpClientStub;
237 void unregisterFromCandidates()
239 T *pt = mpt ? mpt : mtPtr.get();
240 Lock lock(gCandidatesMutex());
241 I_Future * pFuture = gCandidates().find(pt);
244 gCandidates().erase(pt);
250 std::shared_ptr<State> mStatePtr;
261 const std::string & mMsg;
265 class RCF_EXPORT FutureConverterBase
274 const char * szArity);
276 FutureConverterBase(
const FutureConverterBase& rhs);
277 FutureConverterBase &operator=(
const FutureConverterBase &rhs);
280 void callSync()
const;
281 void callAsync()
const;
286 const char * mSzFunc;
287 const char * mSzArity;
304 const char * szFunc =
"",
305 const char * szArity =
"") :
306 FutureConverterBase(clientStub, fnId, rcs, szFunc, szArity),
312 FutureConverterBase(rhs),
319 FutureConverterBase::operator=(rhs);
335 mpClientStub->clearParameters();
343 mpClientStub->setAsync(
true);
344 future.mStatePtr->setClientStub(mpClientStub, mpT);
355 if (!mpClientStub->getAsync())
357 mpClientStub->clearParameters();
366 template<
typename T,
typename U>
369 return fi.operator T() == u;
372 template<
typename T,
typename U>
375 return u == fi.operator T();
381 #endif // INCLUDE_RCF_FUTURE_HPP bool ready()
Tests whether the result of an asynchronous call is ready.
Definition: Future.hpp:99
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:55
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:105
RemoteCallMode
Remote call mode.
Definition: Enums.hpp:140
Provides the ability for remote calls to be executed asynchronously.
Definition: Future.hpp:50
void cancel()
Cancels an asynchronous call.
Definition: Future.hpp:111
T & operator*()
Dereferences this Future instance. If the remote call is still in progress, this function will block ...
Definition: Future.hpp:76
Utility class used by RCF to determine whether a remote call should be performed synchronously or asy...
Definition: Future.hpp:34
bool ready()
Returns true if an asynchronous call is ready.
void clear()
Clears this Future instance.
Definition: Future.hpp:117
Definition: AmiIoHandler.hpp:23
Future(const T &t)
Constructs a new Future instance, holding a copy of t.
Definition: Future.hpp:67