00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef OCL_DEPLOYMENTCOMPONENT_HPP
00030 #define OCL_DEPLOYMENTCOMPONENT_HPP
00031
00032 #include <rtt/RTT.hpp>
00033 #include <rtt/TaskContext.hpp>
00034 #include <rtt/Properties.hpp>
00035 #include <rtt/Attribute.hpp>
00036 #include <rtt/Ports.hpp>
00037 #include <ocl/OCL.hpp>
00038 #include <vector>
00039 #include <map>
00040 #include <rtt/marsh/PropertyDemarshaller.hpp>
00041
00042
00043 #ifndef OCL_STATIC
00044 #define OCL_STATIC
00045 #include <ocl/ComponentLoader.hpp>
00046 #undef OCL_STATIC
00047 #else
00048 #include <ocl/ComponentLoader.hpp>
00049 #endif
00050
00051 namespace OCL
00052 {
00053
00085 class OCL_API DeploymentComponent
00086 : public RTT::TaskContext
00087 {
00088 protected:
00093 RTT::PropertyBag root;
00094 RTT::Property<std::string> compPath;
00095 RTT::Property<bool> autoUnload;
00096 RTT::Attribute<bool> validConfig;
00097 RTT::Constant<int> sched_RT;
00098 RTT::Constant<int> sched_OTHER;
00099 RTT::Constant<int> lowest_Priority;
00100 RTT::Constant<int> highest_Priority;
00101 RTT::Property<std::string> target;
00102
00108 struct ComponentData {
00109 ComponentData()
00110 : instance(0), act(0), loaded(false),
00111 autostart(false), autoconf(false),
00112 autoconnect(false), autosave(false),
00113 proxy(false), server(false),
00114 use_naming(true),type(""),
00115 configfile("")
00116 {}
00120 RTT::TaskContext* instance;
00125 ActivityInterface* act;
00131 bool loaded;
00132 bool autostart, autoconf, autoconnect, autosave;
00133 bool proxy, server, use_naming;
00134 std::string type, configfile;
00135 };
00136
00140 struct ConnectionData {
00141 typedef std::vector<RTT::PortInterface*> Ports;
00142 typedef std::vector<RTT::TaskContext*> Owners;
00143 Ports ports;
00144 Owners owners;
00145 };
00146
00150 typedef std::map<std::string, ConnectionData> ConMap;
00151 ConMap conmap;
00152
00156 typedef std::map<std::string, ComponentData> CompList;
00157 CompList comps;
00158
00163 class LoadedLib{
00164 public:
00165 LoadedLib(std::string n, void* h)
00166 {
00167 name = n;
00168 handle = h;
00169 }
00170 std::string name;
00171 void* handle;
00172 std::vector<std::string> components_type;
00173 };
00174
00175 static std::vector< LoadedLib > loadedLibs;
00176
00180 void* handle;
00184 std::string libname;
00185
00192 bool configureHook();
00193
00198 bool unloadComponentImpl( CompList::iterator cit );
00199
00200
00208 virtual bool componentLoaded(TaskContext* c);
00209 public:
00229 DeploymentComponent(std::string name = "Deployer", std::string siteFile = "");
00230
00237 ~DeploymentComponent();
00238
00239 TaskContext* myGetPeer(std::string name) {return comps[ name ].instance; }
00240
00250 bool connectPeers(const std::string& one, const std::string& other);
00251
00262 bool connectPorts(const std::string& one, const std::string& other);
00263
00277 bool connectPorts(const std::string& one, const std::string& one_port,
00278 const std::string& other, const std::string& other_port);
00279
00289 bool addPeer(const std::string& from, const std::string& to);
00290
00291 using TaskContext::addPeer;
00292 using TaskContext::connectPeers;
00293
00298 bool import(const std::string& path);
00299
00308 bool loadLibrary(const std::string& name);
00309
00321 bool loadComponent(const std::string& name, const std::string& type);
00322
00331 bool unloadComponent(const std::string& name);
00332
00338 void displayComponentTypes() const;
00339
00351 bool setPeriodicActivity(const std::string& comp_name,
00352 double period, int priority,
00353 int scheduler);
00354
00366 bool setActivity(const std::string& comp_name,
00367 double period, int priority,
00368 int scheduler);
00369
00380 bool setNonPeriodicActivity(const std::string& comp_name,
00381 int priority,
00382 int scheduler);
00383
00392 bool setSequentialActivity(const std::string& comp_name);
00393
00403 bool setSlaveActivity(const std::string& comp_name,
00404 double period);
00405
00414 bool setMasterSlaveActivity(const std::string& comp_name,
00415 const std::string& master_name);
00416
00430 bool setNamedActivity(const std::string& comp_name,
00431 const std::string& act_type,
00432 double period, int priority,
00433 int scheduler, const std::string& master_name = "");
00434
00448 bool loadComponents(const std::string& config_file);
00449
00476 bool configureComponents();
00477
00483 bool startComponents();
00484
00489 void clearConfiguration();
00490
00494 bool stopComponents();
00495
00499 bool cleanupComponents();
00500
00504 bool unloadComponents();
00505
00510 bool kickStart(const std::string& file_name);
00511
00517 bool kickOutComponent(const std::string& comp_name);
00518
00523 void kickOut(const std::string& config_file);
00524
00528 bool kickOutAll();
00529
00530
00531 using TaskCore::configure;
00532
00541 bool configure(const std::string& name);
00542
00552 bool configureFromFile(const std::string& name, const std::string& filename);
00553
00568 bool loadConfiguration(const std::string& config_file);
00569
00576 bool loadConfigurationString(const std::string& config_text);
00577
00582 FactoryMap& getFactories();
00583
00589 bool stopComponent(RTT::TaskContext *instance);
00590
00596 bool stopComponent(const std::string& comp_name)
00597 {
00598 return this->stopComponent( this->getPeer(comp_name) );
00599 }
00600
00606 bool cleanupComponent(RTT::TaskContext *instance);
00607
00613 bool cleanupComponent(const std::string& comp_name)
00614 {
00615 return this->cleanupComponent( this->getPeer(comp_name) );
00616 }
00617
00618 };
00619
00620
00621 }
00622 #endif