00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Task_T.h 00006 * 00007 * $Id: Task_T.h 80826 2008-03-04 14:51:23Z wotte $ 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 /** 00115 * Tests whether we can enqueue a message without blocking. 00116 * 00117 * @deprecated This method is deprecated and will go away in the future. 00118 */ 00119 int can_put (ACE_Message_Block *); 00120 00121 // = ACE_Task utility routines to identify names et al. 00122 /// Return the name of the enclosing Module if there's one associated 00123 /// with the Task, else returns 0. 00124 const ACE_TCHAR *name (void) const; 00125 00126 // = Pointers to next ACE_Task_Base (if ACE is part of an ACE_Stream). 00127 /// Get next Task pointer. 00128 ACE_Task<ACE_SYNCH_USE> *next (void); 00129 00130 /// Set next Task pointer. 00131 void next (ACE_Task<ACE_SYNCH_USE> *); 00132 00133 /// Return the Task's sibling if there's one associated with the 00134 /// Task's Module, else returns 0. 00135 ACE_Task<ACE_SYNCH_USE> *sibling (void); 00136 00137 /// Return the Task's Module if there is one, else returns 0. 00138 ACE_Module<ACE_SYNCH_USE> *module (void) const; 00139 00140 /** 00141 * Flush the task's queue, i.e., free all of the enqueued 00142 * message blocks and unblocks any threads waiting on the queue. 00143 * Note that if this conflicts with the C++ iostream <flush> 00144 * function, just rewrite the iostream function as ::<flush>. 00145 */ 00146 int flush (u_long flag = ACE_Task_Flags::ACE_FLUSHALL); 00147 00148 // = Special routines corresponding to certain message types. 00149 00150 /// Manipulate watermarks. 00151 void water_marks (ACE_IO_Cntl_Msg::ACE_IO_Cntl_Cmds, size_t); 00152 00153 /// Queue of messages on the ACE_Task.. 00154 ACE_Message_Queue<ACE_SYNCH_USE> *msg_queue_; 00155 00156 /// true if should delete Message_Queue, false otherwise. 00157 bool delete_msg_queue_; 00158 00159 /// Back-pointer to the enclosing module. 00160 ACE_Module<ACE_SYNCH_USE> *mod_; 00161 00162 /// Pointer to adjacent ACE_Task. 00163 ACE_Task<ACE_SYNCH_USE> *next_; 00164 00165 /// Dump the state of an object. 00166 void dump (void) const; 00167 00168 /// Declare the dynamic allocation hooks. 00169 ACE_ALLOC_HOOK_DECLARE; 00170 00171 private: 00172 00173 // = Disallow these operations. 00174 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Task<ACE_SYNCH_USE> &)) 00175 ACE_UNIMPLEMENTED_FUNC (ACE_Task (const ACE_Task<ACE_SYNCH_USE> &)) 00176 }; 00177 00178 #if defined ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT 00179 template class ACE_Export ACE_Task<ACE_MT_SYNCH>; 00180 template class ACE_Export ACE_Task<ACE_NULL_SYNCH>; 00181 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT */ 00182 00183 ACE_END_VERSIONED_NAMESPACE_DECL 00184 00185 #if defined (__ACE_INLINE__) 00186 #include "ace/Task_T.inl" 00187 #endif /* __ACE_INLINE__ */ 00188 00189 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00190 #include "ace/Task_T.cpp" 00191 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00192 00193 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00194 #pragma implementation ("Task_T.cpp") 00195 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00196 00197 #include /**/ "ace/post.h" 00198 #endif /* ACE_TASK_T_H */