The SGIOChannel base class provides a consistent method for applications to communication through various mediums. More...
#include <iochannel.hxx>
Public Member Functions | |
SGIOChannel () | |
Constructor. | |
virtual | ~SGIOChannel () |
Destructor. | |
virtual bool | open (const SGProtocolDir d) |
Open a channel. | |
virtual int | read (char *buf, int length) |
The read() method is modeled after the read() Unix system call. | |
virtual int | readline (char *buf, int length) |
The readline() method is similar to read() except that it will stop at the first end of line encountered in the input buffer. | |
virtual int | write (const char *buf, const int length) |
The write() method is modeled after the write() Unix system call and is analogous to the read() method. | |
virtual int | writestring (const char *str) |
The writestring() method is a simple wrapper that will calculate the length of a null terminated character array and write it to the output channel. | |
virtual bool | close () |
The close() method is modeled after the close() Unix system call and will close an open device. | |
virtual bool | eof () |
The eof() method returns true if end of file has been reached in a context where that makes sense. |
The SGIOChannel base class provides a consistent method for applications to communication through various mediums.
By providing a base class with multiple derived classes, and application such as FlightGear can implement a way to speak any protocol via any kind of I/O channel.
All of the SGIOChannel derived classes have exactly the same usage interface once an instance has been created.
Definition at line 76 of file iochannel.hxx.
bool SGIOChannel::close | ( | ) | [virtual] |
The close() method is modeled after the close() Unix system call and will close an open device.
You should call this method when you are done using your IO class, before it is destructed.
Reimplemented in SGFile, SGSerial, SGSocket, and SGSocketUDP.
Definition at line 70 of file iochannel.cxx.
bool SGIOChannel::eof | ( | ) | [virtual] |
The eof() method returns true if end of file has been reached in a context where that makes sense.
Otherwise it returns false.
Definition at line 76 of file iochannel.cxx.
bool SGIOChannel::open | ( | const SGProtocolDir | d | ) | [virtual] |
Open a channel.
d | channel communication "direction" Direction can be one of:
|
Reimplemented in SGFile, SGSerial, SGSocket, and SGSocketUDP.
Definition at line 40 of file iochannel.cxx.
int SGIOChannel::read | ( | char * | buf, | |
int | length | |||
) | [virtual] |
The read() method is modeled after the read() Unix system call.
You must provide a pointer to a character buffer that has enough allocated space for your potential read. You can also specify the maximum number of bytes allowed for this particular read. The actual number of bytes read is returned. You are responsible to ensure that the size of buf is large enough to accomodate your input message
buf | a char pointer to your input buffer | |
length | max number of bytes to read |
Reimplemented in SGFile, SGSerial, SGSocket, and SGSocketUDP.
Definition at line 46 of file iochannel.cxx.
int SGIOChannel::readline | ( | char * | buf, | |
int | length | |||
) | [virtual] |
The readline() method is similar to read() except that it will stop at the first end of line encountered in the input buffer.
buf | a char pointer to your input buffer | |
length | max number of bytes to read |
Reimplemented in SGFile, SGSerial, SGSocket, and SGSocketUDP.
Definition at line 52 of file iochannel.cxx.
int SGIOChannel::write | ( | const char * | buf, | |
const int | length | |||
) | [virtual] |
The write() method is modeled after the write() Unix system call and is analogous to the read() method.
You provide a pointer to a buffer of data, and then length of that data to be written out. The number of bytes written is returned.
buf | a char pointer to your output buffer | |
length | number of bytes to write |
Reimplemented in SGFile, SGSerial, SGSocket, and SGSocketUDP.
Definition at line 58 of file iochannel.cxx.
int SGIOChannel::writestring | ( | const char * | str | ) | [virtual] |
The writestring() method is a simple wrapper that will calculate the length of a null terminated character array and write it to the output channel.
buf | a char pointer to your output buffer |
Reimplemented in SGFile, SGSerial, SGSocket, and SGSocketUDP.
Definition at line 64 of file iochannel.cxx.