Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Future_Set.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Future_Set.h
00006  *
00007  *  $Id: Future_Set.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author John Tucker <jtucker@infoglide.com>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_FUTURE_SET_H
00014 #define ACE_FUTURE_SET_H
00015 #include "ace/pre.h"
00016 
00017 #include "ace/Thread.h"
00018 #include "ace/Message_Queue.h"
00019 #include "ace/Future.h"
00020 #include "ace/Hash_Map_Manager.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 #pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 #if defined (ACE_HAS_THREADS)
00027 
00028 /**
00029  * @class ACE_Future_Set
00030  *
00031  * @brief This class implements a mechanism which allows the values of
00032  * a collection of ACE_Future objects to be accessed by reader threads
00033  * as they become available.  The caller(s) provide the ACE_Future_Set
00034  * (i.e. the observer...) with the collection of ACE_Future objects
00035  * (i.e. the subjects...) that are to be observed using the
00036  * the ACE_Future_Set::insert() method.  The caller(s) may then iterate
00037  * over the collection in the order in which they become readable using
00038  * the ACE_Future_Set::next_readable() method.
00039  */
00040 template <class T>
00041 class ACE_Future_Set : public ACE_Future_Observer<T>
00042 {
00043 public:
00044   // = Initialization and termination methods.
00045 
00046   /// Constructor.
00047   ACE_Future_Set (ACE_Message_Queue<ACE_SYNCH> *future_notification_queue_ = 0);
00048 
00049   /// Destructor.
00050   ~ACE_Future_Set (void);
00051 
00052   /**
00053    * Return 1 if their are no ACE_Future objects left on its queue and
00054    * 0 otherwise.
00055    *
00056    * When an ACE_Future_Set has no ACE_Future>subjects to observe it is
00057    * empty. The ACE_Future_Set is in the empty state when either the caller(s)
00058    * have retrieved every readable ACE_Future subject assigned the
00059    * ACE_Future_Set via the ACE_Future_Set::next_readable() method,
00060    * or when the ACE_Future_Set has not been assigned any subjects.
00061    */
00062   int is_empty (void) const;
00063 
00064   /**
00065    * Enqueus the given ACE_Future into this objects queue when it is
00066    * readable.
00067    *
00068    * Returns 0 if the future is successfully inserted, 1 if the
00069    * future is already inserted, and -1 if failures occur.
00070    */
00071   int insert (ACE_Future<T> &future);
00072 
00073   /**
00074    * Wait up to <tv> time to get the <value>.  Note that <tv> must be
00075    * specified in absolute time rather than relative time.); get the
00076    * next <ACE_Future> that is readable.  If <tv> = 0, the will block
00077    * forever.
00078    *
00079    * If a readable future becomes available, then the input
00080    * <ACE_Future> object param will be assigned with it and 1 will
00081    * be returned.  If the <ACE_Future_Set> is empty (i.e. see definition
00082    * of <ACE_Future_Set::is_empty>), then 0 is returned.
00083    *
00084    * When a readable <ACE_Future> object is retrieved via the
00085    * <ACE_Future_Set::next_readable> method, the <ACE_Future_Set> will
00086    * remove that <ACE_Future> object from its list of subjects.
00087    */
00088   int next_readable (ACE_Future<T> &result,
00089                      ACE_Time_Value *tv = 0);
00090 
00091   /// Called by the ACE_Future subject in which we are subscribed to
00092   /// when its value is written to.
00093   virtual void update (const ACE_Future<T> &future);
00094 
00095   /// Declare the dynamic allocation hooks.
00096   ACE_ALLOC_HOOK_DECLARE;
00097 
00098 private:
00099   // = Disallow these operations.
00100   ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Future_Set<T> &))
00101   ACE_UNIMPLEMENTED_FUNC (ACE_Future_Set (const ACE_Future_Set<T> &))
00102 
00103   typedef ACE_Future<T> FUTURE;
00104 
00105   typedef ACE_Future_Rep<T> FUTURE_REP;
00106 
00107   typedef ACE_Future_Holder<T> FUTURE_HOLDER;
00108 
00109   typedef ACE_Pointer_Hash<FUTURE_REP *> FUTURE_REP_HASH;
00110 
00111   typedef ACE_Equal_To<FUTURE_REP *> FUTURE_REP_COMPARE;
00112 
00113   typedef ACE_Hash_Map_Manager_Ex<FUTURE_REP *,
00114                                   FUTURE_HOLDER *,
00115                                   FUTURE_REP_HASH,
00116                                   FUTURE_REP_COMPARE,
00117                                   ACE_Null_Mutex> FUTURE_HASH_MAP;
00118 
00119   /// Map of <ACE_Futures>, subjects, which have not been written to by
00120   /// client's writer thread.
00121   FUTURE_HASH_MAP future_map_;
00122 
00123   /// Message queue for notifying the reader thread of <ACE_Futures> which
00124   /// have been written to by client's writer thread.
00125   ACE_Message_Queue<ACE_SYNCH> *future_notification_queue_;
00126 
00127   /// Keeps track of whether we need to delete the message queue.
00128   int delete_queue_;
00129 };
00130 
00131 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00132 #include "ace/Future_Set.cpp"
00133 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00134 
00135 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00136 #pragma implementation ("Future_Set.cpp")
00137 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00138 
00139 #endif /* ACE_HAS_THREADS */
00140 #include "ace/post.h"
00141 #endif /* ACE_FUTURE_SET_H */

Generated on Mon Jun 16 11:19:44 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002