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
00060 class OCL_API DeploymentComponent
00061 : public RTT::TaskContext
00062 {
00063 protected:
00068 RTT::PropertyBag root;
00069 RTT::Property<std::string> compPath;
00070 RTT::Property<bool> autoUnload;
00071 RTT::Attribute<bool> validConfig;
00072 RTT::Constant<int> sched_RT;
00073 RTT::Constant<int> sched_OTHER;
00074 RTT::Constant<int> lowest_Priority;
00075 RTT::Constant<int> highest_Priority;
00076 RTT::Property<std::string> target;
00077
00083 struct ComponentData {
00084 ComponentData()
00085 : instance(0), act(0), loaded(false),
00086 autostart(false), autoconf(false),
00087 autoconnect(false), autosave(false),
00088 proxy(false), server(false),
00089 use_naming(true),type(""),
00090 configfile("")
00091 {}
00095 RTT::TaskContext* instance;
00100 ActivityInterface* act;
00106 bool loaded;
00107 bool autostart, autoconf, autoconnect, autosave;
00108 bool proxy, server, use_naming;
00109 std::string type, configfile;
00110 };
00111
00115 struct ConnectionData {
00116 typedef std::vector<RTT::PortInterface*> Ports;
00117 typedef std::vector<RTT::TaskContext*> Owners;
00118 Ports ports;
00119 Owners owners;
00120 };
00121
00125 typedef std::map<std::string, ConnectionData> ConMap;
00126 ConMap conmap;
00127
00131 typedef std::map<std::string, ComponentData> CompList;
00132 CompList comps;
00133
00138 class LoadedLib{
00139 public:
00140 LoadedLib(std::string n, void* h)
00141 {
00142 name = n;
00143 handle = h;
00144 }
00145 std::string name;
00146 void* handle;
00147 std::vector<std::string> components_type;
00148 };
00149
00150 static std::vector< LoadedLib > loadedLibs;
00151
00155 void* handle;
00159 std::string libname;
00160
00164 bool configureHook();
00165
00170 bool unloadComponentImpl( CompList::iterator cit );
00171
00172
00180 virtual bool componentLoaded(TaskContext* c);
00181 public:
00182 DeploymentComponent(std::string name = "Configurator");
00183
00184 ~DeploymentComponent();
00185
00186 TaskContext* myGetPeer(std::string name) {return comps[ name ].instance; }
00187
00197 bool connectPeers(const std::string& one, const std::string& other);
00198
00209 bool connectPorts(const std::string& one, const std::string& other);
00210
00224 bool connectPorts(const std::string& one, const std::string& one_port,
00225 const std::string& other, const std::string& other_port);
00226
00236 bool addPeer(const std::string& from, const std::string& to);
00237
00238 using TaskContext::addPeer;
00239 using TaskContext::connectPeers;
00240
00245 bool import(const std::string& path);
00246
00255 bool loadLibrary(const std::string& name);
00256
00268 bool loadComponent(const std::string& name, const std::string& type);
00269
00278 bool unloadComponent(const std::string& name);
00279
00285 void displayComponentTypes() const;
00286
00298 bool setPeriodicActivity(const std::string& comp_name,
00299 double period, int priority,
00300 int scheduler);
00301
00312 bool setNonPeriodicActivity(const std::string& comp_name,
00313 int priority,
00314 int scheduler);
00315
00325 bool setSlaveActivity(const std::string& comp_name,
00326 double period);
00327
00336 bool setMasterSlaveActivity(const std::string& comp_name,
00337 const std::string& master_name);
00338
00352 bool setActivity(const std::string& comp_name,
00353 const std::string& act_type,
00354 double period, int priority,
00355 int scheduler, const std::string& master_name = "");
00356
00370 bool loadComponents(const std::string& config_file);
00371
00398 bool configureComponents();
00399
00405 bool startComponents();
00406
00411 void clearConfiguration();
00412
00416 bool stopComponents();
00417
00421 bool cleanupComponents();
00422
00426 bool unloadComponents();
00427
00432 bool kickStart(const std::string& file_name);
00433
00439 bool kickOutComponent(const std::string& comp_name);
00440
00445 void kickOut(const std::string& config_file);
00446
00450 bool kickOutAll();
00451
00452
00453 using TaskCore::configure;
00454
00463 bool configure(const std::string& name);
00464
00474 bool configureFromFile(const std::string& name, const std::string& filename);
00475
00490 bool loadConfiguration(const std::string& config_file);
00491
00498 bool loadConfigurationString(const std::string& config_text);
00499
00504 FactoryMap& getFactories();
00505
00511 bool stopComponent(RTT::TaskContext *instance);
00512
00518 bool stopComponent(const std::string& comp_name)
00519 {
00520 return this->stopComponent( this->getPeer(comp_name) );
00521 }
00522
00528 bool cleanupComponent(RTT::TaskContext *instance);
00529
00535 bool cleanupComponent(const std::string& comp_name)
00536 {
00537 return this->cleanupComponent( this->getPeer(comp_name) );
00538 }
00539
00540 };
00541
00542
00543 }
00544 #endif