OrocosComponentLibrary  2.9.0
DeploymentComponent.hpp
1 /***************************************************************************
2  tag: Peter Soetens Thu Jul 3 15:34:31 CEST 2008 DeploymentComponent.hpp
3 
4  DeploymentComponent.hpp - description
5  -------------------
6  begin : Thu July 03 2008
7  copyright : (C) 2008 Peter Soetens
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2.1 of the License, or (at your option) any later version. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19  * Lesser General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this library; if not, write to the Free Software *
23  * Foundation, Inc., 59 Temple Place, *
24  * Suite 330, Boston, MA 02111-1307 USA *
25  * *
26  ***************************************************************************/
27 
28 
29 #ifndef OCL_DEPLOYMENTCOMPONENT_HPP
30 #define OCL_DEPLOYMENTCOMPONENT_HPP
31 
32 #include <rtt/RTT.hpp>
33 #include <rtt/TaskContext.hpp>
34 #include <rtt/extras/Properties.hpp>
35 #include <rtt/Attribute.hpp>
36 #include <rtt/InputPort.hpp>
37 #include <rtt/OutputPort.hpp>
38 #include <ocl/OCL.hpp>
39 #include <vector>
40 #include <map>
41 #include <rtt/marsh/PropertyDemarshaller.hpp>
42 
43 // Suppress warnings in ocl/Component.hpp
44 #ifndef OCL_STATIC
45 #define OCL_STATIC
46 #include <ocl/Component.hpp>
47 #undef OCL_STATIC
48 #else
49 #include <ocl/Component.hpp>
50 #endif
51 
52 namespace OCL
53 {
54 
86  class OCL_API DeploymentComponent
87  : public RTT::TaskContext
88  {
89  protected:
94  RTT::PropertyBag root;
95  std::string compPath;
96  int defaultWaitPeriodPolicy;
97  RTT::Property<bool> autoUnload;
98  RTT::Attribute<bool> validConfig;
99  RTT::Constant<int> sched_RT;
100  RTT::Constant<int> sched_OTHER;
101  RTT::Constant<int> lowest_Priority;
102  RTT::Constant<int> highest_Priority;
103  RTT::Attribute<std::string> target;
106 
112  struct ComponentData {
113  ComponentData()
114  : instance(0), act(0), loaded(false), loadedProperties(false),
115  autostart(false), autoconf(false),
116  autoconnect(false), autosave(false),
117  proxy(false), server(false),
118  use_naming(true),
119  configfile(""),
120  group(0)
121  {}
125  RTT::TaskContext* instance;
130  base::ActivityInterface* act;
136  bool loaded;
142  bool autostart, autoconf, autoconnect, autosave;
143  bool proxy, server, use_naming;
144  std::string configfile;
145  std::vector<std::string> plugins;
147  int group;
148  };
149 
153  struct ConnectionData {
154  typedef std::vector<RTT::base::PortInterface*> Ports;
155  typedef std::vector<RTT::TaskContext*> Owners;
156  Ports ports;
157  Owners owners;
158  RTT::ConnPolicy policy;
159  };
160 
164  typedef std::map<std::string, ConnectionData> ConMap;
165  ConMap conmap;
166 
170  typedef std::map<std::string, ComponentData> CompMap;
171  typedef std::list<std::string> CompList;
172  CompMap compmap;
173  CompList comps;
174 
181  bool configureHook();
182 
187  bool unloadComponentImpl( CompMap::iterator cit );
188 
189 
197  virtual bool componentLoaded(RTT::TaskContext* c);
198 
204  virtual void componentUnloaded(RTT::TaskContext* c);
205 
214  Service::shared_ptr stringToService(std::string const& names);
223  ServiceRequester::shared_ptr stringToServiceRequester(std::string const& names);
232  base::PortInterface* stringToPort(std::string const& names);
233 
234  public:
254  DeploymentComponent(std::string name = "Deployer", std::string siteFile = "");
255 
263 
264  RTT::TaskContext* myGetPeer(std::string name) {return compmap[ name ].instance; }
265 
276  bool connectPeers(const std::string& one, const std::string& other);
277 
278  using TaskContext::connectPorts;
296  bool connectPorts(const std::string& one, const std::string& other);
297 
313  bool connectPorts(const std::string& one, const std::string& one_port,
314  const std::string& other, const std::string& other_port);
315 
326  bool connect(const std::string& one, const std::string& other, ConnPolicy policy);
327 
335  bool stream(const std::string& port, ConnPolicy policy);
336 
340  bool createStream(const std::string& component, const std::string& port, ConnPolicy policy);
341 
342  using TaskContext::connectServices;
351  bool connectServices(const std::string& one, const std::string& other);
352 
359  bool connectOperations(const std::string& required, const std::string& provided);
360 
371  bool addPeer(const std::string& from, const std::string& target);
372 
384  bool aliasPeer(const std::string& from, const std::string& target, const std::string& alias);
385 
386  using RTT::TaskContext::addPeer;
387  using RTT::TaskContext::connectPeers;
388 
403  bool import(const std::string& package);
404 
412  void path(const std::string& path);
413 
423  bool loadLibrary(const std::string& name);
424 
434  bool reloadLibrary(const std::string& filepath);
435 
447  bool loadComponent(const std::string& name, const std::string& type);
448 
463  bool loadService(const std::string& component, const std::string& service);
464 
473  bool unloadComponent(const std::string& name);
474 
480  void displayComponentTypes() const;
481 
487  std::vector<std::string> getComponentTypes() const;
488 
500  bool setPeriodicActivity(const std::string& comp_name,
501  double period, int priority,
502  int scheduler);
503 
515  bool setActivity(const std::string& comp_name,
516  double period, int priority,
517  int scheduler);
518 
530  bool setFileDescriptorActivity(const std::string& comp_name,
531  double timeout, int priority,
532  int scheduler);
533 
546  bool setActivityOnCPU(const std::string& comp_name,
547  double period, int priority,
548  int scheduler, unsigned int cpu_nr);
549 
558  bool setSequentialActivity(const std::string& comp_name);
559 
569  bool setSlaveActivity(const std::string& comp_name,
570  double period);
571 
580  bool setMasterSlaveActivity(const std::string& comp_name,
581  const std::string& master_name);
582 
598  bool setNamedActivity(const std::string& comp_name,
599  const std::string& act_type,
600  double period, int priority,
601  int scheduler, const std::string& master_name = "");
602 
617  bool setNamedActivity(const std::string& comp_name,
618  const std::string& act_type,
619  double period, int priority,
620  int scheduler, unsigned cpu_affinity,
621  const std::string& master_name = "");
622 
631  bool setWaitPeriodPolicy(const std::string& comp_name,
632  int policy);
633 
649  bool loadComponents(const std::string& config_file);
663  bool loadComponentsInGroup(const std::string& config_file,
664  const int group);
665 
692  bool configureComponents();
693 
701  bool configureComponentsGroup(const int group);
702 
708  bool startComponents();
714  bool startComponentsGroup(const int group);
715 
720  void clearConfiguration();
721 
725  bool stopComponents();
731  bool stopComponentsGroup(const int group);
732 
736  bool cleanupComponents();
742  bool cleanupComponentsGroup(const int group);
743 
747  bool unloadComponents();
753  bool unloadComponentsGroup(const int group);
754 
759  bool kickStart(const std::string& file_name);
760 
766  bool kickOutComponent(const std::string& comp_name);
767 
772  void kickOut(const std::string& config_file);
773 
779  bool kickOutAll();
784  bool kickOutGroup(const int group);
785 
790  bool runScript(const std::string& file_name);
791 
792  using base::TaskCore::configure;
793 
802  bool configure(const std::string& name);
803 
813  bool configureFromFile(const std::string& name, const std::string& filename);
814 
829  bool loadConfiguration(const std::string& config_file);
830 
837  bool loadConfigurationString(const std::string& config_text);
838 
843  const RTT::FactoryMap& getFactories() const;
844 
850  bool configureComponent(RTT::TaskContext *instance);
851 
857  bool configureComponent(const std::string& comp_name)
858  {
859  return this->configureComponent( this->getPeer(comp_name) );
860  }
861 
867  bool startComponent(RTT::TaskContext *instance);
868 
874  bool startComponent(const std::string& comp_name)
875  {
876  return this->startComponent( this->getPeer(comp_name) );
877  }
878 
884  bool stopComponent(RTT::TaskContext *instance);
885 
891  bool stopComponent(const std::string& comp_name)
892  {
893  return this->stopComponent( this->getPeer(comp_name) );
894  }
895 
901  bool cleanupComponent(RTT::TaskContext *instance);
902 
908  bool cleanupComponent(const std::string& comp_name)
909  {
910  return this->cleanupComponent( this->getPeer(comp_name) );
911  }
912 
920  void shutdownDeployment();
921 
928  bool waitForSignals(int *sigs, std::size_t sig_count);
929 
934  bool waitForSignal(int signumber);
935 
940  bool waitForInterrupt();
941 
942  };
943 
944 
945 }
946 #endif
std::map< std::string, ComponentData > CompMap
This list and map hold the dynamically loaded components.
int group
Group number this component belongs to.
base::ActivityInterface * act
The activity created by DeploymentComponent.
Assembles all ports which share a connection.
std::map< std::string, ConnectionData > ConMap
This maps connection names to associated ports.
bool stopComponent(const std::string &comp_name)
Stop a single loaded and running components.
int nextGroup
Next group number.
bool configureComponent(const std::string &comp_name)
Configure a single loaded and running components.
RTT::TaskContext * instance
The component instance.
This file contains the macros and definitions to create dynamically loadable components.
bool cleanupComponent(const std::string &comp_name)
Cleanup a single loaded and not running component.
bool startComponent(const std::string &comp_name)
Stop a single loaded and running components.
The Orocos Component Library.
Definition: Component.hpp:43
bool loaded
True if it was loaded and created by DeploymentComponent.
A Component for deploying (configuring) other components in an application.
bool loadedProperties
True if successfully loaded a property file, and so will need auto-saving (it autosave is on) ...
Each configured component is stored in a struct like this.
RTT::PropertyBag root
This bag stores the current configuration.