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::Attribute<std::string> target;
00102
00108 struct ComponentData {
00109 ComponentData()
00110 : instance(0), act(0), loaded(false), loadedProperties(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;
00136 bool loadedProperties;
00137 bool autostart, autoconf, autoconnect, autosave;
00138 bool proxy, server, use_naming;
00139 std::string type, configfile;
00140 };
00141
00145 struct ConnectionData {
00146 typedef std::vector<RTT::PortInterface*> Ports;
00147 typedef std::vector<RTT::TaskContext*> Owners;
00148 Ports ports;
00149 Owners owners;
00150 };
00151
00155 typedef std::map<std::string, ConnectionData> ConMap;
00156 ConMap conmap;
00157
00161 typedef std::map<std::string, ComponentData> CompList;
00162 CompList comps;
00163
00164 static std::string default_comp_path;
00165
00172 bool configureHook();
00173
00178 bool unloadComponentImpl( CompList::iterator cit );
00179
00180
00188 virtual bool componentLoaded(TaskContext* c);
00189
00195 virtual void componentUnloaded(TaskContext* c);
00196
00197 public:
00217 DeploymentComponent(std::string name = "Deployer", std::string siteFile = "");
00218
00225 ~DeploymentComponent();
00226
00227 TaskContext* myGetPeer(std::string name) {return comps[ name ].instance; }
00228
00238 bool connectPeers(const std::string& one, const std::string& other);
00239
00250 bool connectPorts(const std::string& one, const std::string& other);
00251
00265 bool connectPorts(const std::string& one, const std::string& one_port,
00266 const std::string& other, const std::string& other_port);
00267
00277 bool addPeer(const std::string& from, const std::string& to);
00278
00279 using TaskContext::addPeer;
00280 using TaskContext::connectPeers;
00281
00286 bool import(const std::string& path);
00287
00296 bool loadLibrary(const std::string& name);
00297
00309 bool loadComponent(const std::string& name, const std::string& type);
00310
00319 bool unloadComponent(const std::string& name);
00320
00326 void displayComponentTypes() const;
00327
00339 bool setPeriodicActivity(const std::string& comp_name,
00340 double period, int priority,
00341 int scheduler);
00342
00354 bool setActivity(const std::string& comp_name,
00355 double period, int priority,
00356 int scheduler);
00357
00368 bool setNonPeriodicActivity(const std::string& comp_name,
00369 int priority,
00370 int scheduler);
00371
00380 bool setSequentialActivity(const std::string& comp_name);
00381
00391 bool setSlaveActivity(const std::string& comp_name,
00392 double period);
00393
00402 bool setMasterSlaveActivity(const std::string& comp_name,
00403 const std::string& master_name);
00404
00418 bool setNamedActivity(const std::string& comp_name,
00419 const std::string& act_type,
00420 double period, int priority,
00421 int scheduler, const std::string& master_name = "");
00422
00436 bool loadComponents(const std::string& config_file);
00437
00464 bool configureComponents();
00465
00471 bool startComponents();
00472
00477 void clearConfiguration();
00478
00482 bool stopComponents();
00483
00487 bool cleanupComponents();
00488
00492 bool unloadComponents();
00493
00498 bool kickStart(const std::string& file_name);
00499
00505 bool kickOutComponent(const std::string& comp_name);
00506
00511 void kickOut(const std::string& config_file);
00512
00516 bool kickOutAll();
00517
00518
00519 using TaskCore::configure;
00520
00529 bool configure(const std::string& name);
00530
00540 bool configureFromFile(const std::string& name, const std::string& filename);
00541
00556 bool loadConfiguration(const std::string& config_file);
00557
00564 bool loadConfigurationString(const std::string& config_text);
00565
00570 FactoryMap& getFactories();
00571
00577 bool stopComponent(RTT::TaskContext *instance);
00578
00584 bool stopComponent(const std::string& comp_name)
00585 {
00586 return this->stopComponent( this->getPeer(comp_name) );
00587 }
00588
00594 bool cleanupComponent(RTT::TaskContext *instance);
00595
00601 bool cleanupComponent(const std::string& comp_name)
00602 {
00603 return this->cleanupComponent( this->getPeer(comp_name) );
00604 }
00605
00606 };
00607
00608
00609 }
00610 #endif