PTLib
Version 2.14.3
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
channel.h
Go to the documentation of this file.
1
/*
2
* channel.h
3
*
4
* I/O channel ancestor 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
* $Revision: 32474 $
30
* $Author: rjongbloed $
31
* $Date: 2014-08-09 14:23:47 +1000 (Sat, 09 Aug 2014) $
32
*/
33
34
#ifndef PTLIB_CHANNEL_H
35
#define PTLIB_CHANNEL_H
36
37
#ifdef P_USE_PRAGMA
38
#pragma interface
39
#endif
40
41
#include <
ptlib/mutex.h
>
42
44
// I/O Channels
45
46
class
PChannel
;
47
48
/* Buffer class used in PChannel stream.
49
This class is necessary for implementing the standard C++ iostream interface
50
on <code>PChannel</code> classes and its descendents. It is an internal class and
51
should not ever be used by application writers.
52
*/
53
class
PChannelStreamBuffer
:
public
streambuf {
54
55
protected
:
56
/* Construct the streambuf for standard streams on a channel. This is used
57
internally by the <code>PChannel</code> class.
58
*/
59
PChannelStreamBuffer
(
60
PChannel
* chan
// Channel the buffer operates on.
61
);
62
63
virtual
int_type
overflow
(int_type = EOF);
64
virtual
int_type
underflow
();
65
virtual
int
sync
();
66
virtual
pos_type
seekoff
(std::streamoff, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out);
67
virtual
pos_type
seekpos
(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
68
69
PBoolean
SetBufferSize
(
70
PINDEX newSize
71
);
72
73
private
:
74
// Member variables
75
PChannel
* channel;
76
PCharArray
input, output;
77
78
public
:
79
PChannelStreamBuffer
(
const
PChannelStreamBuffer
& sbuf);
80
PChannelStreamBuffer
&
operator=
(
const
PChannelStreamBuffer
& sbuf);
81
82
friend
class
PChannel
;
83
};
84
85
107
class
PChannel
:
public
PObject
,
public
std::iostream
108
{
109
PCLASSINFO(
PChannel
,
PObject
);
110
113
protected
:
115
PChannel
();
116
117
public
:
119
~PChannel
();
121
133
virtual
Comparison
Compare
(
134
const
PObject
& obj
135
)
const
;
136
150
virtual
PINDEX
HashFunction
()
const
;
152
162
virtual
PBoolean
IsOpen
()
const
;
163
169
virtual
PString
GetName
()
const
{
return
channelName
; }
170
176
virtual
P_INT_PTR
GetHandle
()
const
;
177
183
FILE *
FDOpen
(
const
char
* mode);
184
194
virtual
PChannel
*
GetBaseReadChannel
()
const
;
195
205
virtual
PChannel
*
GetBaseWriteChannel
()
const
;
207
213
enum
Errors
{
214
NoError
,
215
NotFound
,
216
FileExists
,
217
DiskFull
,
218
AccessDenied
,
219
DeviceInUse
,
220
BadParameter
,
221
NoMemory
,
222
NotOpen
,
223
Timeout
,
224
Interrupted
,
225
BufferTooSmall
,
226
Miscellaneous
,
227
ProtocolFailure
,
228
Unavailable
,
229
NumNormalisedErrors
230
};
231
237
enum
ErrorGroup
{
238
LastReadError
,
239
LastWriteError
,
240
LastGeneralError
,
241
NumErrorGroups
242
};
243
248
Errors
GetErrorCode
(
249
ErrorGroup
group =
NumErrorGroups
250
)
const
;
251
257
int
GetErrorNumber
(
258
ErrorGroup
group =
NumErrorGroups
259
)
const
;
260
266
virtual
PString
GetErrorText
(
267
ErrorGroup
group =
NumErrorGroups
268
)
const
;
269
276
static
PString
GetErrorText
(
277
Errors
lastError,
278
int
osError = 0
279
);
281
291
void
SetReadTimeout
(
292
const
PTimeInterval
& time
293
);
294
301
PTimeInterval
GetReadTimeout
()
const
;
302
315
virtual
PBoolean
Read
(
316
void
* buf,
317
PINDEX len
318
);
319
334
PINDEX
GetLastReadCount
()
const
;
335
347
virtual
int
ReadChar
();
348
357
PBoolean
ReadBlock
(
358
void
* buf,
359
PINDEX len
360
);
361
369
PString
ReadString
(
370
PINDEX len
371
);
373
383
void
SetWriteTimeout
(
384
const
PTimeInterval
& time
385
);
386
394
PTimeInterval
GetWriteTimeout
()
const
;
395
407
virtual
PBoolean
Write
(
408
const
void
* buf,
409
PINDEX len
410
);
411
424
virtual
PBoolean
Write
(
425
const
void
* buf,
426
PINDEX len,
427
const
void
*
/*mark*/
428
) {
return
Write
(buf,len); }
429
430
443
virtual
PINDEX
GetLastWriteCount
()
const
;
444
453
PBoolean
WriteChar
(
int
c);
454
461
PBoolean
WriteString
(
462
const
PString
& str
463
);
465
468
class
AsyncContext
;
469
typedef
PNotifierTemplate<PChannel::AsyncContext &>
AsyncNotifier
;
470
#define PDECLARE_AsyncNotifier(cls, fn) PDECLARE_NOTIFIER2(PChannel, cls, fn, PChannel::AsyncContext &)
471
#define PCREATE_AsyncNotifier(fn) PCREATE_NOTIFIER2(fn, PChannel::AsyncContext &)
472
475
#ifdef _WIN32
476
typedef
OVERLAPPED AsyncContextBase;
477
#elif defined _AIO_H
478
typedef
struct
aiocb AsyncContextBase;
479
#else
480
class
AsyncContextBase
{ off_t m_offset; };
481
#endif
482
class
AsyncContext
:
public
AsyncContextBase
483
{
484
public
:
485
AsyncContext
(
486
void
* buf = NULL,
487
PINDEX len = 0,
488
const
AsyncNotifier
& notifier =
AsyncNotifier
()
489
);
490
493
void
SetOffset
(off_t offset);
494
495
void
*
m_buffer
;
496
PINDEX
m_length
;
497
AsyncNotifier
m_notifier
;
498
499
Errors
m_errorCode
;
500
int
m_errorNumber
;
501
502
// Internal stuff
503
PChannel
*
m_channel
;
504
typedef
void (
PChannel
::*
CompletionFunction
)(
AsyncContext
&);
505
P_ALIGN_FIELD
(
CompletionFunction
,m_onComplete,16);
506
bool
Initialise
(
PChannel
* channel,
CompletionFunction
onComplete);
507
void
OnIOComplete
(PINDEX length,
int
errorNumber);
508
};
509
523
virtual
bool
ReadAsync
(
524
AsyncContext
& context
525
);
526
532
virtual
void
OnReadComplete
(
533
AsyncContext
& context
534
);
535
549
virtual
bool
WriteAsync
(
550
AsyncContext
& context
551
);
552
558
virtual
void
OnWriteComplete
(
559
AsyncContext
& context
560
);
562
569
virtual
PBoolean
Close
();
570
571
enum
ShutdownValue
{
572
ShutdownRead
= 0,
573
ShutdownWrite
= 1,
574
ShutdownReadAndWrite
= 2
575
};
576
584
virtual
PBoolean
Shutdown
(
585
ShutdownValue
option
586
);
587
595
virtual
bool
SetLocalEcho
(
596
bool
localEcho
597
);
598
602
virtual
bool
FlowControl
(
const
void
* flowData);
603
609
PBoolean
SetBufferSize
(
610
PINDEX newSize
611
);
612
651
PBoolean
SendCommandString
(
652
const
PString
& command
653
);
654
659
void
AbortCommandString
();
661
662
protected
:
663
PChannel
(
const
PChannel
&);
664
PChannel
&
operator=
(
const
PChannel
&);
665
// Prevent usage by external classes
666
667
674
virtual
PBoolean
ConvertOSError
(
675
P_INT_PTR
libcReturnValue,
676
ErrorGroup
group =
LastGeneralError
677
);
678
679
public
:
683
PBoolean
SetErrorValues
(
684
Errors
errorCode,
685
int
osError,
686
ErrorGroup
group =
LastGeneralError
687
);
688
689
protected
:
698
int
ReadCharWithTimeout
(
699
PTimeInterval
& timeout
// Timeout for read.
700
);
701
702
// Receive a (partial) command string, determine if completed yet.
703
PBoolean
ReceiveCommandString
(
704
int
nextChar,
705
const
PString
& reply,
706
PINDEX & pos,
707
PINDEX start
708
);
709
710
virtual
int
os_errno
()
const
;
711
712
// Member variables
714
P_INT_PTR
os_handle
;
715
717
Errors
lastErrorCode
[
NumErrorGroups
+1];
719
int
lastErrorNumber
[
NumErrorGroups
+1];
721
PINDEX
lastReadCount
;
723
PINDEX
lastWriteCount
;
725
PTimeInterval
readTimeout
;
727
PTimeInterval
writeTimeout
;
729
PString
channelName
;
730
731
private
:
732
// New functions for class
733
void
Construct();
734
// Complete platform dependent construction.
735
736
// Member variables
737
PBoolean
abortCommandString;
738
// Flag to abort the transmission of a command in SendCommandString().
739
740
741
// Include platform dependent part of class
742
#ifdef _WIN32
743
#include "msos/ptlib/channel.h"
744
#else
745
#include "unix/ptlib/channel.h"
746
#endif
747
748
};
749
750
753
class
PNullChannel
:
public
PChannel
754
{
755
PCLASSINFO
(
PNullChannel
,
PChannel
)
756
public
:
757
PNullChannel
();
758
759
PBoolean
Read
(
void
*, PINDEX);
760
PBoolean
Write
(
const
void
*, PINDEX);
761
};
762
763
764
#endif // PTLIB_CHANNEL_H
765
766
767
// End Of File ///////////////////////////////////////////////////////////////
include
ptlib
channel.h
Generated on Fri Oct 10 2014 21:15:12 for PTLib by
1.8.3.1