Skip to content

Commit a43c7a7

Browse files
committed
Merge branch 'updated-dataflow-semantics-connpolicy' into updated-dataflow-semantics-rebased
2 parents bf9f4c7 + 0e1c2b9 commit a43c7a7

13 files changed

+526
-160
lines changed

rtt/ConnPolicy.cpp

Lines changed: 105 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -47,128 +47,144 @@
4747
#include "Property.hpp"
4848
#include "PropertyBag.hpp"
4949

50+
#include <boost/lexical_cast.hpp>
51+
#include <iostream>
52+
5053
using namespace std;
5154

5255
namespace RTT
5356
{
57+
struct ConnPolicy::ConnPolicyDefault {};
58+
ConnPolicy::ConnPolicy(const ConnPolicyDefault &)
59+
: type(DATA)
60+
, size(0)
61+
, lock_policy(LOCK_FREE)
62+
, init(false)
63+
, pull(false)
64+
, read_policy(ReadUnordered)
65+
, write_policy(WritePrivate)
66+
, max_threads(0)
67+
, mandatory(true)
68+
, transport(0)
69+
, data_size(0)
70+
{}
71+
72+
ConnPolicy &ConnPolicy::Default()
73+
{
74+
static ConnPolicy *s_default_policy = new ConnPolicy(ConnPolicyDefault());
75+
return *s_default_policy;
76+
}
77+
5478
ConnPolicy ConnPolicy::buffer(int size, int lock_policy /*= LOCK_FREE*/, bool init_connection /*= false*/, bool pull /*= false*/)
5579
{
56-
ConnPolicy result(BUFFER, lock_policy);
80+
ConnPolicy result;
81+
result.type = BUFFER;
82+
result.size = size;
83+
result.lock_policy = lock_policy;
5784
result.init = init_connection;
5885
result.pull = pull;
59-
result.size = size;
6086
return result;
6187
}
6288

6389
ConnPolicy ConnPolicy::circularBuffer(int size, int lock_policy /*= LOCK_FREE*/, bool init_connection /*= false*/, bool pull /*= false*/)
6490
{
65-
ConnPolicy result(CIRCULAR_BUFFER, lock_policy);
91+
ConnPolicy result;
92+
result.type = CIRCULAR_BUFFER;
93+
result.size = size;
94+
result.lock_policy = lock_policy;
6695
result.init = init_connection;
6796
result.pull = pull;
68-
result.size = size;
6997
return result;
7098
}
7199

72100
ConnPolicy ConnPolicy::data(int lock_policy /*= LOCK_FREE*/, bool init_connection /*= true*/, bool pull /*= false*/)
73101
{
74-
ConnPolicy result(DATA, lock_policy);
102+
ConnPolicy result;
103+
result.type = DATA;
104+
result.lock_policy = lock_policy;
75105
result.init = init_connection;
76106
result.pull = pull;
77107
return result;
78108
}
79109

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) {}
110+
ConnPolicy::ConnPolicy()
111+
: type(Default().type)
112+
, size(Default().size)
113+
, lock_policy(Default().lock_policy)
114+
, init(Default().init)
115+
, pull(Default().pull)
116+
, read_policy(Default().read_policy)
117+
, write_policy(Default().write_policy)
118+
, max_threads(Default().max_threads)
119+
, mandatory(Default().mandatory)
120+
, transport(Default().transport)
121+
, data_size(Default().data_size)
122+
{}
123+
124+
ConnPolicy::ConnPolicy(int type)
125+
: type(type)
126+
, size(Default().size)
127+
, lock_policy(Default().lock_policy)
128+
, init(Default().init)
129+
, pull(Default().pull)
130+
, read_policy(Default().read_policy)
131+
, write_policy(Default().write_policy)
132+
, max_threads(Default().max_threads)
133+
, mandatory(Default().mandatory)
134+
, transport(Default().transport)
135+
, data_size(Default().data_size)
136+
{}
82137

83-
/** @cond */
84-
/** This is dead code. We use the boost::serialization now.
85-
*/
86-
bool composeProperty(const PropertyBag& bag, ConnPolicy& result)
138+
ConnPolicy::ConnPolicy(int type, int lock_policy)
139+
: type(type)
140+
, size(Default().size)
141+
, lock_policy(lock_policy)
142+
, init(Default().init)
143+
, pull(Default().pull)
144+
, read_policy(Default().read_policy)
145+
, write_policy(Default().write_policy)
146+
, max_threads(Default().max_threads)
147+
, mandatory(Default().mandatory)
148+
, transport(Default().transport)
149+
, data_size(Default().data_size)
150+
{}
151+
152+
std::ostream &operator<<(std::ostream &os, const ConnPolicy &cp)
87153
{
88-
Property<int> i;
89-
Property<bool> b;
90-
Property<string> s;
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;
154+
std::string type;
155+
switch(cp.type) {
156+
case ConnPolicy::UNBUFFERED: type = "UNBUFFERED"; break;
157+
case ConnPolicy::DATA: type = "DATA"; break;
158+
case ConnPolicy::BUFFER: type = "BUFFER"; break;
159+
case ConnPolicy::CIRCULAR_BUFFER: type = "CIRCULAR_BUFFER"; break;
160+
default: type = "(unknown type)"; break;
114161
}
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;
162+
if (cp.size > 0) {
163+
type += "[" + boost::lexical_cast<std::string>(cp.size) + "]";
128164
}
129165

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;
166+
std::string lock_policy;
167+
switch(cp.lock_policy) {
168+
case ConnPolicy::UNSYNC: lock_policy = "UNSYNC"; break;
169+
case ConnPolicy::LOCKED: lock_policy = "LOCKED"; break;
170+
case ConnPolicy::LOCK_FREE: lock_policy = "LOCK_FREE"; break;
171+
default: lock_policy = "(unknown lock policy)"; break;
143172
}
144173

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;
174+
std::string pull;
175+
switch(cp.pull) {
176+
case ConnPolicy::PUSH: pull = "PUSH"; break;
177+
case ConnPolicy::PULL: pull = "PULL"; break;
151178
}
152-
return true;
153-
}
154179

155-
/** This is dead code. We use the boost::serialization now.
156-
* @internal
157-
*/
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-
}
172-
/** @endcond */
180+
os << pull << " ";
181+
os << cp.write_policy << " ";
182+
os << cp.read_policy << " ";
183+
os << lock_policy << " ";
184+
os << type;
185+
if (!cp.name_id.empty()) os << " (name_id=" << cp.name_id << ")";
186+
if (cp.max_threads > 0) os << " (max_threads=" << cp.max_threads << ")";
173187

188+
return os;
189+
}
174190
}

0 commit comments

Comments
 (0)