DABC (Data Acquisition Backbone Core)
2.9.9
|
Base class for most of the DABC classes. More...
#include <dabc/Object.h>
Data Structures | |
struct | ConstructorPair |
Structure used to specify arguments for object constructor. More... | |
Public Member Functions | |
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 const char * | ClassName () const |
Returns class name of the object instance. More... | |
virtual bool | Find (ConfigIO &cfg) |
Method to locate object in xml file. More... | |
Object * | FindChild (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 |
Object * | GetChild (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... | |
Object * | GetParent () 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 () |
Static Public Member Functions | |
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 | |
enum | EFlags { flStateMask = 0x000f , flIsOwner = 0x0010 , flCleanup = 0x0020 , flHasThread = 0x0040 , flAutoDestroy = 0x0080 , flLogging = 0x0100 , flNoMutex = 0x0200 , flHidden = 0x0400 , flChildsHidden = 0x0800 , flTopXmlLevel = 0x1000 } |
Protected Member Functions | |
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 Object * | CreateInstance (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 | 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 | 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... | |
Mutex * | ObjectMutex () 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... | |
Static Protected Member Functions | |
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... | |
Protected Attributes | |
int | fObjectBlock |
counter for blocking calls, as long as non-zero, non of child can be removed More... | |
ReferencesVector * | fObjectChilds |
list of the child objects More... | |
unsigned | fObjectFlags |
flag, protected by the mutex More... | |
Mutex * | fObjectMutex |
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... | |
Private Types | |
enum | EState { stConstructor = 0 , stNormal = 1 , stWaitForThread = 2 , stDoingDestroy = 3 , stWaitForDestructor = 4 , stDestructor = 5 } |
These are object live stages. More... | |
Private Member Functions | |
void | Constructor () |
Initializes all variables of the object. More... | |
bool | DecReference (bool ask_to_destroy, bool do_decrement=true, bool from_thread=false) |
Decrements reference counter, return true if object must be destroyed. More... | |
void | Destructor () |
Destroys all internal data, reentrant. More... | |
EState | GetState () const |
Returns object state value. More... | |
bool | IncReference (bool withmutex=true) |
Increments reference counter, return false if it cannot be done. More... | |
void | SetCleanupBit () |
Method set cleanup bit that object will be cleaned up in all registered objects Used only by manager therefore private. More... | |
void | SetState (EState st) |
Set object state value. More... | |
Static Private Member Functions | |
static Reference | SearchForChild (Reference &ref, const char *name, bool firsttime, bool force) throw () |
Static Private Attributes | |
static unsigned | gNumCreated = 0 |
number of created instances, will used for object id More... | |
static unsigned | gNumInstances = 0 |
actual number of existing instances More... | |
Friends | |
class | Manager |
class | Reference |
Base class for most of the DABC classes.
Provides possibility to build thread safe hierarchy of the objects. Has references counter to be sure how many references are existing on this object.
Thread-safety for the Object only has means together with Reference class. Only existence of reference can ensure that object will not be destroyed or completely changed by some other threads. General concept is that object can only be changed if reference counter is equal to 0 (in fact, only in constructor). There is main exception - list child objects can be changed in any moment, therefore to ensure at each moment that child or children objects will not change in meanwhile, one should use references on child. In all other special cases such possibility will be extra marked in documentation. In normal case attempt to change the referenced object will rise an exception.
|
private |
These are object live stages.
Normally they should go one after another
|
protected |
Enumerator | |
---|---|
flStateMask | use 4 bits for state |
flIsOwner | flag indicates default ownership for child objects |
flCleanup | flag indicates that one should cleanup pointer from depended objects |
flHasThread | flag indicates that object has thread and should be cleaned up via thread |
flAutoDestroy | object will be automatically destroyed when no references exists, normally set in constructor, example Command |
flLogging | object is marked to provide logging information, for debug purposes only |
flNoMutex | object will be created without mutex, only can be used in constructor |
flHidden | hide object from hierarchy scan |
flChildsHidden | hide all childs from hierarchy scan |
flTopXmlLevel | object (or folder) can be found on top xml level in the Context |
|
protected |
Definition at line 132 of file Object.cxx.
dabc::Object::Object | ( | const std::string & | name, |
unsigned | flags = flIsOwner |
||
) |
Resolve problem with child-parent mutex locking.
Now this completely avoidable. Parent pointer was and is safe - as long object is exists parent reference is preserved, only in destructor parent will be released. Child reference can disappear in any time, therefore it was difficult to get reference on child while only pointer is not enough - somebody else can remove it very fast. Therefore fObjectBlock counter is introduced. As long it is non-zero no any removal of childs are allowed. As result, reference on all childs are preserved. One can release parent lock, acquire reference on child (which includes child mutex locking) and after that again parent lock and decrement of block counter. This only limits situation during removal of childs - it all correspondent methods one should respect block counter.
Definition at line 103 of file Object.cxx.
Definition at line 117 of file Object.cxx.
|
virtual |
Definition at line 147 of file Object.cxx.
|
private |
Initializes all variables of the object.
Definition at line 210 of file Object.cxx.
|
private |
Destroys all internal data, reentrant.
Definition at line 225 of file Object.cxx.
|
private |
Increments reference counter, return false if it cannot be done.
[in] | withmutex | can indicate that object mutex is already locked and we do not need repeat it again |
Definition at line 278 of file Object.cxx.
|
private |
Decrements reference counter, return true if object must be destroyed.
somebody else has reference, when it release reference object will be automatically destroyed
Definition at line 317 of file Object.cxx.
|
inlineprivate |
|
inlineprivate |
|
staticprivate |
Definition at line 742 of file Object.cxx.
|
private |
Method set cleanup bit that object will be cleaned up in all registered objects Used only by manager therefore private.
Definition at line 297 of file Object.cxx.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
protected |
Return number of references on the object.
Definition at line 557 of file Object.cxx.
|
inlineprotectedvirtual |
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.
Reimplemented in saftdabc::Device, and dabc::Worker.
|
protected |
Internal DABC method, should be called by thread which was requested to destroy object.
Definition at line 504 of file Object.cxx.
|
protectedvirtual |
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.
Method is called in context of thread, to which object belongs to. If user redefines this method, he is responsible to call method of parent class
Reimplemented in verbs::PoolRegistry, saftdabc::Device, mbs::ClientTransport, dabc::Worker, dabc::WorkerAddon, dabc::Thread, dabc::SocketConnectAddon, dabc::PoolHandle, dabc::Port, dabc::ParameterContainer, dabc::ModuleSync, dabc::Module, dabc::Device, and dabc::Application.
Definition at line 532 of file Object.cxx.
|
inlineprotectedvirtual |
This method is called at the moment when DecReference think that object can be destroyed and wants to return true.
Object can decide to find another way to the destructor and reject this. After _DoDeleteItself() returns true, it is fully object responsibility to delete itself.
Reimplemented in dabc::Thread.
|
protected |
Specifies if object will be owner of its new childs.
Definition at line 154 of file Object.cxx.
|
protected |
Set autodestroy flag for the object Once enabled, object will be destroyed when last reference will be cleared.
Definition at line 160 of file Object.cxx.
|
inlineprotectedvirtual |
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.
Reimplemented in dabc::Worker, and verbs::PoolRegistry.
|
protected |
Return true if object is in normal state.
Typically should used from inside object itself (therefore protected) to reject from the beginning actions which are too complex for object which is started to be destroyed
Definition at line 309 of file Object.cxx.
|
protected |
Method used to produce full item name,.
Produced name can be used to find such item in the objects hierarchy
Definition at line 1061 of file Object.cxx.
|
protected |
Same as IsNormalState() but without mutex lock - user should lock mutex himself.
Definition at line 303 of file Object.cxx.
|
inlineprotectedvirtual |
Method used to create new item to be placed as child of the object.
Reimplemented in dabc::HierarchyContainer.
|
inlineprotectedvirtual |
Method called when new childs are add or old are removed.
Reimplemented in dabc::HierarchyContainer.
|
staticprotected |
Internal DABC method, used to produce pair - object parent and object name, which is typically should be used as argument in class constructor.
[in] | prnt | reference on parent object |
[in] | fullname | relative to parent path and name |
[in] | withmanager | identify if object should be inserted into manager hierarchy (default) or not |
Definition at line 934 of file Object.cxx.
|
staticprotected |
Internal DABC method, used to produce pair - object parent and object name, which is typically should be used as argument in class constructor.
Definition at line 974 of file Object.cxx.
|
staticprotected |
Internal DABC method, used to produce pair - object parent and object name, which is typically should be used as argument in class constructor.
Definition at line 979 of file Object.cxx.
|
inline |
|
inline |
bool dabc::Object::IsParent | ( | Object * | obj | ) | const |
Checks if specified argument is in the list of object parents.
Definition at line 985 of file Object.cxx.
|
inline |
|
inline |
|
inline |
bool dabc::Object::IsName | ( | const char * | str, |
int | len | ||
) | const |
Checks if object name is same as provided, thread safe
[in] | str | string with name to be compared |
[in] | len | specifies how many characters should be checked if len == 0, method will return false. if len < 0, str will be supposed normal null-terminated string |
Definition at line 203 of file Object.cxx.
bool dabc::Object::IsNameMatch | ( | const std::string & | mask | ) | const |
Check if object name match to the mask.
Definition at line 999 of file Object.cxx.
bool dabc::Object::IsOwner | ( | ) | const |
Returns true if object is owner of its children, thread safe
Definition at line 167 of file Object.cxx.
bool dabc::Object::IsLogging | ( | ) | const |
Return true if object selected for logging, thread safe
Definition at line 173 of file Object.cxx.
void dabc::Object::SetLogging | ( | bool | on = true | ) |
Sets logging flag, thread safe
Definition at line 197 of file Object.cxx.
bool dabc::Object::IsHidden | ( | ) | const |
Return true if object wants to be hidden from hierarchy scan, thread safe
Definition at line 191 of file Object.cxx.
bool dabc::Object::IsChildsHidden | ( | ) | const |
Return true if object wants to hide childs from hierarchy scan, thread safe
Definition at line 179 of file Object.cxx.
bool dabc::Object::IsTopXmlLevel | ( | ) | const |
Return true if object should be searched in the top level of the xml file, thread safe
Definition at line 185 of file Object.cxx.
bool dabc::Object::AddChild | ( | Object * | child, |
bool | withmutex = true |
||
) | |||
throw | ( | ||
) |
Add object to list of child objects, thread safe
[in] | child | object to add |
[in] | withmutex | true if object mutex should be locked |
Definition at line 565 of file Object.cxx.
bool dabc::Object::AddChildAt | ( | Object * | child, |
unsigned | pos, | ||
bool | withmutex = true |
||
) |
Add object to list of child objects at specified position.
[in] | child | object to add |
[in] | pos | position at which add object, if grater than number of childs, will be add at the end |
[in] | withmutex | true if object mutex should be locked |
Definition at line 570 of file Object.cxx.
bool dabc::Object::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.
Definition at line 604 of file Object.cxx.
bool dabc::Object::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.
Definition at line 665 of file Object.cxx.
bool dabc::Object::RemoveChilds | ( | bool | cleanup = true | ) |
Remove all childs.
If object is owner and cleanup flag (default) is specified, when childs will be destroyed.
Definition at line 821 of file Object.cxx.
unsigned dabc::Object::NumChilds | ( | ) | const |
returns number of child objects
Definition at line 670 of file Object.cxx.
dabc::Object * dabc::Object::GetChild | ( | unsigned | n | ) | const |
returns pointer on child object
Definition at line 677 of file Object.cxx.
dabc::Reference dabc::Object::GetChildRef | ( | unsigned | n | ) | const |
returns reference on child object
Definition at line 684 of file Object.cxx.
bool dabc::Object::GetAllChildRef | ( | ReferencesVector * | vect | ) | const |
Definition at line 701 of file Object.cxx.
dabc::Object * dabc::Object::FindChild | ( | const char * | name | ) | const |
returns pointer on child object with given name
Definition at line 730 of file Object.cxx.
dabc::Reference dabc::Object::FindChildRef | ( | const char * | name, |
bool | force = false |
||
) | const | ||
throw | ( | ||
) |
returns reference on child object with given name
Definition at line 735 of file Object.cxx.
dabc::Reference dabc::Object::GetFolder | ( | const std::string & | name, |
bool | force = false |
||
) | |||
throw | ( | ||
) |
Return folder of specified name, no special symbols allowed.
[in] | name | folder name |
[in] | force | if true, missing folder will be created |
Definition at line 814 of file Object.cxx.
|
virtual |
Print object content on debug output.
Reimplemented in dabc::Thread, dabc::RecordContainer, and dabc::Manager.
Definition at line 1092 of file Object.cxx.
std::string dabc::Object::ItemName | ( | bool | compact = true | ) | const |
Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call.
[in] | compact | if true [default], objects belonging to the application will not include application name in their path |
Definition at line 1076 of file Object.cxx.
|
static |
User method for object destroyment.
In many cases object may not be destroyed immediately while references can exists. Nevertheless, pointer on the object is no longer valid - object can be destroyed in other thread in any time. In some special cases objects cannot be destroyed at all - they will be cleaned by other means (like thread - it is only destroyed by manager when no longer used TODO: probably, one should remove it and always use reference
Definition at line 921 of file Object.cxx.
|
inlinevirtual |
Returns class name of the object instance.
In some cases class name used to correctly locate object in xml file
Reimplemented in verbs::WorkerAddon, verbs::Thread, verbs::Device, verbs::TimeoutWorker, saftdabc::Device, root::Monitor, http::Server, http::FastCgi, http::Civetweb, dabc::Thread::ExecWorker, dabc::Worker, dabc::WorkerAddon, dabc::Transport, dabc::Thread, dabc::SocketThread, dabc::SocketClientAddon, dabc::SocketServerAddon, dabc::SocketConnectAddon, dabc::SocketIOAddon, dabc::SocketAddon, dabc::SocketDevice, dabc::RecordContainer, dabc::Publisher, dabc::PoolHandle, dabc::OutputPort, dabc::InputPort, dabc::Port, dabc::ParameterContainer, dabc::NetworkTransport, dabc::ModuleSync, dabc::ModuleAsync, dabc::Module, dabc::MemoryPool, dabc::Manager, dabc::HierarchyContainer, dabc::Factory, dabc::Device, dabc::ConnectionObject, dabc::CommandContainer, and dabc::Application.
|
virtual |
Method to locate object in xml file.
Can be reimplemented in derived classes to check more attributes like class name
Reimplemented in dabc::Thread::ExecWorker, dabc::Worker, dabc::Module, dabc::MemoryPool, dabc::Manager, dabc::Device, and dabc::Application.
Definition at line 929 of file Object.cxx.
|
inlinevirtual |
Fill fields map, which is relevant for the object Objects hierarchy produced from dabc::Manager.
Reimplemented in dabc::ParameterContainer, dabc::Module, and dabc::Application.
|
inlinestatic |
|
static |
\ brief Methods to inspect how many objects pointers are remained
Garbage collector will not remove lost objects itself - one can only watch how many objects and which kind are remain in memory. Method only work when DABC compiled with option "make extrachecks=true"
Definition at line 1099 of file Object.cxx.
|
static |
Check if name matches to specified mask.
Mask can include special symbols *
and ?
Definition at line 1004 of file Object.cxx.
|
static |
Check if name matches to specified mask.
Mask can be a list of masks separated by semicolon like name1*:name2*:??name??
Definition at line 1028 of file Object.cxx.
|
protected |
Changes object name.
Should not be used if any references exists on the object
Definition at line 871 of file Object.cxx.
|
protected |
Changes object name disregard of existing references.
Definition at line 884 of file Object.cxx.
|
protected |
Method should be used by the object to delete itself.
Definition at line 509 of file Object.cxx.
|
staticprivate |
|
staticprivate |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |