DABC (Data Acquisition Backbone Core)  2.9.9
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
dabc::SocketAddon Class Reference

Special addon class for handling of socket and socket events. More...

#include <dabc/SocketThread.h>

Inheritance diagram for dabc::SocketAddon:
dabc::WorkerAddon dabc::Object dabc::SocketConnectAddon dabc::SocketIOAddon hadaq::NewAddon dabc::SocketClientAddon dabc::SocketServerAddon aqua::ClientOutput dabc::SocketNetworkInetrface dabc::SocketProtocolAddon mbs::ClientTransport mbs::DaqStatusAddon mbs::ServerOutputAddon

Public Types

enum  ESocketEvents {
  evntSocketRead = Worker::evntFirstAddOn , evntSocketWrite , evntSocketError , evntSocketStartConnect ,
  evntSocketLast , evntSocketRecvInfo = Worker::evntFirstSystem , evntSocketSendInfo , evntSocketErrorInfo ,
  evntSocketCloseInfo , evntSocketLastInfo
}
 

Public Member Functions

virtual const char * ClassName () const
 Returns class name of the object instance. More...
 
void CloseSocket ()
 
bool IsDeliverEventsToWorker () const
 
bool IsDoingInput () const
 
bool IsDoingOutput () const
 
bool IsSocket () const
 
virtual std::string RequiredThrdClass () const
 
void SetDeliverEventsToWorker (bool on=true)
 
void SetIOPriority (int prior=1)
 Method defines priority level for socket IO events. More...
 
void SetSocket (int fd)
 
int Socket () const
 
 SocketAddon (int fd=-1)
 
int TakeSocket ()
 
int TakeSocketError ()
 
virtual ~SocketAddon ()
 
- Public Member Functions inherited from dabc::WorkerAddon
 WorkerAddon (const std::string &name)
 
virtual ~WorkerAddon ()
 
- Public Member Functions inherited from dabc::Object
bool AddChild (Object *child, bool withmutex=true) throw ()
 Add object to list of child objects, thread safe More...
 
bool AddChildAt (Object *child, unsigned pos, bool withmutex=true)
 Add object to list of child objects at specified position. More...
 
virtual void BuildFieldsMap (RecordFieldsMap *cont)
 Fill fields map, which is relevant for the object Objects hierarchy produced from dabc::Manager. More...
 
virtual bool Find (ConfigIO &cfg)
 Method to locate object in xml file. More...
 
ObjectFindChild (const char *name) const
 returns pointer on child object with given name More...
 
Reference FindChildRef (const char *name, bool force=false) const throw ()
 returns reference on child object with given name More...
 
bool GetAllChildRef (ReferencesVector *vect) const
 
ObjectGetChild (unsigned n) const
 returns pointer on child object More...
 
Reference GetChildRef (unsigned n) const
 returns reference on child object More...
 
Reference GetFolder (const std::string &name, bool force=false) throw ()
 Return folder of specified name, no special symbols allowed. More...
 
const char * GetName () const
 Returns name of the object, thread safe More...
 
ObjectGetParent () const
 Returns pointer on parent object, thread safe More...
 
Reference GetParentRef () const
 
bool IsChildsHidden () const
 Return true if object wants to hide childs from hierarchy scan, thread safe More...
 
bool IsHidden () const
 Return true if object wants to be hidden from hierarchy scan, thread safe More...
 
bool IsLogging () const
 Return true if object selected for logging, thread safe More...
 
bool IsName (const char *str) const
 Checks if object name is same as provided string, thread safe More...
 
bool IsName (const char *str, int len) const
 Checks if object name is same as provided, thread safe More...
 
bool IsName (const std::string &str) const
 Checks if object name is same as provided string, thread safe More...
 
bool IsNameMatch (const std::string &mask) const
 Check if object name match to the mask. More...
 
bool IsOwner () const
 Returns true if object is owner of its children, thread safe More...
 
