GNU CommonC++
Public Member Functions | Protected Member Functions | Friends | List of all members
ost::SerialService Class Reference

The SerialService is a thead service object that is meant to service attached serial ports. More...

#include <serial.h>

Inheritance diagram for ost::SerialService:
ost::Thread ost::Mutex

Public Member Functions

void update (unsigned char flag=0xff)
 Notify service thread that a port has been added or removed, or a timer changed, so that a new schedule can be computed for expiring attached ports. More...
 
 SerialService (int pri=0, size_t stack=0, const char *id=NULL)
 Create a service thread for attaching serial ports. More...
 
virtual ~SerialService ()
 Terminate the service thread and update attached objects. More...
 
int getCount (void)
 Get current reference count. More...
 
- Public Member Functions inherited from ost::Thread
 Thread (bool isMain)
 This is actually a special constructor that is used to create a thread "object" for the current execution context when that context is not created via an instance of a derived Thread object itself. More...
 
 Thread (int pri=0, size_t stack=0)
 When a thread object is contructed, a new thread of execution context is created. More...
 
 Thread (const Thread &th)
 A thread of execution can also be specified by cloning an existing thread. More...
 
virtual ~Thread ()
 The thread destructor should clear up any resources that have been allocated by the thread. More...
 
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...
 
ThreadgetParent (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...
 

Protected Member Functions

virtual void onUpdate (unsigned char flag)
 A virtual handler for processing user defined update requests (1-254) which have been posted through Update. More...
 
virtual void onEvent (void)
 A virtual handler for event loop calls. More...
 
virtual void onCallback (SerialPort *port)
 A virtual handler for adding support for additional callback events into SerialPort. More...
 
- Protected Member Functions inherited from ost::Thread
void setName (const char *text)
 Set the name of the current 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...
 

Friends

class SerialPort
 

Additional Inherited Members

- Public Types inherited from ost::Thread
enum  Throw { throwNothing, throwObject, throwException }
 How to raise error. More...
 
enum  Cancel {
  cancelInitial =0, cancelDeferred =1, cancelImmediate, cancelDisabled,
  cancelManual, cancelDefault =cancelDeferred
}
 How work cancellation. More...
 
enum  Suspend { suspendEnable, suspendDisable }
 How work suspend. More...
 
typedef enum ost::Thread::Throw Throw
 How to raise error. More...
 
typedef enum ost::Thread::Cancel Cancel
 How work cancellation. More...
 
typedef enum ost::Thread::Suspend Suspend
 How work suspend. More...
 
- Static Public Member Functions inherited from ost::Thread
static Threadget (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...
 

Detailed Description

The SerialService is a thead service object that is meant to service attached serial ports.

Multiple pool objects may be created and multiple serial ports may be attached to the same thread of of execution. This allows one to balance threads and the serial ports they service.

The TTYPort and TTYService classes are used to form thread-pool serviced serial I/O protocol sets. These can be used when one has a large number of serial devices to manage, and a single (or limited number of) thread(s) can then be used to service the tty port objects present. Each tty port supports a timer control and several virtual methods that the service thread can call when events occur. This model provides for "callback" event management, whereby the service thread performs a "callback" into the port object when events occur. Specific events supported include the expiration of a TTYPort timer, pending input data waiting to be read, and "sighup" connection breaks.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m

Thread pool service for serial ports.

Constructor & Destructor Documentation

◆ SerialService()

ost::SerialService::SerialService ( int  pri = 0,
size_t  stack = 0,
const char *  id = NULL 
)

Create a service thread for attaching serial ports.

The thread begins execution with the first attached port.

Parameters
priof this thread to run under.
stackstack size.
idstack ID.

◆ ~SerialService()

virtual ost::SerialService::~SerialService ( )
virtual

Terminate the service thread and update attached objects.

Member Function Documentation

◆ getCount()

int ost::SerialService::getCount ( void  )
inline

Get current reference count.

This can be used when selecting the lead used service handler from a pool.

Returns
count of active ports.

◆ onCallback()

virtual void ost::SerialService::onCallback ( SerialPort port)
protectedvirtual

A virtual handler for adding support for additional callback events into SerialPort.

Parameters
portserial port currently being evaluated.

◆ onEvent()

virtual void ost::SerialService::onEvent ( void  )
protectedvirtual

A virtual handler for event loop calls.

This can be used to extend event loop processing.

◆ onUpdate()

virtual void ost::SerialService::onUpdate ( unsigned char  flag)
protectedvirtual

A virtual handler for processing user defined update requests (1-254) which have been posted through Update.

Parameters
flagof update request.

◆ update()

void ost::SerialService::update ( unsigned char  flag = 0xff)

Notify service thread that a port has been added or removed, or a timer changed, so that a new schedule can be computed for expiring attached ports.

This can also be used to pass requests to the OnUpdate() event handler.

Parameters
flagevent for OnUpdate, termination, or reschedule.

Friends And Related Function Documentation

◆ SerialPort

friend class SerialPort
friend

The documentation for this class was generated from the following file: