Task_T.h

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

Generated on Thu Nov 9 09:42:06 2006 for ACE by doxygen 1.3.6