ACE_Future< T > Class Template Reference

This class implements a ``single write, multiple read'' pattern that can be used to return results from asynchronous method invocations. More...

#include <Future.h>

Collaboration diagram for ACE_Future< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Future (void)
 Constructor.

 ACE_Future (const ACE_Future< T > &r)
 ACE_Future (const T &r)
 ~ACE_Future (void)
 Destructor.

void operator= (const ACE_Future< T > &r)
int cancel (const T &r)
int cancel (void)
bool operator== (const ACE_Future< T > &r) const
bool operator!= (const ACE_Future< T > &r) const
 Inequality operator, which is the opposite of equality.

int set (const T &r)
int get (T &value, ACE_Time_Value *tv=0) const
 operator T ()
int ready (void) const
 Check if the result is available.

int attach (ACE_Future_Observer< T > *observer)
int detach (ACE_Future_Observer< T > *observer)
void dump (void) const
 Dump the state of an object.

ACE_Future_Rep< T > * get_rep (void)

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Types

typedef ACE_Future_Rep< T > FUTURE_REP
 Protect operations on the .


Private Attributes

FUTURE_REPfuture_rep_

Detailed Description

template<class T>
class ACE_Future< T >

This class implements a ``single write, multiple read'' pattern that can be used to return results from asynchronous method invocations.

Definition at line 241 of file Future.h.


Member Typedef Documentation

template<class T>
typedef ACE_Future_Rep<T> ACE_Future< T >::FUTURE_REP [private]
 

Protect operations on the .

Definition at line 372 of file Future.h.

Referenced by ACE_Future< T >::ACE_Future().


Constructor & Destructor Documentation

template<class T>
ACE_Future< T >::ACE_Future void   ) 
 

Constructor.

Definition at line 289 of file Future.cpp.

References ACE_Future< T >::FUTURE_REP.

00290   : future_rep_ (FUTURE_REP::create ())
00291 {
00292 }

template<class T>
ACE_Future< T >::ACE_Future const ACE_Future< T > &  r  ) 
 

Copy constructor binds this and r to the same ACE_Future_Rep. An ACE_Future_Rep is created if necessary.

Definition at line 295 of file Future.cpp.

References ACE_Future< T >::FUTURE_REP.

00296   : future_rep_ (FUTURE_REP::attach (((ACE_Future<T> &) r).future_rep_))
00297 {
00298 }

template<class T>
ACE_Future< T >::ACE_Future const T &  r  ) 
 

Constructor that initialises an ACE_Future to point to the result r immediately.

Definition at line 301 of file Future.cpp.

References ACE_Future< T >::FUTURE_REP, ACE_Future< T >::future_rep_, and ACE_Future_Rep< T >::set().

00302   : future_rep_ (FUTURE_REP::create ())
00303 {
00304   this->future_rep_->set (r, *this);
00305 }

template<class T>
ACE_Future< T >::~ACE_Future void   ) 
 

Destructor.

Definition at line 308 of file Future.cpp.

References ACE_Future< T >::future_rep_.

00309 {
00310   FUTURE_REP::detach (future_rep_);
00311 }


Member Function Documentation

template<class T>
int ACE_Future< T >::attach ACE_Future_Observer< T > *  observer  ) 
 

Attaches the specified observer to a subject (this ACE_Future). The update method of the specified subject will be invoked with a copy of the associated ACE_Future as input when the result gets set. If the result is already set when this method gets invoked, then the update method of the specified subject will be invoked immediately.

Parameters:
observer The observer to attach to the subject.
Return values:
0 Success.
1 The observer was already attached.
-1 Error; check ACE_OS::last_error() for an error code.

Definition at line 367 of file Future.cpp.

References ACE_Future_Rep< T >::attach(), and ACE_Future< T >::future_rep_.

00368 {
00369   return this->future_rep_->attach (observer, *this);
00370 }

