23 #ifndef DABC_Application
47 class StdManagerFactory;
48 class ReferencesVector;
50 class ParamEventReceiverList;
54 static const char*
CmdName() {
return "DeletePool"; }
57 {
SetStr(
"PoolName", name); }
73 static const char*
CmdName() {
return "CreateModule"; }
75 CmdCreateModule(
const std::string &classname,
const std::string &modulename,
const std::string &thrdname =
"") :
85 static const char*
CmdName() {
return "StartModule"; }
92 static const char*
CmdName() {
return "StopModule"; }
99 static const char*
CmdName() {
return "DeleteModule"; }
115 SetStr(
"AppClass", appclass);
123 static const char*
CmdName() {
return "CreateDevice"; }
128 SetStr(
"DevClass", devclass);
129 SetStr(
"DevName", devname);
135 static const char*
CmdName() {
return "DestroyDevice"; }
140 SetStr(
"DevName", devname);
146 static const char*
CmdName() {
return "CreateThread"; }
150 CmdCreateThread(
const std::string &thrdname,
const std::string &thrdclass =
"",
const std::string &devname =
"") :
154 SetStr(
"ThrdClass", thrdclass);
155 SetStr(
"ThrdDev", devname);
168 SetStr(
"ClassName", classname);
169 SetStr(
"ObjName", objname);
182 static const char*
PortArg() {
return "PortName"; }
183 static const char*
KindArg() {
return "TransportKind"; }
185 CmdCreateTransport(
const std::string &portname,
const std::string &transportkind,
const std::string &thrdname =
"") :
207 SetStr(
"PortName", portname);
220 static const char*
ParName() {
return "ParName"; }
221 static const char*
ParValue() {
return "ParValue"; }
247 static const
char*
States() {
return "States"; }
248 static const char*
NodeId() {
return "NodeId"; }
250 static void SetState(std::string& sbuf,
unsigned node,
bool on)
252 while (sbuf.length() <= node) sbuf.append(
"x");
253 sbuf[node] = on ?
'x' :
'o';
256 static bool GetState(
const std::string &sbuf,
unsigned node)
258 if (node>=sbuf.length())
return false;
259 return sbuf[node] ==
'x';
434 void Sleep(
double tmout,
const char* prefix = 0);
462 virtual const char*
ClassName()
const {
return "Manager"; }
494 bool DecomposeAddress(
const std::string &url,
bool& islocal, std::string& server, std::string& itemtname);
496 std::string
ComposeAddress(
const std::string &server,
const std::string &itemtname =
"");
505 virtual void Print(
int lvl = 0);
595 {
return null() ? std::string() :
GetObject()->GetLocalAddress(); }
598 {
return null() ? std::string() :
GetObject()->GetNodeAddress(nodeid); }
600 bool DecomposeAddress(
const std::string &url,
bool& islocal, std::string& server, std::string& itemtname)
601 {
return null() ?
false :
GetObject()->DecomposeAddress(url, islocal, server, itemtname); }
603 std::string
ComposeAddress(
const std::string &server,
const std::string &itemname =
"")
604 {
return null() ? std::string() :
GetObject()->ComposeAddress(server, itemname); }
606 bool CreateApplication(
const std::string &classname =
"",
const std::string &appthrd =
"");
608 ThreadRef CreateThread(
const std::string &thrdname,
const std::string &classname =
"",
const std::string &devname =
"");
615 bool CreateDevice(
const std::string &classname,
const std::string &devname);
628 unsigned buffersize = 0,
629 unsigned numbuffers = 0);
633 ModuleRef CreateModule(
const std::string &classname,
const std::string &modulename,
const std::string &thrdname =
"");
636 void StopModule(
const std::string &modulename);
641 bool CreateTransport(
const std::string &portname,
const std::string &transportkind =
"",
const std::string &thrdname =
"");
643 void*
CreateAny(
const std::string &classname,
const std::string &objname =
"");
665 {
return null() ?
true : !
GetObject()->fMgrStoppedTime.null(); }
679 void Sleep(
double tmout,
const char* prefix = 0);
687 void RunCmdLoop(
double runtime = 0.,
const std::string &remnode =
"")
696 bool CreateControl(
bool withserver,
int serv_port = 0,
bool allow_clients =
true);
703 extern ManagerRef
mgr;
#define DABC_COMMAND(cmd_class, cmd_name)
#define DABC_REFERENCE(RefClass, ParentClass, T)
Reference on dabc::Application class
Template to put any object, not derived from dabc::Object, into cleanup queue.
virtual ~CleanupEnvelope()
DABC_COMMAND(CmdCleanupApplication, "CleanupManager")
DABC_COMMAND(CmdCreateAny, "CreateAny")
CmdCreateApplication(const std::string &appclass, const std::string &thrdname="")
DABC_COMMAND(CmdCreateApplication, "CreateApplication")
static const char * CmdName()
CmdCreateDevice(const std::string &devclass, const std::string &devname)
static const char * CmdName()
CmdCreateModule(const std::string &classname, const std::string &modulename, const std::string &thrdname="")
CmdCreateObject(const std::string &classname, const std::string &objname)
DABC_COMMAND(CmdCreateObject, "CreateObject")
static const char * ThrdNameArg()
std::string GetThrdName() const
static const char * CmdName()
CmdCreateThread(const std::string &thrdname, const std::string &thrdclass="", const std::string &devname="")
std::string PortName() const
void SetPoolName(const std::string &name)
CmdCreateTransport(const std::string &portname, const std::string &transportkind, const std::string &thrdname="")
std::string PoolName() const
static const char * KindArg()
static const char * PortArg()
std::string TransportKind() const
DABC_COMMAND(CmdCreateTransport, "CreateTransport")
static const char * CmdName()
CmdDeleteModule(const std::string &modulename)
CmdDeletePool(const std::string &name)
static const char * CmdName()
CmdDestroyDevice(const std::string &devname)
static const char * CmdName()
DABC_COMMAND(CmdDestroyTransport, "DestroyTransport")
CmdDestroyTransport(const std::string &portname)
Command to request current state of known nodes
static bool GetState(const std::string &sbuf, unsigned node)
static const char * States()
static void SetState(std::string &sbuf, unsigned node, bool on)
static const char * NodeId()
CmdModule(const char *cmdname, const std::string &module)
static const char * ModuleArg()
RecordField GetParValue()
static const char * ParValue()
static const char * ParName()
DABC_COMMAND(CmdSetParameter, "SetParameter")
void SetParValue(const RecordField &v)
CmdSetParameter(const std::string &parname, const RecordField &v)
CmdSetParameter(const std::string &parname)
CmdStartModule(const std::string &modulename="*")
static const char * CmdName()
CmdStopModule(const std::string &modulename="*")
static const char * CmdName()
Represents command with its arguments.
bool SetStr(const std::string &name, const char *value)
std::string GetStr(const std::string &name, const std::string &dflt="") const
Interface class between xml configuration and dabc objects.
Full-functional class to reading configuration from xml files.
Small helper class to correctly instantiate user-specific factories.
Factory for user-specific classes
Reference on manager object
WorkerRef FindDevice(const std::string &name)
void StopModule(const std::string &modulename)
bool ActivateConnections(double tmout, bool sync=true)
ThreadRef CurrentThread()
Returns reference on the thread, which is now active.
DataInput * CreateDataInput(const std::string &kind)
Create data input, using factories methods.
void RunMainLoop(double runtime=0.)
Run manager main loop.
Reference FindPool(const std::string &name)
ThreadsLayout GetThreadsLayout() const
ModuleRef CreateModule(const std::string &classname, const std::string &modulename, const std::string &thrdname="")
bool CreateTransport(const std::string &portname, const std::string &transportkind="", const std::string &thrdname="")
std::string GetLocalAddress()
Return identifier of local host, which can be used everywhere for node addressing.
bool IsTerminated() const
unsigned NumThreads() const
Reference CreateObject(const std::string &classname, const std::string &objname)
Reference FindPort(const std::string &port)
ConnectionRequest Connect(const std::string &port1, const std::string &port2)
Request connection between two ports.
bool DeleteModule(const std::string &name)
void Sleep(double tmout, const char *prefix=0)
Sleep for specified time, keep thread event loop running See Manager::Sleep() method for more details...
void RunCmdLoop(double runtime=0., const std::string &remnode="")
Run manager command loop.
void StartModule(const std::string &modulename)
Parameter FindPar(const std::string &parname)
ThreadRef FindThread(const std::string &name, const std::string &required_class="")
bool DeletePool(const std::string &name)
bool CleanupApplication()
Method safely deletes all object created for application - modules, devices, memory pools.
Reference FindItem(const std::string &name)
bool DeleteDevice(const std::string &devname)
bool ParameterEventSubscription(Worker *ptr, bool subscribe, const std::string &mask, bool onlychangeevent=true)
std::string ComposeAddress(const std::string &server, const std::string &itemname="")
bool CreateApplication(const std::string &classname="", const std::string &appthrd="")
std::string GetNodeAddress(int nodeid)
bool IsLocalItem(const std::string &name)
Returns true, if name of the item should specify name in local context or from remote node.
bool CreateMemoryPool(const std::string &poolname, unsigned buffersize=0, unsigned numbuffers=0)
Generic method to create memory pool.
bool DecomposeAddress(const std::string &url, bool &islocal, std::string &server, std::string &itemtname)
WorkerRef GetCommandChannel()
void * CreateAny(const std::string &classname, const std::string &objname="")
ModuleRef FindModule(const std::string &name)
bool CreateDevice(const std::string &classname, const std::string &devname)
bool CreatePublisher()
Create publisher, which manage all published hierarchies.
bool CreateControl(bool withserver, int serv_port=0, bool allow_clients=true)
Create command channel Parameter withserver defines if server socket will be created,...
ThreadRef CreateThread(const std::string &thrdname, const std::string &classname="", const std::string &devname="")
Manager of everything in DABC
int NodeId() const
Return nodes id of local node.
WorkerRef DoCreateModule(const std::string &classname, const std::string &modulename, Command cmd)
ModuleRef FindModule(const std::string &name)
static const char * ConnMgrName()
bool IsAnyModuleRunning()
virtual int PreviewCommand(Command cmd)
This method called before command will be executed.
std::string ComposeAddress(const std::string &server, const std::string &itemtname="")
Provides string, which can be used as receiver argument.
void Sleep(double tmout, const char *prefix=0)
Perform sleeping with event loop running.
void ProduceParameterEvent(ParameterContainer *par, int evid)
bool fAppFinished
when true, reply from application was received
std::string GetLastCreatedDevName()
virtual void Print(int lvl=0)
Displays on std output list of running threads and modules.
Reference DoCreateObject(const std::string &classname, const std::string &objname="", Command cmd=nullptr)
std::string fLastCreatedDevName
name of last created device, automatically used for connection establishing
static void ProcessFactory(Factory *factory)
ThreadsLayout fThrLayout
defines distribution of threads
static Factory * fFirstFactories[10]
first factories, which are comming before manager is created
virtual bool Find(ConfigIO &cfg)
Method to locate object in xml file.
WorkerRef FindDevice(const std::string &name)
bool DeleteAnyObject(T *obj)
Delete of any kind of object in manager thread.
bool UnregisterDependency(Object *src, Object *tgt, bool bidirectional=false)
Unregister dependency between objects.
bool InstallSignalHandlers()
static int fInstanceId
magic number which indicates that instance is initialized
Reference FindItem(const std::string &itemname, bool islocal=false)
Find object in manager hierarchy with specified itemname.
static const char * AppThrdName()
TimeStamp fMgrStoppedTime
indicate when manager mainloop was stopped
void RunManagerCmdLoop(double runtime=0., const std::string &remnode="")
Runs manager command loop - when command shell is used.
ReferencesVector * fDestroyQueue
int NumNodes()
Returns number of nodes in the cluster FIXME:probably must be removed.
virtual void ProcessEvent(const EventId &)
bool ProcessParameterEvents()
ThreadRef FindThread(const std::string &name, const std::string &required_class="")
static const char * CmdChlName()
bool ProcessDestroyQueue()
Reference FindPort(const std::string &name)
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
static void SetAutoDestroy(bool on)
Method set flag if manager instance should be destroyed when process finished.
virtual bool ReplyCommand(Command cmd)
Reimplement this method to react on command reply Return true if command can be destroyed by framewor...
bool DoCleanupApplication()
ParamEventReceiverList * fParEventsReceivers
list of workers, registered for receiving of parameter events Used only from manager thread,...
ReferencesVector * fTimedPars
static const char * MgrThrdName()
bool DoCreateMemoryPool(Command cmd)
bool RegisterDependency(Object *src, Object *tgt, bool bidirectional=false)
Register dependency between objects.
static int fFirstFactoriesId
magic number which should be set when fFirstFactories initialized for the first time
RecordsQueue< ParamRec > fParsQueue
void ProcessCtrlCSignal()
Reference GetThreadsFolder(bool force=false)
Return reference on folder with all registered threads.
Reference FindPool(const std::string &name)
WorkerRef GetCommandChannel()
Return reference on command channel.
void RunManagerMainLoop(double runtime=0.)
Runs manager mainloop.
std::string GetNodeAddress(int nodeid)
Return address of the node to be able communicate with it.
virtual double ProcessTimeout(double last_diff)
std::string fLocalAddress
Identifier for the current application Only set when control instance is created Depending on configu...
ThreadRef CurrentThread()
static const char * FactoriesFolderName()
void HaltManager()
Delete all modules and stop manager thread.
virtual const char * ClassName() const
Returns class name of the object instance.
std::string GetLocalAddress()
Return address of current application.
ThreadsLayout GetThreadsLayout() const
void FillItemName(const Object *ptr, std::string &itemname, bool compact=true)
Method should be used to produce name of object, which can be used as item name in different Find met...
Configuration * cfg() const
static const char * ThreadsFolderName()
ThreadRef DoCreateThread(const std::string &thrdname, const std::string &classname="", const std::string &devname="", Command cmd=nullptr)
Create thread with specified name and class name.
static Manager * fInstance
pointer on current manager instance
bool DecomposeAddress(const std::string &url, bool &islocal, std::string &server, std::string &itemtname)
From address like dabc://nodeabc:988/item/subtim extracts server (with port) and itemname If server n...
Reference GetFactoriesFolder(bool force=false)
Return reference on folder with factories.
virtual bool DestroyObject(Reference ref)
Delete derived from Object class object in manager thread.
Reference on dabc::Module class
Base class for most of the DABC classes.
Reference GetFolder(const std::string &name, bool force=false)
Return folder of specified name, no special symbols allowed.
unsigned NumChilds() const
returns number of child objects
Container for parameter object.
Base class for input and output ports.
RecordField GetField(const std::string &name) const
bool SetField(const std::string &name, const RecordField &v)
Template of queue with complex objects.
Reference on the arbitrary object
void Release()
Releases reference on the object.
Object * GetObject() const
Return pointer on the object.
Vector of dabc::Reference objects.
Reference on the dabc::Thread class
Reference on dabc::Worker
Active object, which is working inside dabc::Thread.
const char * xmlThreadAttr
const char * xmlClassAttr
Event structure, exchanged between DABC threads.
ParamRec & operator=(const ParamRec &src)
Parameter par
reference on the parameter
ParamRec(const ParamRec &src)
ParamRec(Parameter p, int e)
Class for acquiring and holding timestamps.