OrocosComponentLibrary  2.8.3
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 
238  bool waitForSignal(int signumber);
239 
244  bool waitForInterrupt();
245 
246  public:
266  DeploymentComponent(std::string name = "Deployer", std::string siteFile = "");
267 
275 
276  RTT::TaskContext* myGetPeer(std::string name) {return compmap[ name ].instance; }
277 
288  bool connectPeers(const std::string& one, const std::string& other);
289 
290  using TaskContext::connectPorts;
308  bool connectPorts(const std::string& one, const std::string& other);
309 
325  bool connectPorts(const std::string& one, const std::string& one_port,
326  const std::string& other, const std::string& other_port);
327 
338  bool connect(const std::string& one, const std::string& other, ConnPolicy policy);
339 
347  bool stream(const std::string& port, ConnPolicy policy);
348 
352  bool createStream(const std::string& component, const std::string& port, ConnPolicy policy);
353 
354  using TaskContext::connectServices;
363  bool connectServices(const std::string& one, const std::string& other);
364 
371  bool connectOperations(const std::string& required, const std::string& provided);
372 
383  bool addPeer(const std::string& from, const std::string& target);
384 
396  bool aliasPeer(const std::string& from, const std::string& target, const std::string& alias);
397 
398  using RTT::TaskContext::addPeer;
399  using RTT::TaskContext::connectPeers;
400 
415  bool import(const std::string& package);
416 
424  void path(const std::string& path);
425 
435  bool loadLibrary(const std::string& name);
436 
446  bool reloadLibrary(const std::string& filepath);
447 
459  bool loadComponent(const std::string& name, const std::string& type);
460 
475  bool loadService(const std::string& component, const std::string& service);
476 
485  bool unloadComponent(const std::string& name);
486 
492  void displayComponentTypes() const;
493 
499  std::vector<std::string> getComponentTypes() const;
500 
512  bool setPeriodicActivity(const std::string& comp_name,
513  double period, int priority,
514  int scheduler);
515 
527  bool setActivity(const std::string& comp_name,
528  double period, int priority,
529  int scheduler);
530 
542  bool setFileDescriptorActivity(const std::string& comp_name,
543  double timeout, int priority,
544  int scheduler);
545 
558  bool setActivityOnCPU(const std::string& comp_name,
559  double period, int priority,
560  int scheduler, unsigned int cpu_nr);
561 
570  bool setSequentialActivity(const std::string& comp_name);
571 
581  bool setSlaveActivity(const std::string& comp_name,
582  double period);
583 
592  bool setMasterSlaveActivity(const std::string& comp_name,
593  const std::string& master_name);
594 
610  bool setNamedActivity(const std::string& comp_name,
611  const std::string& act_type,
612  double period, int priority,
613  int scheduler, const std::string& master_name = "");
614 
629  bool setNamedActivity(const std::string& comp_name,
630  const std::string& act_type,
631  double period, int priority,
632  int scheduler, unsigned cpu_affinity,
633  const std::string& master_name = "");
634 
643  bool setWaitPeriodPolicy(const std::string& comp_name,
644  int policy);
645 
661  bool loadComponents(const std::string& config_file);
675  bool loadComponentsInGroup(const std::string& config_file,
676  const int group);
677 
704  bool configureComponents();
705 
713  bool configureComponentsGroup(const int group);
714 
720  bool startComponents();
726  bool startComponentsGroup(const int group);
727 
732  void clearConfiguration();
733 
737  bool stopComponents();
743  bool stopComponentsGroup(const int group);
744 
748  bool cleanupComponents();
754  bool cleanupComponentsGroup(const int group);
755 
759  bool unloadComponents();
765  bool unloadComponentsGroup(const int group);
766 
771  bool kickStart(const std::string& file_name);
772 
778  bool kickOutComponent(const std::string& comp_name);
779 
784  void kickOut(const std::string& config_file);
785 
791  bool kickOutAll();
796  bool kickOutGroup(const int group);
797 
802  bool runScript(const std::string& file_name);
803 
804  using base::TaskCore::configure;
805 
814  bool configure(const std::string& name);
815 
825  bool configureFromFile(const std::string& name, const std::string& filename);
826 
841  bool loadConfiguration(const std::string& config_file);
842 
849  bool loadConfigurationString(const std::string& config_text);
850 
855  const RTT::FactoryMap& getFactories() const;
856 
862  bool configureComponent(RTT::TaskContext *instance);
863 
869  bool configureComponent(const std::string& comp_name)
870  {
871  return this->configureComponent( this->getPeer(comp_name) );
872  }
873 
879  bool startComponent(RTT::TaskContext *instance);
880 
886  bool startComponent(const std::string& comp_name)
887  {
888  return this->startComponent( this->getPeer(comp_name) );
889  }
890 
896  bool stopComponent(RTT::TaskContext *instance);
897 
903  bool stopComponent(const std::string& comp_name)
904  {
905  return this->stopComponent( this->getPeer(comp_name) );
906  }
907 
913  bool cleanupComponent(RTT::TaskContext *instance);
914 
920  bool cleanupComponent(const std::string& comp_name)
921  {
922  return this->cleanupComponent( this->getPeer(comp_name) );
923  }
924 
932  void shutdownDeployment();
933 
934  };
935 
936 
937 }
938 #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.