template<class T>
int ACE_Future< T >::cancel void   ) 
 

Cancel an ACE_Future. Put the future into its initial state. Returns 0 on succes and -1 on failure. It is now possible to reuse the ACE_Future. But remember, the ACE_Future is now bound to a new ACE_Future_Rep.

Definition at line 334 of file Future.cpp.

Referenced by ACE_Future< T >::cancel().

00335 {
00336   // If this ACE_Future is already attached to a ACE_Future_Rep,
00337   // detach it (maybe delete the ACE_Future_Rep).
00338   FUTURE_REP::assign (this->future_rep_,
00339                       FUTURE_REP::create ());
00340   return 0;
00341 }

template<class T>
int ACE_Future< T >::cancel const T &  r  ) 
 

Cancel an ACE_Future and assign the value r. It is used if a client does not want to wait for the value to be produced.

Definition at line 326 of file Future.cpp.

References ACE_Future< T >::cancel(), ACE_Future< T >::future_rep_, and ACE_Future_Rep< T >::set().

00327 {
00328   this->cancel ();
00329   return this->future_rep_->set (r,
00330                                  *this);
00331 }

template<class T>
int ACE_Future< T >::detach ACE_Future_Observer< T > *  observer  ) 
 

Detaches the specified observer from a subject (this ACE_Future). The update method of the specified subject will not be invoked when the ACE_Future_Rep result gets set.

Parameters:
observer The observer to attach to the subject.
Return values:
0 The observer was successfully detached.
-1 Error, including the observer not attached prior to calling this method.

Definition at line 373 of file Future.cpp.

References ACE_Future_Rep< T >::detach(), and ACE_Future< T >::future_rep_.

00374 {
00375   return this->future_rep_->detach (observer);
00376 }

template<class T>
void ACE_Future< T >::dump void   )  const
 

Dump the state of an object.

Definition at line 410 of file Future.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_Future_Rep< T >::dump(), ACE_Future< T >::future_rep_, and LM_DEBUG.

00411 {
00412 #if defined (ACE_HAS_DUMP)
00413   ACE_DEBUG ((LM_DEBUG,
00414               ACE_BEGIN_DUMP, this));
00415 
00416   if (this->future_rep_)
00417     this->future_rep_->dump ();
00418 
00419   ACE_DEBUG ((LM_DEBUG,
00420               ACE_END_DUMP));
00421 #endif /* ACE_HAS_DUMP */
00422 }

template<class T>
int ACE_Future< T >::get T &  value,
ACE_Time_Value tv = 0
const
 

Wait to get the object's value.

Parameters:
value Receives the value of this ACE_Future when it is set.
tv Pointer to an ACE_Time_Value containing the absolute time to wait until for the value to be set. If tv is 0, the call waits indefinitely for the value to be set, unless an error occurs.
Return values:
0 Success; value contains the value of the ACE_Future.
-1 Error; check ACE_OS::last_error() for an error code.

Definition at line 359 of file Future.cpp.

References ACE_Future< T >::future_rep_, and ACE_Future_Rep< T >::get().

00361 {
00362   // We return the ACE_Future_rep.
00363   return this->future_rep_->get (value, tv);
00364 }

template<class T>
ACE_Future_Rep< T > * ACE_Future< T >::get_rep void   ) 
 

Get the underlying ACE_Future_Rep pointer. Note that this method should rarely, if ever, be used and that modifying the underlying ACE_Future_Rep should be done with extreme caution.

Definition at line 425 of file Future.cpp.

References ACE_Future< T >::future_rep_.

Referenced by ACE_Future_Set< T >::update().

00426 {
00427   return this->future_rep_;
00428 }

template<class T>
ACE_Future< T >::operator T  ) 
 

Deprecated:
Note that this method is going away in a subsequent release since it doesn't distinguish between failure results and success results (exceptions should be used, but they aren't portable...). Type conversion, which obtains the result of the asynchronous method invocation. Will block forever. The get() method should be used instead since it separates the error value from the result, and also permits timeouts.

