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

Task_T.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Task_T.h
00006  *
00007  *  $Id: Task_T.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_TASK_T_H
00014 #define ACE_TASK_T_H
00015 #include "ace/pre.h"
00016 
00017 #include "ace/Message_Queue.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #include "ace/Synch_T.h"
00024 #include "ace/Task.h"
00025 
00026 // Forward decls...
00027 template <ACE_SYNCH_DECL> class ACE_Module;
00028 
00029 /**
00030  * @class ACE_Task
00031  *
00032  * @brief Primary interface for application message processing, as well
00033  * as input and output message queueing.
00034  *
00035  * This class serves as the basis for passive and active objects
00036  * in ACE.
00037  */
00038 template <ACE_SYNCH_DECL>
00039 class ACE_Task : public ACE_Task_Base
00040 {
00041 public:
00042   friend class ACE_Module<ACE_SYNCH_USE>;
00043   friend class ACE_Module_Type;
00044 
00045   // = Initialization/termination methods.
00046   /**
00047    * Initialize a Task, supplying a thread manager and a message
00048    * queue.  If the user doesn't supply a ACE_Message_Queue pointer
00049    * then we'll allocate one dynamically.  Otherwise, we'll use the
00050    * one passed as a parameter.
00051    */
00052   ACE_Task (ACE_Thread_Manager *thr_mgr = 0,
00053             ACE_Message_Queue<ACE_SYNCH_USE> *mq = 0);
00054 
00055   /// Destructor.
00056   virtual ~ACE_Task (void);
00057 
00058   /// Gets the message queue associated with this task.
00059   ACE_Message_Queue<ACE_SYNCH_USE> *msg_queue (void);
00060 
00061   /// Sets the message queue associated with this task.
00062   void msg_queue (ACE_Message_Queue<ACE_SYNCH_USE> *);
00063 
00064 public: // Should be protected:
00065   // = Message queue manipulation methods.
00066 
00067   // = Enqueue and dequeue methods.
00068 
00069   // For the following five method if <timeout> == 0, the caller will
00070   // block until action is possible, else will wait until the
00071   // <{absolute}> time specified in *<timeout> elapses).  These calls
00072   // will return, however, when queue is closed, deactivated, when a
00073   // signal occurs, or if the time specified in timeout elapses, (in
00074   // which case errno = EWOULDBLOCK).
00075 
00076   /// Insert message into the message queue.  Note that <timeout> uses
00077   /// <{absolute}> time rather than <{relative}> time.
00078   int putq (ACE_Message_Block *, ACE_Time_Value *timeout = 0);
00079 
00080   /**
00081    * Extract the first message from the queue (blocking).  Note that
00082    * <timeout> uses <{absolute}> time rather than <{relative}> time.
00083    * Returns number of items in queue if the call succeeds or -1 otherwise.
00084    */
00085   int getq (ACE_Message_Block *&mb, ACE_Time_Value *timeout = 0);
00086 
00087   /// Return a message to the queue.  Note that <timeout> uses
00088   /// <{absolute}> time rather than <{relative}> time.
00089   int ungetq (ACE_Message_Block *, ACE_Time_Value *timeout = 0);
00090 
00091   /**
00092    * Turn the message around and send it back down the Stream.  Note
00093    * that <timeout> uses <{absolute}> time rather than <{relative}>
00094    * time.
00095    */
00096   int reply (ACE_Message_Block *, ACE_Time_Value *timeout = 0);
00097 
00098   /**
00099    * Transfer message to the adjacent ACE_Task in a ACE_Stream.  Note
00100    * that <timeout> uses <{absolute}> time rather than <{relative}>
00101    * time.
00102    */
00103   int put_next (ACE_Message_Block *msg, ACE_Time_Value *timeout = 0);
00104 
00105   /// Tests whether we can enqueue a message without blocking.
00106   int can_put (ACE_Message_Block *);
00107 
00108   // = ACE_Task utility routines to identify names et al.
00109   /// Return the name of the enclosing Module if there's one associated
00110   /// with the Task, else returns 0.
00111   const ACE_TCHAR *name (void) const;
00112 
00113   // = Pointers to next ACE_Task_Base (if ACE is part of an ACE_Stream).
00114   /// Get next Task pointer.
00115   ACE_Task<ACE_SYNCH_USE> *next (void);
00116 
00117   /// Set next Task pointer.
00118   void next (ACE_Task<ACE_SYNCH_USE> *);
00119 
00120   /// Return the Task's sibling if there's one associated with the
00121   /// Task's Module, else returns 0.
00122   ACE_Task<ACE_SYNCH_USE> *sibling (void);
00123 
00124   /// Return the Task's Module if there is one, else returns 0.
00125   ACE_Module<ACE_SYNCH_USE> *module (void) const;
00126 
00127   /**
00128    * Flush the task's queue, i.e., free all of the enqueued
00129    * message blocks and releases any threads blocked on the queue.
00130    * Note that if this conflicts with the C++ iostream <flush>
00131    * function, just rewrite the iostream function as ::<flush>.
00132    */
00133   int flush (u_long flag = ACE_Task_Flags::ACE_FLUSHALL);
00134 
00135   // = Special routines corresponding to certain message types.
00136 
00137   /// Manipulate watermarks.
00138   void water_marks (ACE_IO_Cntl_Msg::ACE_IO_Cntl_Cmds, size_t);
00139 
00140   /// Queue of messages on the ACE_Task..
00141   ACE_Message_Queue<ACE_SYNCH_USE> *msg_queue_;
00142 
00143   /// 1 if should delete Message_Queue, 0 otherwise.
00144   int delete_msg_queue_;
00145 
00146   /// Back-pointer to the enclosing module.
00147   ACE_Module<ACE_SYNCH_USE> *mod_;
00148 
00149   /// Pointer to adjacent ACE_Task.
00150   ACE_Task<ACE_SYNCH_USE> *next_;
00151 
00152   /// Dump the state of an object.
00153   void dump (void) const;
00154 
00155   /// Declare the dynamic allocation hooks.
00156   ACE_ALLOC_HOOK_DECLARE;
00157 
00158 private:
00159 
00160   // = Disallow these operations.
00161   ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Task<ACE_SYNCH_USE> &))
00162   ACE_UNIMPLEMENTED_FUNC (ACE_Task (const ACE_Task<ACE_SYNCH_USE> &))
00163 };
00164 
00165 #if defined ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT
00166 template class ACE_Export ACE_Task<ACE_MT_SYNCH>;
00167 template class ACE_Export ACE_Task<ACE_NULL_SYNCH>;
00168 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT */
00169 
00170 #if defined (__ACE_INLINE__)
00171 #include "ace/Task_T.i"
00172 #endif /* __ACE_INLINE__ */
00173 
00174 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00175 #include "ace/Task_T.cpp"
00176 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00177 
00178 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00179 #pragma implementation ("Task_T.cpp")
00180 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00181 
00182 #include "ace/post.h"
00183 #endif /* ACE_TASK_T_H */

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