3 //=============================================================================
7 * $Id: Task_Ex_T.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Kobi Cohen-Arazi <kobi-co@barak-online.net>
11 //=============================================================================
13 #ifndef ACE_TASK_EX_T_H
14 #define ACE_TASK_EX_T_H
15 #include /**/ "ace/pre.h"
17 #include "ace/Service_Object.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/Synch_Traits.h"
26 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
29 template <ACE_SYNCH_DECL
> class ACE_Module
;
34 * @brief Primary interface for application message processing, as well
35 * as input and output message queueing.
37 * Unlike ACE_Task, these class doesn't have the ability to be a part of
38 * a Stream chain. I.e. You cannot (yet) chain modules based on ACE_Task_Ex.
40 * @todo: We can merge ACE_Task and ACE_Task_Ex to be one class.
41 * something like that:
42 * template <ACE_SYNCH_DECL, ACE_MESSAGE_TYPE = ACE_Message_Block>
43 * class ACE_Task : public ACE_Task_Base
45 * // use here the code from ACE_Task_Ex using ACE_Message_Queue_Ex
48 * Now specialized version of ACE_Task with ACE_Message_Block as its
51 * template <ACE_SYNCH_DECL>
52 * class ACE_Task <ACE_SYNCH_USE, ACE_Message_Block> : public ACE_Task_Base
54 * // put here the good old ACE_Task code
57 * When User (and legacy code) write ACE_Task<ACE_MT_SYNCH>, specialized ACE_Task
60 template <ACE_SYNCH_DECL
, class ACE_MESSAGE_TYPE
>
61 class ACE_Task_Ex
: public ACE_Task_Base
64 friend class ACE_Module
<ACE_SYNCH_USE
>;
65 friend class ACE_Module_Type
;
66 typedef ACE_Message_Queue_Ex
<ACE_MESSAGE_TYPE
, ACE_SYNCH_USE
> MESSAGE_QUEUE_EX
;
68 // = Initialization/termination methods.
70 * Initialize a Task, supplying a thread manager and a message
71 * queue. If the user doesn't supply a ACE_Message_Queue pointer
72 * then we'll allocate one dynamically. Otherwise, we'll use the
73 * one passed as a parameter.
75 ACE_Task_Ex (ACE_Thread_Manager
*thr_mgr
= 0,
76 MESSAGE_QUEUE_EX
*mq
= 0);
79 virtual ~ACE_Task_Ex (void);
81 /// Gets the message queue associated with this task.
82 MESSAGE_QUEUE_EX
*msg_queue (void);
84 /// Sets the message queue associated with this task.
85 void msg_queue (MESSAGE_QUEUE_EX
*);
87 public: // Should be protected:
88 // = Message queue manipulation methods.
90 // = Enqueue and dequeue methods.
92 // For the following five method if @a timeout == 0, the caller will
93 // block until action is possible, else will wait until the
94 // <{absolute}> time specified in *@a timeout elapses). These calls
95 // will return, however, when queue is closed, deactivated, when a
96 // signal occurs, or if the time specified in timeout elapses, (in
97 // which case errno = EWOULDBLOCK).
99 /// Insert message into the message queue. Note that @a timeout uses
100 /// <{absolute}> time rather than <{relative}> time.
101 int putq (ACE_MESSAGE_TYPE
*, ACE_Time_Value
*timeout
= 0);
104 * Extract the first message from the queue (blocking). Note that
105 * @a timeout uses <{absolute}> time rather than <{relative}> time.
106 * Returns number of items in queue if the call succeeds or -1 otherwise.
108 int getq (ACE_MESSAGE_TYPE
*&mb
, ACE_Time_Value
*timeout
= 0);
110 /// Return a message to the queue. Note that @a timeout uses
111 /// <{absolute}> time rather than <{relative}> time.
112 int ungetq (ACE_MESSAGE_TYPE
*, ACE_Time_Value
*timeout
= 0);
115 * Turn the message around and send it back down the Stream. Note
116 * that @a timeout uses <{absolute}> time rather than <{relative}>
119 int reply (ACE_MESSAGE_TYPE
*, ACE_Time_Value
*timeout
= 0);
122 * Transfer message to the adjacent ACE_Task_Ex in a ACE_Stream. Note
123 * that @a timeout uses <{absolute}> time rather than <{relative}>
126 int put_next (ACE_MESSAGE_TYPE
*msg
, ACE_Time_Value
*timeout
= 0);
129 * Tests whether we can enqueue a message without blocking.
130 * @deprecated This method is deprecated and will go away in the future.
132 int can_put (ACE_MESSAGE_TYPE
*);
134 // = ACE_Task utility routines to identify names et al.
135 /// Return the name of the enclosing Module if there's one associated
136 /// with the Task, else returns 0.
137 const ACE_TCHAR
*name (void) const;
139 // = Pointers to next ACE_Task_Base (if ACE is part of an ACE_Stream).
140 /// Get next Task pointer.
141 ACE_Task
<ACE_SYNCH_USE
> *next (void);
143 /// Set next Task pointer.
144 void next (ACE_Task
<ACE_SYNCH_USE
> *);
146 /// Alwasy return 0. @todo FIXME
147 ACE_Task
<ACE_SYNCH_USE
> *sibling (void);
149 /// Return the Task's Module if there is one, else returns 0.
150 ACE_Module
<ACE_SYNCH_USE
> *module (void) const;
153 * Flush the task's queue, i.e., free all of the enqueued
154 * message blocks and releases any threads blocked on the queue.
155 * Note that if this conflicts with the C++ iostream <flush>
156 * function, just rewrite the iostream function as ::<flush>.
158 int flush (u_long flag
= ACE_Task_Flags::ACE_FLUSHALL
);
160 // = Special routines corresponding to certain message types.
162 /// Manipulate watermarks.
163 void water_marks (ACE_IO_Cntl_Msg::ACE_IO_Cntl_Cmds
, size_t);
165 /// Queue of messages on the ACE_Task..
166 MESSAGE_QUEUE_EX
*msg_queue_
;
168 /// true if should delete Message_Queue, false otherwise.
169 bool delete_msg_queue_
;
171 /// Back-pointer to the enclosing module.
172 ACE_Module
<ACE_SYNCH_USE
> *mod_
;
174 /// Pointer to adjacent ACE_Task.
175 ACE_Task
<ACE_SYNCH_USE
> *next_
;
177 /// Dump the state of an object.
178 void dump (void) const;
180 /// Declare the dynamic allocation hooks.
181 ACE_ALLOC_HOOK_DECLARE
;
185 // = Disallow these operations.
186 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Task_Ex
<ACE_SYNCH_USE
, ACE_MESSAGE_TYPE
> &))
187 ACE_UNIMPLEMENTED_FUNC (ACE_Task_Ex (const ACE_Task_Ex
<ACE_SYNCH_USE
, ACE_MESSAGE_TYPE
> &))
190 ACE_END_VERSIONED_NAMESPACE_DECL
192 #if defined (__ACE_INLINE__)
193 #include "ace/Task_Ex_T.inl"
194 #endif /* __ACE_INLINE__ */
196 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
197 #include "ace/Task_Ex_T.cpp"
198 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
200 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
201 #pragma implementation ("Task_Ex_T.cpp")
202 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
204 #include /**/ "ace/post.h"
205 #endif /* ACE_TASK_EX_H */