OrocosComponentLibrary
2.7.0
|
00001 /*************************************************************************** 00002 tag: Peter Soetens Thu Jul 3 15:34:31 CEST 2008 DeploymentComponent.hpp 00003 00004 DeploymentComponent.hpp - description 00005 ------------------- 00006 begin : Thu July 03 2008 00007 copyright : (C) 2008 Peter Soetens 00008 email : peter.soetens@fmtc.be 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU Lesser General Public * 00013 * License as published by the Free Software Foundation; either * 00014 * version 2.1 of the License, or (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00019 * Lesser General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation, Inc., 59 Temple Place, * 00024 * Suite 330, Boston, MA 02111-1307 USA * 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 // Suppress warnings in ocl/Component.hpp 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 std::vector<std::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(std::string const& names); 00220 ServiceRequester::shared_ptr stringToServiceRequester(std::string const& names); 00229 base::PortInterface* stringToPort(std::string const& names); 00230 00235 bool waitForSignal(int signumber); 00236 00241 bool waitForInterrupt(); 00242 00243 public: 00263 DeploymentComponent(std::string name = "Deployer", std::string siteFile = ""); 00264 00271 ~DeploymentComponent(); 00272 00273 RTT::TaskContext* myGetPeer(std::string name) {return comps[ name ].instance; } 00274 00285 bool connectPeers(const std::string& one, const std::string& other); 00286 00287 using TaskContext::connectPorts; 00305 bool connectPorts(const std::string& one, const std::string& other); 00306 00322 bool connectPorts(const std::string& one, const std::string& one_port, 00323 const std::string& other, const std::string& other_port); 00324 00335 bool connect(const std::string& one, const std::string& other, ConnPolicy policy); 00336 00344 bool stream(const std::string& port, ConnPolicy policy); 00345 00349 bool createStream(const std::string& component, const std::string& port, ConnPolicy policy); 00350 00351 using TaskContext::connectServices; 00360 bool connectServices(const std::string& one, const std::string& other); 00361 00368 bool connectOperations(const std::string& required, const std::string& provided); 00369 00380 bool addPeer(const std::string& from, const std::string& target); 00381 00393 bool aliasPeer(const std::string& from, const std::string& target, const std::string& alias); 00394 00395 using RTT::TaskContext::addPeer; 00396 using RTT::TaskContext::connectPeers; 00397 00412 bool import(const std::string& package); 00413 00421 void path(const std::string& path); 00422 00432 bool loadLibrary(const std::string& name); 00433 00443 bool reloadLibrary(const std::string& filepath); 00444 00456 bool loadComponent(const std::string& name, const std::string& type); 00457 00472 bool loadService(const std::string& component, const std::string& service); 00473 00482 bool unloadComponent(const std::string& name); 00483 00489 void displayComponentTypes() const; 00490 00496 std::vector<std::string> getComponentTypes() const; 00497 00509 bool setPeriodicActivity(const std::string& comp_name, 00510 double period, int priority, 00511 int scheduler); 00512 00524 bool setActivity(const std::string& comp_name, 00525 double period, int priority, 00526 int scheduler); 00527 00539 bool setFileDescriptorActivity(const std::string& comp_name, 00540 double timeout, int priority, 00541 int scheduler); 00542 00555 bool setActivityOnCPU(const std::string& comp_name, 00556 double period, int priority, 00557 int scheduler, unsigned int cpu_nr); 00558 00567 bool setSequentialActivity(const std::string& comp_name); 00568 00578 bool setSlaveActivity(const std::string& comp_name, 00579 double period); 00580 00589 bool setMasterSlaveActivity(const std::string& comp_name, 00590 const std::string& master_name); 00591 00607 bool setNamedActivity(const std::string& comp_name, 00608 const std::string& act_type, 00609 double period, int priority, 00610 int scheduler, const std::string& master_name = ""); 00611 00626 bool setNamedActivity(const std::string& comp_name, 00627 const std::string& act_type, 00628 double period, int priority, 00629 int scheduler, unsigned cpu_affinity, 00630 const std::string& master_name = ""); 00631 00647 bool loadComponents(const std::string& config_file); 00661 bool loadComponentsInGroup(const std::string& config_file, 00662 const int group); 00663 00690 bool configureComponents(); 00691 00699 bool configureComponentsGroup(const int group); 00700 00706 bool startComponents(); 00712 bool startComponentsGroup(const int group); 00713 00718 void clearConfiguration(); 00719 00723 bool stopComponents(); 00729 bool stopComponentsGroup(const int group); 00730 00734 bool cleanupComponents(); 00740 bool cleanupComponentsGroup(const int group); 00741 00745 bool unloadComponents(); 00751 bool unloadComponentsGroup(const int group); 00752 00757 bool kickStart(const std::string& file_name); 00758 00764 bool kickOutComponent(const std::string& comp_name); 00765 00770 void kickOut(const std::string& config_file); 00771 00777 bool kickOutAll(); 00782 bool kickOutGroup(const int group); 00783 00788 bool runScript(const std::string& file_name); 00789 00790 using base::TaskCore::configure; 00791 00800 bool configure(const std::string& name); 00801 00811 bool configureFromFile(const std::string& name, const std::string& filename); 00812 00827 bool loadConfiguration(const std::string& config_file); 00828 00835 bool loadConfigurationString(const std::string& config_text); 00836 00841 const RTT::FactoryMap& getFactories() const; 00842 00848 bool stopComponent(RTT::TaskContext *instance); 00849 00855 bool stopComponent(const std::string& comp_name) 00856 { 00857 return this->stopComponent( this->getPeer(comp_name) ); 00858 } 00859 00865 bool cleanupComponent(RTT::TaskContext *instance); 00866 00872 bool cleanupComponent(const std::string& comp_name) 00873 { 00874 return this->cleanupComponent( this->getPeer(comp_name) ); 00875 } 00876 00883 void shutdownDeployment(); 00884 00885 }; 00886 00887 00888 } 00889 #endif