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/extras/Properties.hpp>
00035 #include <rtt/Attribute.hpp>
00036 #include <rtt/InputPort.hpp>
00037 #include <rtt/OutputPort.hpp>
00038 #include <ocl/OCL.hpp>
00039 #include <vector>
00040 #include <map>
00041 #include <rtt/marsh/PropertyDemarshaller.hpp>
00042
00043
00044 #ifndef OCL_STATIC
00045 #define OCL_STATIC
00046 #include <ocl/Component.hpp>
00047 #undef OCL_STATIC
00048 #else
00049 #include <ocl/Component.hpp>
00050 #endif
00051
00052 namespace OCL
00053 {
00054
00086 class OCL_API DeploymentComponent
00087 : public RTT::TaskContext
00088 {
00089 protected:
00094 RTT::PropertyBag root;
00095 std::string compPath;
00096 RTT::Property<bool> autoUnload;
00097 RTT::Attribute<bool> validConfig;
00098 RTT::Constant<int> sched_RT;
00099 RTT::Constant<int> sched_OTHER;
00100 RTT::Constant<int> lowest_Priority;
00101 RTT::Constant<int> highest_Priority;
00102 RTT::Attribute<std::string> target;
00104 int nextGroup;
00105
00111 struct ComponentData {
00112 ComponentData()
00113 : instance(0), act(0), loaded(false), loadedProperties(false),
00114 autostart(false), autoconf(false),
00115 autoconnect(false), autosave(false),
00116 proxy(false), server(false),
00117 use_naming(true),
00118 configfile(""),
00119 group(0)
00120 {}
00124 RTT::TaskContext* instance;
00129 base::ActivityInterface* act;
00135 bool loaded;
00140 bool loadedProperties;
00141 bool autostart, autoconf, autoconnect, autosave;
00142 bool proxy, server, use_naming;
00143 std::string configfile;
00144 vector<string> plugins;
00146 int group;
00147 };
00148
00152 struct ConnectionData {
00153 typedef std::vector<RTT::base::PortInterface*> Ports;
00154 typedef std::vector<RTT::TaskContext*> Owners;
00155 Ports ports;
00156 Owners owners;
00157 RTT::ConnPolicy policy;
00158 };
00159
00163 typedef std::map<std::string, ConnectionData> ConMap;
00164 ConMap conmap;
00165
00169 typedef std::map<std::string, ComponentData> CompList;
00170 CompList comps;
00171
00178 bool configureHook();
00179
00184 bool unloadComponentImpl( CompList::iterator cit );
00185
00186
00194 virtual bool componentLoaded(RTT::TaskContext* c);
00195
00201 virtual void componentUnloaded(RTT::TaskContext* c);
00202
00211 Service::shared_ptr stringToService(string const& names);
00220 base::PortInterface* stringToPort(string const& names);
00221 public:
00241 DeploymentComponent(std::string name = "Deployer", std::string siteFile = "");
00242
00249 ~DeploymentComponent();
00250
00251 RTT::TaskContext* myGetPeer(std::string name) {return comps[ name ].instance; }
00252
00263 bool connectPeers(const std::string& one, const std::string& other);
00264
00265 using TaskContext::connectPorts;
00283 bool connectPorts(const std::string& one, const std::string& other);
00284
00300 bool connectPorts(const std::string& one, const std::string& one_port,
00301 const std::string& other, const std::string& other_port);
00302
00313 bool connect(const std::string& one, const std::string& other, ConnPolicy policy);
00314
00322 bool stream(const std::string& port, ConnPolicy policy);
00323
00327 bool createStream(const std::string& component, const std::string& port, ConnPolicy policy);
00328
00329 using TaskContext::connectServices;
00338 bool connectServices(const std::string& one, const std::string& other);
00339
00350 bool addPeer(const std::string& from, const std::string& target);
00351
00352 using RTT::TaskContext::addPeer;
00353 using RTT::TaskContext::connectPeers;
00354
00369 bool import(const std::string& package);
00370
00378 void path(const std::string& path);
00379
00389 bool loadLibrary(const std::string& name);
00390
00402 bool loadComponent(const std::string& name, const std::string& type);
00403
00418 bool loadService(const std::string& component, const std::string& service);
00419
00428 bool unloadComponent(const std::string& name);
00429
00435 void displayComponentTypes() const;
00436
00442 std::vector<std::string> getComponentTypes() const;
00443
00455 bool setPeriodicActivity(const std::string& comp_name,
00456 double period, int priority,
00457 int scheduler);
00458
00470 bool setActivity(const std::string& comp_name,
00471 double period, int priority,
00472 int scheduler);
00473
00482 bool setSequentialActivity(const std::string& comp_name);
00483
00493 bool setSlaveActivity(const std::string& comp_name,
00494 double period);
00495
00504 bool setMasterSlaveActivity(const std::string& comp_name,
00505 const std::string& master_name);
00506
00520 bool setNamedActivity(const std::string& comp_name,
00521 const std::string& act_type,
00522 double period, int priority,
00523 int scheduler, const std::string& master_name = "");
00524
00540 bool loadComponents(const std::string& config_file);
00554 bool loadComponentsInGroup(const std::string& config_file,
00555 const int group);
00556
00583 bool configureComponents();
00584
00592 bool configureComponentsGroup(const int group);
00593
00599 bool startComponents();
00605 bool startComponentsGroup(const int group);
00606
00611 void clearConfiguration();
00612
00616 bool stopComponents();
00622 bool stopComponentsGroup(const int group);
00623
00627 bool cleanupComponents();
00633 bool cleanupComponentsGroup(const int group);
00634
00638 bool unloadComponents();
00644 bool unloadComponentsGroup(const int group);
00645
00650 bool kickStart(const std::string& file_name);
00651
00657 bool kickOutComponent(const std::string& comp_name);
00658
00663 void kickOut(const std::string& config_file);
00664
00670 bool kickOutAll();
00675 bool kickOutGroup(const int group);
00676
00681 bool runScript(const std::string& file_name);
00682
00683 using base::TaskCore::configure;
00684
00693 bool configure(const std::string& name);
00694
00704 bool configureFromFile(const std::string& name, const std::string& filename);
00705
00720 bool loadConfiguration(const std::string& config_file);
00721
00728 bool loadConfigurationString(const std::string& config_text);
00729
00734 FactoryMap& getFactories();
00735
00741 bool stopComponent(RTT::TaskContext *instance);
00742
00748 bool stopComponent(const std::string& comp_name)
00749 {
00750 return this->stopComponent( this->getPeer(comp_name) );
00751 }
00752
00758 bool cleanupComponent(RTT::TaskContext *instance);
00759
00765 bool cleanupComponent(const std::string& comp_name)
00766 {
00767 return this->cleanupComponent( this->getPeer(comp_name) );
00768 }
00769
00770 };
00771
00772
00773 }
00774 #endif