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