Orocos Real-Time Toolkit  2.8.3
ConnPolicy.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 22 11:59:08 CEST 2009 ConnPolicy.cpp
3 
4  ConnPolicy.cpp - description
5  -------------------
6  begin : Thu October 22 2009
7  copyright : (C) 2009 Peter Soetens
8  email : peter@thesourcworks.com
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 /*
40  * ConnPolicy.cpp
41  *
42  * Created on: Oct 20, 2009
43  * Author: kaltan
44  */
45 
46 #include "ConnPolicy.hpp"
47 #include "Property.hpp"
48 #include "PropertyBag.hpp"
49 
50 using namespace std;
51 
52 namespace RTT
53 {
54  ConnPolicy ConnPolicy::buffer(int size, int lock_policy /*= LOCK_FREE*/, bool init_connection /*= false*/, bool pull /*= false*/)
55  {
56  ConnPolicy result(BUFFER, lock_policy);
57  result.init = init_connection;
58  result.pull = pull;
59  result.size = size;
60  return result;
61  }
62 
63  ConnPolicy ConnPolicy::circularBuffer(int size, int lock_policy /*= LOCK_FREE*/, bool init_connection /*= false*/, bool pull /*= false*/)
64  {
65  ConnPolicy result(CIRCULAR_BUFFER, lock_policy);
66  result.init = init_connection;
67  result.pull = pull;
68  result.size = size;
69  return result;
70  }
71 
72  ConnPolicy ConnPolicy::data(int lock_policy /*= LOCK_FREE*/, bool init_connection /*= true*/, bool pull /*= false*/)
73  {
74  ConnPolicy result(DATA, lock_policy);
75  result.init = init_connection;
76  result.pull = pull;
77  return result;
78  }
79 
80  ConnPolicy::ConnPolicy(int type /* = DATA*/, int lock_policy /*= LOCK_FREE*/)
81  : type(type), init(false), lock_policy(lock_policy), pull(false), size(0), transport(0), data_size(0) {}
82 
86  bool composeProperty(const PropertyBag& bag, ConnPolicy& result)
87  {
88  Property<int> i;
91  if ( bag.getType() != "ConnPolicy")
92  return false;
93  log(Debug) <<"Composing ConnPolicy..." <<endlog();
94  i = bag.getProperty("type");
95  if ( i.ready() )
96  result.type = i.get();
97  else if ( bag.find("type") ){
98  log(Error) <<"ConnPolicy: wrong property type of 'type'."<<endlog();
99  return false;
100  }
101  i = bag.getProperty("lock_policy");
102  if ( i.ready() )
103  result.lock_policy = i.get();
104  else if ( bag.find("lock_policy") ){
105  log(Error) <<"ConnPolicy: wrong property type of 'lock_policy'."<<endlog();
106  return false;
107  }
108  i = bag.getProperty("size");
109  if ( i.ready() )
110  result.size = i.get();
111  else if ( bag.find("size") ){
112  log(Error) <<"ConnPolicy: wrong property type of 'size'."<<endlog();
113  return false;
114  }
115  i = bag.getProperty("data_size");
116  if ( i.ready() )
117  result.data_size = i.get();
118  else if ( bag.find("data_size") ){
119  log(Error) <<"ConnPolicy: wrong property type of 'data_size'."<<endlog();
120  return false;
121  }
122  i = bag.getProperty("transport");
123  if ( i.ready() )
124  result.transport = i.get();
125  else if ( bag.find("transport") ){
126  log(Error) <<"ConnPolicy: wrong property type of 'transport'."<<endlog();
127  return false;
128  }
129 
130  b = bag.getProperty("init");
131  if ( b.ready() )
132  result.init = b.get();
133  else if ( bag.find("init") ){
134  log(Error) <<"ConnPolicy: wrong property type of 'init'."<<endlog();
135  return false;
136  }
137  b = bag.getProperty("pull");
138  if ( b.ready() )
139  result.pull = b.get();
140  else if ( bag.find("pull") ){
141  log(Error) <<"ConnPolicy: wrong property type of 'pull'."<<endlog();
142  return false;
143  }
144 
145  s = bag.getProperty("name_id");
146  if ( s.ready() )
147  result.name_id = s.get();
148  else if ( bag.find("name_id") ){
149  log(Error) <<"ConnPolicy: wrong property type of 'name_id'."<<endlog();
150  return false;
151  }
152  return true;
153  }
154 
158  void decomposeProperty(const ConnPolicy& cp, PropertyBag& targetbag)
159  {
160  log(Debug) <<"Decomposing ConnPolicy..." <<endlog();
161  assert( targetbag.empty() );
162  targetbag.setType("ConnPolicy");
163  targetbag.ownProperty( new Property<int>("type","Data type", cp.type));
164  targetbag.ownProperty( new Property<bool>("init","Initialize flag", cp.init));
165  targetbag.ownProperty( new Property<int>("lock_policy","Locking Policy", cp.lock_policy));
166  targetbag.ownProperty( new Property<bool>("pull","Fetch data over network", cp.pull));
167  targetbag.ownProperty( new Property<int>("size","The size of a buffered connection", cp.size));
168  targetbag.ownProperty( new Property<int>("transport","The prefered transport. Set to zero if unsure.", cp.transport));
169  targetbag.ownProperty( new Property<int>("data_size","A hint about the data size of a single data sample. Set to zero if unsure.", cp.transport));
170  targetbag.ownProperty( new Property<string>("name_id","The name of the connection to be formed.",cp.name_id));
171  }
174 }
DataSourceType get() const
Get a copy of the value of the property.
Definition: Property.hpp:246
bool ready() const
Inspect if this Property is correctly initialised and ready for usage.
const std::string & getType() const
int data_size
Suggest the payload size of the data sent over this channel.
Definition: ConnPolicy.hpp:174
void setType(const std::string &newtype)
STL namespace.
void decomposeProperty(base::PropertyIntrospection *pi, const Property< MultiVector< S, T > > &c)
A decomposeProperty method for decomposing a Property< MultiVector<S,T> > into a PropertyBag with Pro...
int lock_policy
This is the locking policy on the connection.
Definition: ConnPolicy.hpp:152
int type
DATA, BUFFER or CIRCULAR_BUFFER.
Definition: ConnPolicy.hpp:144
A container for holding references to properties.
Definition: PropertyBag.hpp:96
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:92
bool composeProperty(const PropertyBag &bag, Property< MultiVector< S, T > > &result)
A composeProperty method for composing a property of a MultiVector<S, T>
bool ownProperty(base::PropertyBase *p)
Set a property to be owned by this bag.
Definition: PropertyBag.cpp:83
int size
If the connection is a buffered connection, the size of the buffer.
Definition: ConnPolicy.hpp:159
bool pull
If true, then the sink will have to pull data.
Definition: ConnPolicy.hpp:157
base::PropertyBase * find(const std::string &name) const
Find the base::PropertyBase with name name.
A property represents a named value of any type with a description.
Definition: Property.hpp:76
bool empty() const
Return true if no properties are present in this bag.
bool init
If true, one should initialize the connection&#39;s value with the last value written on the writer port...
Definition: ConnPolicy.hpp:150
base::PropertyBase * getProperty(const std::string &name) const
Get a Property with name name.
int transport
The prefered transport used.
Definition: ConnPolicy.hpp:164
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
std::string name_id
The name of this connection.
Definition: ConnPolicy.hpp:182