Bayonne2 / Common C++ 2 Framework
|
The TTYSession aggragates a TTYStream and a Common C++ Thread which is assumed to be the execution context that will be used to perform actual I/O operations. More...
#include <serial.h>
Public Member Functions | |
TTYSession (const char *name, int pri=0, int stack=0) | |
Create TTY stream that will be managed by it's own thread. More... | |
virtual | ~TTYSession () |
int | start (Semaphore *start=0) |
When a new thread is created, it does not begin immediate execution. More... | |
int | detach (Semaphore *start=0) |
Start a new thread as "detached". More... | |
Thread * | getParent (void) |
Gets the pointer to the Thread class which created the current thread object. More... | |
void | suspend (void) |
Suspends execution of the selected thread. More... | |
void | resume (void) |
Resumes execution of the selected thread. More... | |
Cancel | getCancel (void) |
Used to retrieve the cancellation mode in effect for the selected thread. More... | |
bool | isRunning (void) const |
Verifies if the thread is still running or has already been terminated but not yet deleted. More... | |
bool | isDetached (void) const |
Check if this thread is detached. More... | |
void | join (void) |
Blocking call which unlocks when thread terminates. More... | |
bool | isThread (void) const |
Tests to see if the current execution context is the same as the specified thread object. More... | |
cctid_t | getId (void) const |
Get system thread numeric identifier. More... | |
const char * | getName (void) const |
Get the name string for this thread, to use in debug messages. More... | |
void | setTimeout (timeout_t to) |
Set the timeout control. More... | |
void | interactive (bool flag) |
Set tty mode to buffered or "interactive". More... | |
int | sync (void) |
Flushes the stream input and out buffers, writes pending output. More... | |
bool | isPending (Pending pend, timeout_t timeout=TIMEOUT_INF) |
Get the status of pending operations. More... | |
Error | setSpeed (unsigned long speed) |
Set serial port speed for both input and output. More... | |
Error | setCharBits (int bits) |
Set character size. More... | |
Error | setParity (Parity parity) |
Set parity mode. More... | |
Error | setStopBits (int bits) |
Set number of stop bits. More... | |
Error | setFlowControl (Flow flow) |
Set flow control. More... | |
void | toggleDTR (timeout_t millisec) |
Set the DTR mode off momentarily. More... | |
void | sendBreak (void) |
Send the "break" signal. More... | |
Error | getErrorNumber (void) |
Often used by a "catch" to fetch the last error of a thrown serial. More... | |
char * | getErrorString (void) |
Often used by a "catch" to fetch the user set error string of a thrown serial. More... | |
int | getBufferSize (void) |
Get the "buffer" size for buffered operations. More... | |
Static Public Member Functions | |
static Thread * | get (void) |
static void | setStack (size_t size=0) |
Set base stack limit before manual stack sizes have effect. More... | |
static void | sleep (timeout_t msec) |
A thread-safe sleep call. More... | |
static void | yield (void) |
Yields the current thread's CPU time slice to allow another thread to begin immediate execution. More... | |
static Throw | getException (void) |
Get exception mode of the current thread. More... | |
static void | setException (Throw mode) |
Set exception mode of the current thread. More... | |
static Cancel | enterCancel (void) |
This is used to help build wrapper functions in libraries around system calls that should behave as cancellation points but don't. More... | |
static void | exitCancel (Cancel cancel) |
This is used to restore a cancel block. More... | |
Protected Member Functions | |
void | setName (const char *text) |
Set the name of the current thread. More... | |
virtual void | run (void)=0 |
All threads execute by deriving the Run method of Thread. More... | |
virtual void | final (void) |
A thread that is self terminating, either by invoking exit() or leaving it's run(), will have this method called. More... | |
virtual void | initial (void) |
The initial method is called by a newly created thread when it starts execution. More... | |
virtual void * | getExtended (void) |
Since getParent() and getThread() only refer to an object of the Thread "base" type, this virtual method can be replaced in a derived class with something that returns data specific to the derived class that can still be accessed through the pointer returned by getParent() and getThread(). More... | |
virtual void | notify (Thread *) |
When a thread terminates, it now sends a notification message to the parent thread which created it. More... | |
void | exit (void) |
Used to properly exit from a Thread derived run() or initial() method. More... | |
void | sync (void) |
Used to wait for a join or cancel, in place of explicit exit. More... | |
bool | testCancel (void) |
test a cancellation point for deferred thread cancellation. More... | |
void | setCancel (Cancel mode) |
Sets thread cancellation mode. More... | |
void | setSuspend (Suspend mode) |
Sets the thread's ability to be suspended from execution. More... | |
void | terminate (void) |
Used by another thread to terminate the current thread. More... | |
void | clrParent (void) |
clear parent thread relationship. More... | |
void | allocate (void) |
Used to allocate the buffer space needed for iostream operations. More... | |
void | endStream (void) |
Used to terminate the buffer space and clean up the tty connection. More... | |
int | underflow (void) |
This streambuf method is used to load the input buffer through the established tty serial port. More... | |
int | uflow (void) |
This streambuf method is used for doing unbuffered reads through the establish tty serial port when in interactive mode. More... | |
int | overflow (int ch) |
This streambuf method is used to write the output buffer through the established tty port. More... | |
void | open (const char *fname) |
Opens the serial device. More... | |
void | close (void) |
Closes the serial device. More... | |
virtual int | aRead (char *Data, const int Length) |
Reads from serial device. More... | |
virtual int | aWrite (const char *Data, const int Length) |
Writes to serial device. More... | |
Error | error (Error error, char *errstr=NULL) |
This service is used to throw all serial errors which usually occur during the serial constructor. More... | |
void | error (char *err) |
This service is used to thow application defined serial errors where the application specific error code is a string. More... | |
void | setError (bool enable) |
This method is used to turn the error handler on or off for "throwing" execptions by manipulating the thrown flag. More... | |
int | setPacketInput (int size, unsigned char btimer=0) |
Set packet read mode and "size" of packet read buffer. More... | |
int | setLineInput (char newline=13, char nl1=0) |
Set "line buffering" read mode and specifies the newline character to be used in seperating line records. More... | |
void | restore (void) |
Restore serial device to the original settings at time of open. More... | |
void | flushInput (void) |
Used to flush the input waiting queue. More... | |
void | flushOutput (void) |
Used to flush any pending output data. More... | |
void | waitOutput (void) |
Used to wait until all output has been sent. More... | |
void | endSerial (void) |
Used as the default destructor for ending serial I/O services. More... | |
void | initConfig (void) |
Used to initialize a newly opened serial file handle. More... | |
Protected Attributes | |
char * | gbuf |
char * | pbuf |
timeout_t | timeout |
HANDLE | dev |
int | bufsize |
The TTYSession aggragates a TTYStream and a Common C++ Thread which is assumed to be the execution context that will be used to perform actual I/O operations.
This class is very anagolous to TCPSession.
|
inherited |
How work cancellation.
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
How work suspend.
|
inherited |
How to raise error.
|
inherited |
How work cancellation.
Enumerator | |
---|---|
cancelInitial |
used internally, do not use |
cancelDeferred |
exit thread on cancellation pointsuch as yield |
cancelImmediate |
exit befor cancellation |
cancelDisabled |
ignore cancellation |
cancelManual |
unimplemented (working in progress)
|
cancelDefault |
default you should use this for compatibility instead of deferred |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
TTYSession::TTYSession | ( | const char * | name, |
int | pri = 0 , |
||
int | stack = 0 |
||
) |
Create TTY stream that will be managed by it's own thread.
name | of tty device to open. |
pri | execution priority. |
stack | allocation needed on some platforms. |
|
virtual |
|
protectedinherited |
Used to allocate the buffer space needed for iostream operations.
This is based on MAX_INPUT.
|
protectedvirtualinherited |
Reads from serial device.
Data | Point to character buffer to receive data. Buffers MUST be at least Length + 1 bytes in size. |
Length | Number of bytes to read. |
|
protectedvirtualinherited |
Writes to serial device.
Data | Point to character buffer containing data to write. Buffers MUST |
Length | Number of bytes to write. |
|
protectedinherited |
Closes the serial device.
|
inlineprotectedinherited |
|
inherited |
Start a new thread as "detached".
This is an alternative start() method that resolves some issues with later glibc implimentations which incorrectly impliment self-detach.
start | optional starting semaphore to alternately use. |
|
protectedinherited |
Used as the default destructor for ending serial I/O services.
It will restore the port to it's original state.
|
protectedinherited |
Used to terminate the buffer space and clean up the tty connection.
This function is called by the destructor.
|
staticinherited |
This is used to help build wrapper functions in libraries around system calls that should behave as cancellation points but don't.
This service is used to throw all serial errors which usually occur during the serial constructor.
error | defined serial error id. |
errstr | string or message to optionally pass. |
|
inlineprotectedinherited |
|
protectedinherited |
|
staticinherited |
This is used to restore a cancel block.
cancel | type that was saved. |
|
protectedvirtualinherited |
A thread that is self terminating, either by invoking exit() or leaving it's run(), will have this method called.
It can be used to self delete the current object assuming the object was created with new on the heap rather than stack local, hence one may often see final defined as "delete this" in a derived thread class. A final method, while running, cannot be terminated or cancelled by another thread. Final is called for all cancellation type (even immediate).
You can safe delete thread ("delete this") class on final, but you should exit ASAP (or do not try to call CommonC++ methods...)
Reimplemented in ThreadQueue.
|
protectedinherited |
Used to flush the input waiting queue.
|
protectedinherited |
Used to flush any pending output data.
|
staticinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
staticinherited |
Get exception mode of the current thread.
|
protectedvirtualinherited |
Since getParent() and getThread() only refer to an object of the Thread "base" type, this virtual method can be replaced in a derived class with something that returns data specific to the derived class that can still be accessed through the pointer returned by getParent() and getThread().
|
inherited |
Get system thread numeric identifier.
|
inlineinherited |
|
inlineinherited |
|
protectedinherited |
Used to initialize a newly opened serial file handle.
You should set serial properties and DTR manually before first use.
|
protectedvirtualinherited |
The initial method is called by a newly created thread when it starts execution.
This method is ran with deferred cancellation disabled by default. The Initial method is given a separate handler so that it can create temporary objects on it's own stack frame, rather than having objects created on run() that are only needed by startup and yet continue to consume stack space.
Reimplemented in TCPSession, and UnixSession.
|
inherited |
Set tty mode to buffered or "interactive".
When interactive, all streamed I/O is directly sent to the serial port immediately.
flag | bool set to true to make interactive. |
|
inherited |
Check if this thread is detached.
|
virtualinherited |
Get the status of pending operations.
This can be used to examine if input or output is waiting, or if an error has occured on the serial device. If read buffer contains data then input is ready and if write buffer contains data it is first flushed then checked.
pend | ready check to perform. |
timeout | in milliseconds. |
Reimplemented from Serial.
|
inherited |
Verifies if the thread is still running or has already been terminated but not yet deleted.
|
inherited |
Tests to see if the current execution context is the same as the specified thread object.
|
inherited |
Blocking call which unlocks when thread terminates.
|
protectedvirtualinherited |
When a thread terminates, it now sends a notification message to the parent thread which created it.
The actual use of this notification is left to be defined in a derived class.
- | the thread that has terminated. |
|
protectedinherited |
Opens the serial device.
fname | Pathname of device to open |
|
protectedinherited |
This streambuf method is used to write the output buffer through the established tty port.
ch | char to push through. |
|
protectedinherited |
Restore serial device to the original settings at time of open.
|
inherited |
Resumes execution of the selected thread.
|
protectedpure virtualinherited |
All threads execute by deriving the Run method of Thread.
This method is called after Initial to begin normal operation of the thread. If the method terminates, then the thread will also terminate after notifying it's parent and calling it's Final() method.
Implemented in SerialService, SingleThreadRTPSession< RTPDataChannel, RTCPChannel, ServiceQueue >, SocketService, ThreadQueue, and SingleRTPSessionPool.
|
inherited |
Send the "break" signal.
|
protectedinherited |
Sets thread cancellation mode.
Threads can either be set immune to termination (cancelDisabled), can be set to terminate when reaching specific "thread cancellation points" (cancelDeferred) or immediately when Terminate is requested (cancelImmediate).
mode | for cancellation of the current thread. |
|
inherited |
Set character size.
bits | character size to use (usually 7 or 8). |
|
inlineprotectedinherited |
|
staticinherited |
Set exception mode of the current thread.
Set flow control.
flow | control mode. |
|
protectedinherited |
Set "line buffering" read mode and specifies the newline character to be used in seperating line records.
isPending can then be used to wait for an entire line of input.
newline | newline character. |
nl1 | EOL2 control character. |
|
protectedinherited |
Set the name of the current thread.
If the name is passed as NULL, then the default name is set (usually object pointer).
text | name to use. |
|
protectedinherited |
Set packet read mode and "size" of packet read buffer.
This sets VMIN to x. VTIM is normally set to "0" so that "isPending()" can wait for an entire packet rather than just the first byte.
size | of packet read request. |
btimer | optional inter-byte data packet timeout. |
Set parity mode.
parity | mode. |
|
inherited |
Set serial port speed for both input and output.
speed | to select. 0 signifies modem "hang up". |
|
inlinestaticinherited |
|
inherited |
Set number of stop bits.
bits | stop bits. |
|
protectedinherited |
Sets the thread's ability to be suspended from execution.
The thread may either have suspend enabled (suspendEnable) or disabled (suspendDisable).
mode | for suspend. |
|
inlineinherited |
|
staticinherited |
A thread-safe sleep call.
On most Posix systems, "sleep()" is implimented with SIGALRM making it unusable from multipe threads. Pthread libraries often define an alternate "sleep" handler such as usleep(), nanosleep(), or nap(), that is thread safe, and also offers a higher timer resolution.
msec | timeout in milliseconds. |
|
inherited |
When a new thread is created, it does not begin immediate execution.
This is because the derived class virtual tables are not properly loaded at the time the C++ object is created within the constructor itself, at least in some compiler/system combinations. The thread can either be told to wait for an external semaphore, or it can be started directly after the constructor completes by calling the start() method.
start | optional starting semaphore to alternately use. |
|
inherited |
Suspends execution of the selected thread.
Pthreads do not normally support suspendable threads, so the behavior is simulated with signals. On systems such as Linux that define threads as processes, SIGSTOP and SIGCONT may be used.
|
inherited |
Flushes the stream input and out buffers, writes pending output.
|
protectedinherited |
Used to wait for a join or cancel, in place of explicit exit.
|
protectedinherited |
Used by another thread to terminate the current thread.
Termination actually occurs based on the current setCancel() mode. When the current thread does terminate, control is returned to the requesting thread. terminate() should always be called at the start of any destructor of a class derived from Thread to assure the remaining part of the destructor is called without the thread still executing.
|
protectedinherited |
test a cancellation point for deferred thread cancellation.
|
inherited |
Set the DTR mode off momentarily.
millisec | number of milliseconds. |
|
protectedinherited |
This streambuf method is used for doing unbuffered reads through the establish tty serial port when in interactive mode.
Also this method will handle proper use of buffers if not in interative mode.
|
protectedinherited |
This streambuf method is used to load the input buffer through the established tty serial port.
|
protectedinherited |
Used to wait until all output has been sent.
|
staticinherited |
Yields the current thread's CPU time slice to allow another thread to begin immediate execution.