Revert to Current Include Style
[ACE_TAO.git] / ACE / ace / Stream_Modules.cpp
blob2114de2f85fa8cb6d3b44162dad2a9b35c058fb5
1 #ifndef ACE_STREAM_MODULES_CPP
2 #define ACE_STREAM_MODULES_CPP
4 #include "ace/Stream_Modules.h"
5 #include "ace/OS_NS_string.h"
7 #if !defined (ACE_LACKS_PRAGMA_ONCE)
8 # pragma once
9 #endif /* ACE_LACKS_PRAGMA_ONCE */
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_ALLOC_HOOK_DEFINE_Tyc(ACE_Stream_Head)
16 template <ACE_SYNCH_DECL, class TIME_POLICY>
17 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::ACE_Stream_Head ()
19 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::ACE_Stream_Head");
22 template <ACE_SYNCH_DECL, class TIME_POLICY>
23 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::~ACE_Stream_Head ()
25 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::~ACE_Stream_Head");
28 template <ACE_SYNCH_DECL, class TIME_POLICY> void
29 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::dump () const
31 #if defined (ACE_HAS_DUMP)
32 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::dump");
33 #endif /* ACE_HAS_DUMP */
36 // ACE_Module that act as the head and tail of a Stream.
38 template <ACE_SYNCH_DECL, class TIME_POLICY> int
39 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::open (void *)
41 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::open");
42 return 0;
45 template <ACE_SYNCH_DECL, class TIME_POLICY> int
46 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::close (u_long)
48 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::close");
49 return 0;
52 template <ACE_SYNCH_DECL, class TIME_POLICY> int
53 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::svc ()
55 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::svc");
56 return -1;
59 template <ACE_SYNCH_DECL, class TIME_POLICY> int
60 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::control (ACE_Message_Block *mb)
62 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::control");
63 ACE_IO_Cntl_Msg *ioc = (ACE_IO_Cntl_Msg *) mb->rd_ptr ();
64 ACE_IO_Cntl_Msg::ACE_IO_Cntl_Cmds cmd;
66 switch (cmd = ioc->cmd ())
68 case ACE_IO_Cntl_Msg::SET_LWM:
69 case ACE_IO_Cntl_Msg::SET_HWM:
70 this->water_marks (cmd, *(size_t *) mb->cont ()->rd_ptr ());
71 ioc->rval (0);
72 break;
73 default:
74 return 0;
76 return ioc->rval ();
79 // Performs canonical flushing at the ACE_Stream Head.
81 template <ACE_SYNCH_DECL, class TIME_POLICY> int
82 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::canonical_flush (ACE_Message_Block *mb)
84 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::canonical_flush");
85 char *cp = mb->rd_ptr ();
87 if (ACE_BIT_ENABLED (*cp, ACE_Task_Flags::ACE_FLUSHR))
89 this->flush (ACE_Task_Flags::ACE_FLUSHALL);
90 ACE_CLR_BITS (*cp, ACE_Task_Flags::ACE_FLUSHR);
93 if (ACE_BIT_ENABLED (*cp, ACE_Task_Flags::ACE_FLUSHW))
94 return this->reply (mb);
95 else
96 mb->release ();
97 return 0;
100 template <ACE_SYNCH_DECL, class TIME_POLICY> int
101 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::put (ACE_Message_Block *mb,
102 ACE_Time_Value *tv)
104 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::put");
105 int res = 0;
107 if (mb->msg_type () == ACE_Message_Block::MB_IOCTL
108 && (res = this->control (mb)) == -1)
109 return res;
111 if (this->is_writer ())
112 return this->put_next (mb, tv);
113 else // this->is_reader ()
115 switch (mb->msg_type ())
117 case ACE_Message_Block::MB_FLUSH:
118 return this->canonical_flush (mb);
119 default:
120 break;
123 return this->putq (mb, tv);
127 template <ACE_SYNCH_DECL, class TIME_POLICY> int
128 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::init (int, ACE_TCHAR *[])
130 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::init");
131 return 0;
134 template <ACE_SYNCH_DECL, class TIME_POLICY> int
135 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::info (ACE_TCHAR **strp, size_t length) const
137 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::info");
138 const ACE_TCHAR *name = this->name ();
140 if (*strp == 0 && (*strp = ACE_OS::strdup (name)) == 0)
141 return -1;
142 else
143 ACE_OS::strsncpy (*strp, name, length);
144 return static_cast<int> (ACE_OS::strlen (name));
147 template <ACE_SYNCH_DECL, class TIME_POLICY> int
148 ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::fini ()
150 ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE, TIME_POLICY>::fini");
151 return 0;
154 ACE_ALLOC_HOOK_DEFINE_Tyc(ACE_Stream_Tail)
156 template <ACE_SYNCH_DECL, class TIME_POLICY>
157 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::ACE_Stream_Tail ()
159 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::ACE_Stream_Tail");
162 template <ACE_SYNCH_DECL, class TIME_POLICY>
163 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::~ACE_Stream_Tail ()
165 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::~ACE_Stream_Tail");
168 template <ACE_SYNCH_DECL, class TIME_POLICY> void
169 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::dump () const
171 #if defined (ACE_HAS_DUMP)
172 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::dump");
173 #endif /* ACE_HAS_DUMP */
176 template <ACE_SYNCH_DECL, class TIME_POLICY> int
177 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::open (void *)
179 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::open");
180 return 0;
183 template <ACE_SYNCH_DECL, class TIME_POLICY> int
184 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::close (u_long)
186 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::close");
187 return 0;
190 template <ACE_SYNCH_DECL, class TIME_POLICY> int
191 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::svc ()
193 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::svc");
194 return -1;
197 template <ACE_SYNCH_DECL, class TIME_POLICY> int
198 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::control (ACE_Message_Block *mb)
200 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::control");
201 ACE_IO_Cntl_Msg *ioc = (ACE_IO_Cntl_Msg *) mb->rd_ptr ();
202 ACE_IO_Cntl_Msg::ACE_IO_Cntl_Cmds cmd;
204 switch (cmd = ioc->cmd ())
206 case ACE_IO_Cntl_Msg::SET_LWM:
207 case ACE_IO_Cntl_Msg::SET_HWM:
209 size_t wm_size = *(size_t *) mb->cont ()->rd_ptr ();
211 this->water_marks (cmd, wm_size);
212 this->sibling ()->water_marks (cmd, wm_size);
213 ioc->rval (0);
214 break;
216 default:
217 mb->msg_type (ACE_Message_Block::MB_IOCNAK);
218 break;
220 return this->reply (mb);
223 // Perform flush algorithm as though we were the driver.
225 template <ACE_SYNCH_DECL, class TIME_POLICY> int
226 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::canonical_flush (ACE_Message_Block *mb)
228 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::canonical_flush");
229 char *cp = mb->rd_ptr ();
231 if (ACE_BIT_ENABLED (*cp, ACE_Task_Flags::ACE_FLUSHW))
233 this->flush (ACE_Task_Flags::ACE_FLUSHALL);
234 ACE_CLR_BITS (*cp, ACE_Task_Flags::ACE_FLUSHW);
237 if (ACE_BIT_ENABLED (*cp, ACE_Task_Flags::ACE_FLUSHR))
239 this->sibling ()->flush (ACE_Task_Flags::ACE_FLUSHALL);
240 return this->reply (mb);
242 else
243 mb->release ();
245 return 0;
248 template <ACE_SYNCH_DECL, class TIME_POLICY> int
249 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::put (ACE_Message_Block *mb,
250 ACE_Time_Value *)
252 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::put");
254 if (this->is_writer ())
256 switch (mb->msg_type ())
258 case ACE_Message_Block::MB_IOCTL:
259 return this->control (mb);
260 /* NOTREACHED */
261 default:
262 mb->release ();
263 return 0;
264 /* NOTREACHED */
268 return -1;
271 template <ACE_SYNCH_DECL, class TIME_POLICY> int
272 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::init (int, ACE_TCHAR *[])
274 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::init");
275 return 0;
278 template <ACE_SYNCH_DECL, class TIME_POLICY> int
279 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::info (ACE_TCHAR **strp, size_t length) const
281 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::info");
282 const ACE_TCHAR *name = this->name ();
284 if (*strp == 0 && (*strp = ACE_OS::strdup (name)) == 0)
285 return -1;
286 else
287 ACE_OS::strsncpy (*strp, name, length);
288 return static_cast<int> (ACE_OS::strlen (name));
291 template <ACE_SYNCH_DECL, class TIME_POLICY> int
292 ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::fini ()
294 ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::fini");
295 return 0;
298 ACE_ALLOC_HOOK_DEFINE_Tyc(ACE_Thru_Task)
300 template <ACE_SYNCH_DECL, class TIME_POLICY>
301 ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::ACE_Thru_Task ()
303 ACE_TRACE ("ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::ACE_Thru_Task");
306 template <ACE_SYNCH_DECL, class TIME_POLICY>
307 ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::~ACE_Thru_Task ()
309 ACE_TRACE ("ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::~ACE_Thru_Task");
312 template <ACE_SYNCH_DECL, class TIME_POLICY> void
313 ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::dump () const
315 #if defined (ACE_HAS_DUMP)
316 ACE_TRACE ("ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::dump");
317 #endif /* ACE_HAS_DUMP */
320 template <ACE_SYNCH_DECL, class TIME_POLICY> int
321 ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::open (void *)
323 ACE_TRACE ("ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::open");
324 return 0;
327 template <ACE_SYNCH_DECL, class TIME_POLICY> int
328 ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::close (u_long)
330 ACE_TRACE ("ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::close");
331 return 0;
334 template <ACE_SYNCH_DECL, class TIME_POLICY> int
335 ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::svc ()
337 ACE_TRACE ("ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::svc");
338 return -1;
341 template <ACE_SYNCH_DECL, class TIME_POLICY> int
342 ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::put (ACE_Message_Block *msg,
343 ACE_Time_Value *tv)
345 ACE_TRACE ("ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::put");
346 return this->put_next (msg, tv);
349 template <ACE_SYNCH_DECL, class TIME_POLICY> int
350 ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::init (int, ACE_TCHAR *[])
352 ACE_TRACE ("ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::init");
353 return 0;
356 template <ACE_SYNCH_DECL, class TIME_POLICY> int
357 ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::info (ACE_TCHAR **strp,
358 size_t length) const
360 ACE_TRACE ("ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::info");
361 const ACE_TCHAR *name = this->name ();
363 if (*strp == 0 && (*strp = ACE_OS::strdup (name)) == 0)
364 return -1;
365 else
366 ACE_OS::strsncpy (*strp, name, length);
367 return static_cast<int> (ACE_OS::strlen (name));
370 template <ACE_SYNCH_DECL, class TIME_POLICY> int
371 ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::fini ()
373 ACE_TRACE ("ACE_Thru_Task<ACE_SYNCH_USE, TIME_POLICY>::fini");
374 return 0;
377 ACE_END_VERSIONED_NAMESPACE_DECL
379 #endif /* ACE_STREAM_MODULES_CPP */