bool IsParent (Object *obj) const
 Checks if specified argument is in the list of object parents. More...
 
bool IsTopXmlLevel () const
 Return true if object should be searched in the top level of the xml file, thread safe More...
 
std::string ItemName (bool compact=true) const
 Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call. More...
 
unsigned NumChilds () const
 returns number of child objects More...
 
 Object (const std::string &name, unsigned flags=flIsOwner)
 Resolve problem with child-parent mutex locking. More...
 
 Object (Reference parent, const std::string &name, unsigned flags=flIsOwner)
 
virtual void Print (int lvl=0)
 Print object content on debug output. More...
 
bool RemoveChild (Object *child, bool cleanup=true) throw ()
 Detach child from parent object If cleanup==true and parent is owner of child, child will be destroyed. More...
 
bool RemoveChildAt (unsigned n, bool cleanup=true) throw ()
 Detach child object from parent at specified position If cleanup==true and object is owner of child, child will be destroyed. More...
 
bool RemoveChilds (bool cleanup=true)
 Remove all childs. More...
 
void SetLogging (bool on=true)
 Sets logging flag, thread safe More...
 
virtual ~Object ()
 

Protected Member Functions

ssize_t DoRecvBuffer (void *buf, ssize_t len)
 
ssize_t DoRecvBufferHdr (void *hdr, ssize_t hdrlen, void *buf, ssize_t len, void *srcaddr=0, unsigned srcaddrlen=0)
 
ssize_t DoSendBuffer (void *buf, ssize_t len)
 
ssize_t DoSendBufferHdr (void *hdr, ssize_t hdrlen, void *buf, ssize_t len, void *tgtaddr=0, unsigned tgtaddrlen=0)
 
bool IsDeleteWorkerOnClose () const
 
virtual void OnSocketError (int msg, const std::string &info)
 Generic error handler. More...
 
virtual void ProcessEvent (const EventId &)
 
void SetDeleteWorkerOnClose (bool on=true)
 
void SetDoingInput (bool on=true)
 Call method to indicate that object wants to read data from the socket. More...
 
void SetDoingOutput (bool on=true)
 Call method to indicate that worker wants to write data to the socket. More...
 
- Protected Member Functions inherited from dabc::WorkerAddon
bool ActivateTimeout (double tmout_sec)
 
void DeleteAddonItself ()
 This is possibility to delete addon itself, invoking worker command. More...
 
void DeleteWorker ()
 This is way to delete worker with addon inclusive. More...
 
void FireWorkerEvent (unsigned evid)
 
virtual long Notify (const std::string &, int)
 Light-weight command interface, which can be used from worker. More...
 
virtual void ObjectCleanup ()
 User method to cleanup object content before it will be destroyed Main motivation is to release any references on other objects to avoid any cross-references and as result deadlocks in objects cleanup. More...
 
virtual void OnThreadAssigned ()
 
virtual double ProcessTimeout (double last_diff)
 
void SubmitWorkerCmd (Command cmd)
 
- Protected Member Functions inherited from dabc::Object
virtual void _ChildsChanged ()
 Method called when new childs are add or old are removed. More...
 
virtual bool _DoDeleteItself ()
 This method is called at the moment when DecReference think that object can be destroyed and wants to return true. More...
 
bool _IsNormalState ()
 Same as IsNormalState() but without mutex lock - user should lock mutex himself. More...
 
virtual ObjectCreateInstance (const std::string &name)
 Method used to create new item to be placed as child of the object. More...
 
void DeleteThis ()
 Method should be used by the object to delete itself. More...
 
virtual bool DestroyByOwnThread ()
 Internal DABC method, used to activate object cleanup via object thread Returns: false - object cannot be cleanup by the thread, true - thread guarantees that DestroyCalledFromOwnThread() will be called from thread context. More...
 
bool DestroyCalledFromOwnThread ()
 Internal DABC method, should be called by thread which was requested to destroy object. More...
 
