PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
indchan.h
Go to the documentation of this file.
1 /*
2  * indchan.h
3  *
4  * Indirect I/O channel class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  */
29 
30 #ifndef PTLIB_INDIRECTCHANNEL_H
31 #define PTLIB_INDIRECTCHANNEL_H
32 
33 #ifdef P_USE_PRAGMA
34 #pragma interface
35 #endif
36 
37 #include <ptlib/channel.h>
38 #include <ptlib/syncthrd.h>
39 
45 class PIndirectChannel : public PChannel
46 {
47  PCLASSINFO(PIndirectChannel, PChannel);
48 
49  public:
57 
61 
62 
72  const PObject & obj
73  ) const;
75 
76 
86  virtual PString GetName() const;
87 
93  virtual P_INT_PTR GetHandle() const;
94 
101  virtual PBoolean Close();
102 
110  virtual PBoolean IsOpen() const;
111 
127  virtual PBoolean Read(
128  void * buf,
129  PINDEX len
130  );
131 
143  virtual int ReadChar();
144 
159  virtual PBoolean Write(
160  const void * buf,
161  PINDEX len
162  );
163 
172  virtual PBoolean Shutdown(
173  ShutdownValue option
174  );
175 
183  virtual bool SetLocalEcho(
184  bool localEcho
185  );
186 
187 
196  virtual PChannel * GetBaseReadChannel() const;
197 
206  virtual PChannel * GetBaseWriteChannel() const;
207 
215  virtual bool CloseBaseReadChannel();
216 
224  virtual bool CloseBaseWriteChannel();
225 
231  virtual PString GetErrorText(
232  ErrorGroup group = NumErrorGroups
233  ) const;
235 
245  PBoolean Open(
246  PChannel & channel
247  );
248 
259  PBoolean Open(
260  PChannel * channel,
261  PBoolean autoDelete = true
262  );
263 
275  PBoolean Open(
278  PBoolean autoDeleteRead = true,
279  PBoolean autoDeleteWrite = true
280  );
281 
289  PChannel * Detach(
291  );
292 
298  PChannel * GetReadChannel() const;
299 
305  bool SetReadChannel(
306  PChannel * channel,
307  bool autoDelete = true,
308  bool closeExisting = false
309  );
310 
316  PChannel * GetWriteChannel() const;
317 
324  PChannel * channel,
325  bool autoDelete = true,
326  bool closeExisting = false
327  );
328 
331  template <class ChannelClass> ChannelClass * FindChannel()
332  {
333  ChannelClass * channel = dynamic_cast<ChannelClass *>(this);
334  if (channel == NULL) {
335  PIndirectChannel * indirect = dynamic_cast<PIndirectChannel *>(readChannel);
336  if (indirect == NULL || (channel = indirect->FindChannel<ChannelClass>()) == NULL) {
337  indirect = dynamic_cast<PIndirectChannel *>(writeChannel);
338  if (indirect != NULL)
339  channel = indirect->FindChannel<ChannelClass>();
340  }
341  }
342  return channel;
343  }
345 
346 
347  protected:
357  virtual PBoolean OnOpen();
358 
359 
360  // Member variables
363 
366 
369 
372 
374  PDECLARE_READ_WRITE_MUTEX(channelPointerMutex);
375 };
376 
377 
378 #endif // PTLIB_INDIRECTCHANNEL_H
379 
380 
381 // End Of File ///////////////////////////////////////////////////////////////
Definition: channel.h:255
PChannel * Detach(ShutdownValue option=ShutdownReadAndWrite)
Detach without closing the read/write channel.
virtual PString GetErrorText(ErrorGroup group=NumErrorGroups) const
Get error message description.
ChannelClass * FindChannel()
Locate a channel of a specific class in the indirect chain.
Definition: indchan.h:331
virtual PString GetName() const
Get the name of the channel.
PBoolean readAutoDelete
Automatically delete read channel on destruction.
Definition: indchan.h:365
virtual int ReadChar()
Read a single character from the channel.
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:2251
virtual PBoolean IsOpen() const
Determine if the channel is currently open and read and write operations can be executed on it...
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:45
PChannel * readChannel
Channel for read operations.
Definition: indchan.h:362
virtual PBoolean Shutdown(ShutdownValue option)
Close one or both of the data streams associated with a channel.
ShutdownValue
Definition: channel.h:589
PChannel * GetReadChannel() const
Get the channel used for read operations.
virtual PChannel * GetBaseWriteChannel() const
This function returns the eventual base channel for writing of a series of indirect channels provided...
PChannel * GetWriteChannel() const
Get the channel used for write operations.
PChannel * writeChannel
Channel for write operations.
Definition: indchan.h:368
Definition: channel.h:592
Abstract class defining I/O channel semantics.
Definition: channel.h:103
PDECLARE_READ_WRITE_MUTEX(channelPointerMutex)
Race condition prevention on closing channel.
virtual PBoolean Close()
Close the channel.
bool PBoolean
Definition: object.h:174
virtual PChannel * GetBaseReadChannel() const
This function returns the eventual base channel for reading of a series of indirect channels provided...
intptr_t P_INT_PTR
Definition: object.h:2646
PIndirectChannel()
Create a new indirect channel without any channels to redirect to.
The character string class.
Definition: pstring.h:108
PBoolean Open(PChannel &channel)
Set the channel for both read and write operations.
Comparison Compare(const PObject &obj) const
Determine if the two objects refer to the same indirect channel.
PBoolean writeAutoDelete
Automatically delete write channel on destruction.
Definition: indchan.h:371
virtual P_INT_PTR GetHandle() const
Get the OS specific handle for the PSoundChannel.
ErrorGroup
Error groups.
Definition: channel.h:251
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
virtual PBoolean OnOpen()
This callback is executed when the Open() function is called with open channels.
virtual bool SetLocalEcho(bool localEcho)
Set local echo mode.
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
bool SetReadChannel(PChannel *channel, bool autoDelete=true, bool closeExisting=false)
Set the channel for read operations.
virtual bool CloseBaseReadChannel()
Close the base channel of channel indirection using PIndirectChannel.
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
PBoolean SetWriteChannel(PChannel *channel, bool autoDelete=true, bool closeExisting=false)
Set the channel for read operations.
virtual bool CloseBaseWriteChannel()
Close the base channel of channel indirection using PIndirectChannel.
~PIndirectChannel()
Close the indirect channel, deleting read/write channels if desired.