Definition at line 379 of file Future.cpp.

References ACE_Future< T >::future_rep_.

00380 {
00381   // note that this will fail (and COREDUMP!)
00382   // if future_rep_ == 0 !
00383   //
00384   // but...
00385   // this is impossible unless somebody is so stupid to
00386   // try something like this:
00387   //
00388   // Future<T> futT;
00389   // T t;
00390   // t = futT;
00391 
00392   // perform type conversion on Future_Rep.
00393   return *future_rep_;
00394 }

template<class T>
bool ACE_Future< T >::operator!= const ACE_Future< T > &  r  )  const
 

Inequality operator, which is the opposite of equality.

Definition at line 320 of file Future.cpp.

References ACE_Future< T >::future_rep_.

00321 {
00322   return r.future_rep_ != this->future_rep_;
00323 }

template<class T>
void ACE_Future< T >::operator= const ACE_Future< T > &  r  ) 
 

Assignment operator that binds this and r to the same ACE_Future_Rep. An ACE_Future_Rep is created if necessary.

Definition at line 397 of file Future.cpp.

References ACE_Future< T >::future_rep_.

00398 {
00399   // assignment:
00400   //
00401   //  bind <this> to the same <ACE_Future_Rep> as <r>.
00402 
00403   // This will work if &r == this, by first increasing the ref count
00404   ACE_Future<T> &r = (ACE_Future<T> &) rhs;
00405   FUTURE_REP::assign (this->future_rep_,
00406                       FUTURE_REP::attach (r.future_rep_));
00407 }

template<class T>
bool ACE_Future< T >::operator== const ACE_Future< T > &  r  )  const
 

Equality operator that returns true if both ACE_Future objects point to the same ACE_Future_Rep object.

Note:
It also returns true if both objects have just been instantiated and not used yet.

Definition at line 314 of file Future.cpp.

References ACE_Future< T >::future_rep_.

00315 {
00316   return r.future_rep_ == this->future_rep_;
00317 }

template<class T>
int ACE_Future< T >::ready void   )  const
 

Check if the result is available.

Definition at line 352 of file Future.cpp.

References ACE_Future< T >::future_rep_, and ACE_Future_Rep< T >::ready().

00353 {
00354   // We're ready if the ACE_Future_rep is ready...
00355   return this->future_rep_->ready ();
00356 }

template<class T>
int ACE_Future< T >::set const T &  r  ) 
 

Make the result available. Is used by the server thread to give the result to all waiting clients. Returns 0 for success, -1 on failure. This function only has an effect the first time it is called for the object (actually, the first time the underlying ACE_Future_Rep has a value assigned to it). Subsequent calls return 0 (success) but have no effect.

Definition at line 344 of file Future.cpp.

References ACE_Future< T >::future_rep_, and ACE_Future_Rep< T >::set().

00345 {
00346   // Give the pointer to the result to the ACE_Future_Rep.
00347   return this->future_rep_->set (r,
00348                                  *this);
00349 }


Member Data Documentation

template<class T>
ACE_Future< T >::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 366 of file Future.h.

template<class T>
FUTURE_REP* ACE_Future< T >::future_rep_ [private]
 

Definition at line 373 of file Future.h.

Referenced by ACE_Future< T >::ACE_Future(), ACE_Future< T >::attach(), ACE_Future< T >::cancel(), ACE_Future< T >::detach(), ACE_Future< T >::dump(), ACE_Future< T >::get(), ACE_Future< T >::get_rep(), ACE_Future< T >::operator T(), ACE_Future< T >::operator!=(), ACE_Future< T >::operator=(), ACE_Future< T >::operator==(), ACE_Future< T >::ready(), ACE_Future< T >::set(), and ACE_Future< T >::~ACE_Future().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:22:31 2006 for ACE by doxygen 1.3.6