void FillFullName (std::string &fullname, Object *upto, bool exclude_top_parent=false) const
 Method used to produce full item name,. More...
 
bool GetFlag (unsigned fl) const
 Return value of selected flag, not thread safe
More...
 
bool IsNormalState ()
 Return true if object is in normal state. More...
 
unsigned NumReferences ()
 Return number of references on the object. More...
 
 Object (const ConstructorPair &pair, unsigned flags=flIsOwner)
 
virtual void ObjectDestroyed (Object *)
 Method called by the manager when registered dependent object is destroyed Should be used in user class to clear all references on the object to let destroy it. More...
 
MutexObjectMutex () const
 Returns mutex, used for protection of Object data members. More...
 
void SetAutoDestroy (bool on=true)
 Set autodestroy flag for the object Once enabled, object will be destroyed when last reference will be cleared. More...
 
void SetFlag (unsigned fl, bool on=true)
 Change value of selected flag, not thread safe
More...
 
void SetName (const char *name)
 Changes object name. More...
 
void SetNameDirect (const char *name)
 Changes object name disregard of existing references. More...
 
void SetOwner (bool on=true)
 Specifies if object will be owner of its new childs. More...
 

Protected Attributes

bool fDeleteWorkerOnClose
 if true, worker will be deleted when socket closed or socket in error More...
 
bool fDeliverEventsToWorker
 if true, completion events will be delivered to the worker More...
 
bool fDoingInput
 true if input data are expected More...
 
bool fDoingOutput
 true if data need to be send More...
 
int fIOPriority
 priority of socket I/O events, default 1 More...
 
int fSocket
 socket handle More...
 
- Protected Attributes inherited from dabc::WorkerAddon
Reference fWorker
 
- Protected Attributes inherited from dabc::Object
int fObjectBlock
 counter for blocking calls, as long as non-zero, non of child can be removed More...
 
ReferencesVectorfObjectChilds
 list of the child objects More...
 
unsigned fObjectFlags
 flag, protected by the mutex More...
 
MutexfObjectMutex
 mutex protects all private property of the object More...
 
std::string fObjectName
 object name More...
 
Reference fObjectParent
 reference on the parent object More...
 
int fObjectRefCnt
 accounts how many references existing on the object, thread safe More...
 

Friends

class SocketThread
 

Additional Inherited Members

- Static Public Member Functions inherited from dabc::Object
static void Destroy (Object *obj) throw ()
 User method for object destroyment. More...
 
static void InspectGarbageCollector ()
 \ brief Methods to inspect how many objects pointers are remained More...
 
static bool NameMatch (const std::string &name, const std::string &mask)
 Check if name matches to specified mask. More...
 
static bool NameMatchM (const std::string &name, const std::string &mask)
 Check if name matches to specified mask. More...
 
static unsigned NumInstances ()
 Static variable counts total number of objects instances. More...
 
- Protected Types inherited from dabc::Object
enum  EFlags {
  flStateMask = 0x000f , flIsOwner = 0x0010 , flCleanup = 0x0020 , flHasThread = 0x0040 ,
  flAutoDestroy = 0x0080 , flLogging = 0x0100 , flNoMutex = 0x0200 , flHidden = 0x0400 ,
  flChildsHidden = 0x0800 , flTopXmlLevel = 0x1000
}
 
- Static Protected Member Functions inherited from dabc::Object
static ConstructorPair MakePair (const std::string &fullname, bool withmanager=true)
 Internal DABC method, used to produce pair - object parent and object name, which is typically should be used as argument in class constructor. More...
 
static ConstructorPair MakePair (Object *prnt, const std::string &fullname, bool withmanager=true)
 Internal DABC method, used to produce pair - object parent and object name, which is typically should be used as argument in class constructor. More...
 
static ConstructorPair MakePair (Reference prnt, const std::string &fullname, bool withmanager=true)
 Internal DABC method, used to produce pair - object parent and object name, which is typically should be used as argument in class constructor. More...
 

