YARP
Yet Another Robot Platform
manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_MANAGER_MANAGER
10 #define YARP_MANAGER_MANAGER
11 
12 #include <yarp/manager/ymm-types.h>
13 #include <yarp/manager/kbase.h>
14 #include <yarp/manager/utility.h>
17 
18 namespace yarp {
19 namespace manager {
20 
24 class Manager : public MEvent{
25 
26 public:
27  Manager( bool withWatchDog=false);
28  Manager(const char* szModPath, const char* szAppPath,
29  const char* szResPath, bool withWatchDog=false);
30  ~Manager() override;
31 
32  bool addApplication(const char* szFileName, char** szAppName_=nullptr, bool modifyName=false);
33  bool addApplications(const char* szPath);
34  bool addModule(const char* szFileName);
35  bool addModules(const char* szPath);
36  bool addResource(const char* szFileName);
37  bool addResources(const char* szPath);
38 
39  bool removeApplication(const char* szFileName, const char* szAppName);
40  bool removeModule(const char* szModName);
41  bool removeResource(const char* szResName);
42 
43  bool loadApplication(const char* szAppName);
44  bool saveApplication(const char* szAppName, const char* fileName=nullptr);
45  bool updateExecutable(unsigned int id, const char* szparam,
46  const char* szhost, const char* szstdio,
47  const char* szworkdir, const char* szenv );
48  bool updateConnection(unsigned int id, const char* from,
49  const char* to, const char* carrier);
50 
51  Node* getNode(std::string appName);
52 
53  bool run();
54  bool run(unsigned int id, bool async=false);
55  bool stop();
56  bool stop(unsigned int id, bool async=false);
57  bool kill();
58  bool kill(unsigned int id, bool async=false);
59  bool connect();
60  bool connect(unsigned int id);
61  bool disconnect();
62  bool disconnect(unsigned int id);
63  bool rmconnect(unsigned int id);
64  bool rmconnect();
65  bool running() { return allRunning(); }
66  bool running(unsigned int id);
67  bool suspended() { return allStopped(); }
68  bool suspended(unsigned int id);
69  bool connected();
70  bool connected(unsigned int id);
71  bool checkDependency();
72  bool exist(unsigned int id);
73  bool existPortFrom(unsigned int id);
74  bool existPortTo(unsigned int id);
75  bool attachStdout(unsigned int id);
76  bool detachStdout(unsigned int id);
77  bool updateResources();
78  bool updateResource(const char* szName);
79  bool waitingModuleRun(unsigned int id);
80  bool waitingModuleStop(unsigned int id);
81  bool waitingModuleKill(unsigned int id);
82  bool loadBalance();
83 
84  void setDefaultBroker(const char* szBroker) { if(szBroker) { strDefBroker = szBroker; } }
85  const char* defaultBroker() { return strDefBroker.c_str(); }
86  ExecutablePContainer& getExecutables() { return runnables; }
87  Executable* getExecutableById(size_t id);
88  bool switchBroker(size_t id);
89  CnnContainer& getConnections() { return connections;}
90  ResourcePContainer& getResources() { return resources; }
91  const char* getApplicationName() { return strAppName.c_str(); }
92 
93  //const char* getDataPort(const char* szDataType);
94 
95  void enableRestrictedMode() { bRestricted = true; }
96  void disableRestrictedMode() { bRestricted = false; }
97  void enableAutoConnect() { bAutoConnect = true; }
98  void disableAutoConnect() { bAutoConnect = false; }
99  void enableAutoDependency() { bAutoDependancy = true; }
100  void disableAutoDependency() { bAutoDependancy = false; }
101  void enableWatchDog() { bWithWatchDog = true; }
102  void disableWatchod() { bWithWatchDog = false; }
103  bool exportDependencyGraph(const char* szFileName) {
104  return knowledge.exportAppGraph(szFileName);
105  }
106 
107  KnowledgeBase* getKnowledgeBase() { return &knowledge; }
108  ErrorLogger* getLogger() { return logger;}
109 
110 protected:
111  void onExecutableStart(void* which) override;
112  void onExecutableStop(void* which) override;
113  void onExecutableDied(void* which) override;
114  void onExecutableFailed(void* which) override;
115  void onCnnStablished(void* which) override;
116  void onCnnFailed(void* which) override;
117  void onError(void* which) override;
118  void onExecutableStdout(void* which, const char* msg) override;
119 
120 
121 private:
122  bool bWithWatchDog;
123  bool bAutoDependancy;
124  bool bAutoConnect;
125  bool bRestricted;
126  ErrorLogger* logger;
127  std::string strAppName;
128  std::string strDefBroker;
129  YarpBroker connector;
130  std::vector<std::string> listOfXml;
131 
132  KnowledgeBase knowledge;
133  ExecutablePContainer runnables;
134  CnnContainer connections;
135  ModulePContainer modules;
136  ResourcePContainer resources;
137 
138  bool createKnowledgeBase(AppLoader &appLoader);
139  void clearExecutables();
140  bool isServer(Module* module);
141  bool connectExtraPorts();
142  bool checkPortsAvailable(Broker* broker);
143  bool allRunning();
144  bool oneRunning();
145  bool allStopped();
146  bool prepare(bool silent=true);
147  bool timeout(double base, double t);
148  bool updateResource(GenericResource* resource);
149  Broker* createBroker(Module* module);
150  bool removeBroker(Executable* exe);
151 };
152 
153 } // namespace yarp
154 } // namespace manager
155 
156 
157 #endif // __YARP_MANAGER_MANAGER__
executable.h
yarp::manager::Manager::getResources
ResourcePContainer & getResources()
Definition: manager.h:90
yarp::manager::Manager::loadBalance
bool loadBalance()
Definition: manager.cpp:261
yarp::manager::Manager::enableAutoDependency
void enableAutoDependency()
Definition: manager.h:99
yarp::manager::Manager::removeModule
bool removeModule(const char *szModName)
Definition: manager.cpp:190
yarp::manager::Manager::~Manager
~Manager() override
Definition: manager.cpp:84
yarp::manager::Manager::kill
bool kill()
Definition: manager.cpp:941
yarp::manager::Manager::addApplication
bool addApplication(const char *szFileName, char **szAppName_=nullptr, bool modifyName=false)
Definition: manager.cpp:91
yarp::manager::Manager::disableRestrictedMode
void disableRestrictedMode()
Definition: manager.h:96
t
float t
Definition: FfmpegWriter.cpp:74
yarp::manager::Manager::removeResource
bool removeResource(const char *szResName)
Definition: manager.cpp:207
yarp::manager::Manager::onExecutableDied
void onExecutableDied(void *which) override
Definition: manager.cpp:1293
yarp::manager::CnnContainer
std::vector< Connection > CnnContainer
Definition: application.h:153
yarp::manager::Manager::exportDependencyGraph
bool exportDependencyGraph(const char *szFileName)
Definition: manager.h:103
yarp::manager::Manager::onExecutableStdout
void onExecutableStdout(void *which, const char *msg) override
Definition: manager.cpp:1295
yarp::manager::Manager::addModule
bool addModule(const char *szFileName)
Definition: manager.cpp:124
yarp::manager::Manager::loadApplication
bool loadApplication(const char *szAppName)
Definition: manager.cpp:226
yarp::manager::Manager::Manager
Manager(bool withWatchDog=false)
Class Manager.
Definition: manager.cpp:42
yarp::manager::Manager::running
bool running()
Definition: manager.h:65
yarp::manager::Manager::onCnnFailed
void onCnnFailed(void *which) override
Definition: manager.cpp:1296
yarp::manager::Manager::onExecutableStart
void onExecutableStart(void *which) override
Definition: manager.cpp:1290
yarp::manager::ErrorLogger
Singleton class ErrorLogger.
Definition: utility.h:60
yarp::manager::Manager::addResources
bool addResources(const char *szPath)
Definition: manager.cpp:161
yarp::manager::Manager::onExecutableStop
void onExecutableStop(void *which) override
Definition: manager.cpp:1291
yarp::manager::Broker
Class Broker.
Definition: broker.h:34
yarp::manager::Manager::updateResources
bool updateResources()
Definition: manager.cpp:531
yarp::manager::ResourcePContainer
std::vector< GenericResource * > ResourcePContainer
Definition: resource.h:62
utility.h
yarp::manager::Manager::switchBroker
bool switchBroker(size_t id)
Definition: manager.cpp:280
yarp::manager::Manager::onExecutableFailed
void onExecutableFailed(void *which) override
Definition: manager.cpp:1294
yarp::manager::Manager::run
bool run()
Definition: manager.cpp:783
yarp::manager::Manager::addModules
bool addModules(const char *szPath)
Definition: manager.cpp:136
yarp::manager::Module
Class Module.
Definition: module.h:103
yarp::manager::Manager::existPortFrom
bool existPortFrom(unsigned int id)
Definition: manager.cpp:694
yarp::manager::Manager::addResource
bool addResource(const char *szFileName)
Definition: manager.cpp:148
yarp::manager::Manager::connect
bool connect()
Definition: manager.cpp:1018
yarp::manager::Manager::checkDependency
bool checkDependency()
Definition: manager.cpp:722
yarp::manager::Manager::saveApplication
bool saveApplication(const char *szAppName, const char *fileName=nullptr)
Definition: manager.cpp:251
yarp::manager::Manager::exist
bool exist(unsigned int id)
Definition: manager.cpp:469
yarp::manager::Manager::detachStdout
bool detachStdout(unsigned int id)
Definition: manager.cpp:1269
yarp::manager::Manager::updateConnection
bool updateConnection(unsigned int id, const char *from, const char *to, const char *carrier)
Definition: manager.cpp:436
yarp::manager::Manager::removeApplication
bool removeApplication(const char *szFileName, const char *szAppName)
Definition: manager.cpp:173
yarp::manager::Manager::disconnect
bool disconnect()
Definition: manager.cpp:1068
yarp::manager::Manager::getExecutables
ExecutablePContainer & getExecutables()
Definition: manager.h:86
yarp::manager::Manager::existPortTo
bool existPortTo(unsigned int id)
Definition: manager.cpp:708
yarp::manager::Manager::stop
bool stop()
Definition: manager.cpp:883
yarp::manager::Node
a Node of a Graph
Definition: node.h:68
yarp::manager::Manager::attachStdout
bool attachStdout(unsigned int id)
Definition: manager.cpp:1247
yarp::manager::MEvent
Definition: executable.h:51
yarp::manager::Manager::waitingModuleKill
bool waitingModuleKill(unsigned int id)
Definition: manager.cpp:677
yarp::manager::KnowledgeBase::exportAppGraph
bool exportAppGraph(const char *szFileName)
Definition: kbase.h:117
yarp::manager::Manager::disableWatchod
void disableWatchod()
Definition: manager.h:102
yarp::manager::KnowledgeBase
Class KnowledgeBase.
Definition: kbase.h:36
ymm-types.h
yarp::manager::Manager::addApplications
bool addApplications(const char *szPath)
Definition: manager.cpp:108
yarp::manager::Manager
Class Manager.
Definition: manager.h:24
yarp::manager::YarpBroker
Class Broker.
Definition: yarpbroker.h:37
module
static RFModule * module
Definition: RFModule.cpp:234
yarp::manager::Manager::waitingModuleStop
bool waitingModuleStop(unsigned int id)
Definition: manager.cpp:662
yarp::manager::Manager::connected
bool connected()
Definition: manager.cpp:1132
yarp::manager::Manager::onError
void onError(void *which) override
Definition: manager.cpp:1297
yarp::manager::Manager::waitingModuleRun
bool waitingModuleRun(unsigned int id)
Definition: manager.cpp:645
yarpbroker.h
yarp::manager::Manager::getExecutableById
Executable * getExecutableById(size_t id)
Definition: manager.cpp:268
yarp::manager::Manager::updateExecutable
bool updateExecutable(unsigned int id, const char *szparam, const char *szhost, const char *szstdio, const char *szworkdir, const char *szenv)
Definition: manager.cpp:410
yarp::manager::Manager::getKnowledgeBase
KnowledgeBase * getKnowledgeBase()
Definition: manager.h:107
yarp::manager::Manager::enableRestrictedMode
void enableRestrictedMode()
Definition: manager.h:95
yarp::manager::Manager::suspended
bool suspended()
Definition: manager.h:67
yarp::manager::GenericResource
Definition: resource.h:21
kbase.h
yarp::manager::Manager::updateResource
bool updateResource(const char *szName)
Definition: manager.cpp:582
yarp::manager::Manager::setDefaultBroker
void setDefaultBroker(const char *szBroker)
Definition: manager.h:84
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::manager::Manager::disableAutoDependency
void disableAutoDependency()
Definition: manager.h:100
yarp::manager::Manager::defaultBroker
const char * defaultBroker()
Definition: manager.h:85
yarp::manager::Manager::enableAutoConnect
void enableAutoConnect()
Definition: manager.h:97
yarp::manager::ModulePContainer
std::vector< Module * > ModulePContainer
Definition: module.h:234
yarp::manager::ExecutablePContainer
std::vector< Executable * > ExecutablePContainer
Definition: executable.h:170
yarp::manager::Manager::rmconnect
bool rmconnect()
Definition: manager.cpp:1103
yarp::manager::Manager::getLogger
ErrorLogger * getLogger()
Definition: manager.h:108
yarp::manager::Manager::getApplicationName
const char * getApplicationName()
Definition: manager.h:91
yarp::manager::Manager::enableWatchDog
void enableWatchDog()
Definition: manager.h:101
yarp::manager::Manager::getConnections
CnnContainer & getConnections()
Definition: manager.h:89
yarp::manager::AppLoader
Abstract Class AppLoader.
Definition: manifestloader.h:24
yarp::manager::Executable
Class Executable.
Definition: executable.h:75
yarp::manager::Manager::disableAutoConnect
void disableAutoConnect()
Definition: manager.h:98
yarp::manager::Manager::getNode
Node * getNode(std::string appName)
Definition: manager.cpp:463
yarp::manager::Manager::onCnnStablished
void onCnnStablished(void *which) override
Definition: manager.cpp:1292