Detailed Description

Special addon class for handling of socket and socket events.

Main aim is to provide asynchronous access to the sockets. SocketAddon has two boolean variables which indicates if worker wants to send or receive data from the socket. User should set these flags to true before starting of appropriate operation. Thread will use these flags to check if such operation can be performed now. If yes, event evntSocketRead or evntSocketWrite will be generated. User should implement ProcessEvent() to react on this even and either read or write data on the sockets. Flag will be cleared, therefore if operation should be continued, user should set flag again. In case of error evntSocketError will be created and both flags will be cleared.

Definition at line 52 of file SocketThread.h.

Member Enumeration Documentation

◆ ESocketEvents

Enumerator
evntSocketRead 
evntSocketWrite 
evntSocketError 
evntSocketStartConnect 
evntSocketLast 

from this event number one can add more socket system events

evntSocketRecvInfo 

event delivered to worker when read is completed

evntSocketSendInfo 

event delivered to worker when write is completed

evntSocketErrorInfo 

event delivered to worker when error is detected

evntSocketCloseInfo 

event delivered to worker when socket is closed

evntSocketLastInfo 

last system event, used by sockets

Definition at line 89 of file SocketThread.h.

Constructor & Destructor Documentation

◆ SocketAddon()

dabc::SocketAddon::SocketAddon ( int  fd = -1)

Definition at line 75 of file SocketThread.cxx.

◆ ~SocketAddon()

dabc::SocketAddon::~SocketAddon ( )
virtual

Definition at line 86 of file SocketThread.cxx.

Member Function Documentation

◆ ProcessEvent()

void dabc::SocketAddon::ProcessEvent ( const EventId evnt)
protectedvirtual

◆ SetDoingInput()

void dabc::SocketAddon::SetDoingInput ( bool  on = true)
inlineprotected

Call method to indicate that object wants to read data from the socket.

When it will be possible, worker get evntSocketRead event

Definition at line 69 of file SocketThread.h.

◆ SetDoingOutput()

void dabc::SocketAddon::SetDoingOutput ( bool  on = true)
inlineprotected

Call method to indicate that worker wants to write data to the socket.

When it will be possible, worker get evntSocketWrite event

Definition at line 73 of file SocketThread.h.

◆ OnSocketError()

void dabc::SocketAddon::OnSocketError ( int  msg,
const std::string &  info 
)
protectedvirtual

Generic error handler.

Also invoked when socket is closed (msg==0)

Reimplemented in dabc::SocketProtocolAddon, dabc::SocketNetworkInetrface, aqua::ClientOutput, mbs::ServerOutputAddon, and mbs::ClientTransport.

Definition at line 146 of file SocketThread.cxx.

◆ DoRecvBuffer()

ssize_t dabc::SocketAddon::DoRecvBuffer ( void *  buf,
ssize_t  len 
)
protected

Definition at line 163 of file SocketThread.cxx.

◆ DoRecvBufferHdr()

ssize_t dabc::SocketAddon::DoRecvBufferHdr ( void *  hdr,
ssize_t  hdrlen,
void *  buf,
ssize_t  len,
void *  srcaddr = 0,
unsigned  srcaddrlen = 0 
)
protected

Definition at line 175 of file SocketThread.cxx.

◆ DoSendBuffer()

ssize_t dabc::SocketAddon::DoSendBuffer ( void *  buf,
ssize_t  len 
)
protected

Definition at line 205 of file SocketThread.cxx.

◆ DoSendBufferHdr()

ssize_t dabc::SocketAddon::DoSendBufferHdr ( void *  hdr,
ssize_t  hdrlen,
void *  buf,
ssize_t  len,
void *  tgtaddr = 0,
unsigned  tgtaddrlen = 0 
)
protected

Definition at line 218 of file SocketThread.cxx.

◆ IsDeleteWorkerOnClose()

bool dabc::SocketAddon::IsDeleteWorkerOnClose ( ) const
inlineprotected

Definition at line 83 of file SocketThread.h.

◆ SetDeleteWorkerOnClose()

void dabc::SocketAddon::SetDeleteWorkerOnClose ( bool  on = true)
inlineprotected

Definition at line 84 of file SocketThread.h.

◆ ClassName()

virtual const char* dabc::SocketAddon::ClassName ( ) const
inlinevirtual

Returns class name of the object instance.

In some cases class name used to correctly locate object in xml file

Reimplemented from dabc::WorkerAddon.

Reimplemented in dabc::SocketClientAddon, dabc::SocketServerAddon, dabc::SocketConnectAddon, and dabc::SocketIOAddon.

Definition at line 105 of file SocketThread.h.

◆ RequiredThrdClass()

virtual std::string dabc::SocketAddon::RequiredThrdClass ( ) const
inlinevirtual

Reimplemented from dabc::WorkerAddon.

Definition at line 106 of file SocketThread.h.

◆ Socket()

int dabc::SocketAddon::Socket ( ) const
inline

Definition at line 108 of file SocketThread.h.

◆ IsSocket()

bool dabc::SocketAddon::IsSocket ( ) const
inline

Definition at line 109 of file SocketThread.h.

◆ IsDoingInput()

bool dabc::SocketAddon::IsDoingInput ( ) const
inline

Definition at line 111 of file SocketThread.h.

◆ IsDoingOutput()

bool dabc::SocketAddon::IsDoingOutput ( ) const
inline

Definition at line 112 of file SocketThread.h.

◆ CloseSocket()

void dabc::SocketAddon::CloseSocket ( )

Definition at line 123 of file SocketThread.cxx.

◆ SetSocket()

void dabc::SocketAddon::SetSocket ( int  fd)

Definition at line 110 of file SocketThread.cxx.

◆ TakeSocket()

int dabc::SocketAddon::TakeSocket ( )

Definition at line 116 of file SocketThread.cxx.

◆ TakeSocketError()

int dabc::SocketAddon::TakeSocketError ( )

Definition at line 132 of file SocketThread.cxx.

◆ IsDeliverEventsToWorker()

bool dabc::SocketAddon::IsDeliverEventsToWorker ( ) const
inline

Definition at line 120 of file SocketThread.h.

◆ SetDeliverEventsToWorker()

void dabc::SocketAddon::SetDeliverEventsToWorker ( bool  on = true)
inline

Definition at line 121 of file SocketThread.h.

◆ SetIOPriority()

void dabc::SocketAddon::SetIOPriority ( int  prior = 1)
inline

Method defines priority level for socket IO events.

Allowed values are from 0-maximal, 1-normal or 2-minimal

Definition at line 125 of file SocketThread.h.

Friends And Related Function Documentation

◆ SocketThread

friend class SocketThread
friend

Definition at line 54 of file SocketThread.h.

Field Documentation

◆ fSocket

int dabc::SocketAddon::fSocket
protected

socket handle

Definition at line 58 of file SocketThread.h.

◆ fDoingInput

bool dabc::SocketAddon::fDoingInput
protected

true if input data are expected

Definition at line 59 of file SocketThread.h.

◆ fDoingOutput

bool dabc::SocketAddon::fDoingOutput
protected

true if data need to be send

Definition at line 60 of file SocketThread.h.

◆ fIOPriority

int dabc::SocketAddon::fIOPriority
protected

priority of socket I/O events, default 1

Definition at line 61 of file SocketThread.h.

◆ fDeliverEventsToWorker

bool dabc::SocketAddon::fDeliverEventsToWorker
protected

if true, completion events will be delivered to the worker

Definition at line 62 of file SocketThread.h.

◆ fDeleteWorkerOnClose

bool dabc::SocketAddon::fDeleteWorkerOnClose
protected

if true, worker will be deleted when socket closed or socket in error

Definition at line 63 of file SocketThread.h.


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