Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "ConnPolicy.hpp"
00047 #include "Property.hpp"
00048 #include "PropertyBag.hpp"
00049
00050 using namespace std;
00051
00052 namespace RTT
00053 {
00054 ConnPolicy ConnPolicy::buffer(int size, int lock_policy , bool init_connection , bool pull )
00055 {
00056 ConnPolicy result(BUFFER, lock_policy);
00057 result.init = init_connection;
00058 result.pull = pull;
00059 result.size = size;
00060 return result;
00061 }
00062
00063 ConnPolicy ConnPolicy::circularBuffer(int size, int lock_policy , bool init_connection , bool pull )
00064 {
00065 ConnPolicy result(CIRCULAR_BUFFER, lock_policy);
00066 result.init = init_connection;
00067 result.pull = pull;
00068 result.size = size;
00069 return result;
00070 }
00071
00072 ConnPolicy ConnPolicy::data(int lock_policy , bool init_connection , bool pull )
00073 {
00074 ConnPolicy result(DATA, lock_policy);
00075 result.init = init_connection;
00076 result.pull = pull;
00077 return result;
00078 }
00079
00080 ConnPolicy::ConnPolicy(int type , int lock_policy )
00081 : type(type), init(false), lock_policy(lock_policy), pull(false), size(0), transport(0), data_size(0) {}
00082
00086 bool composeProperty(const PropertyBag& bag, ConnPolicy& result)
00087 {
00088 Property<int> i;
00089 Property<bool> b;
00090 Property<string> s;
00091 if ( bag.getType() != "ConnPolicy")
00092 return false;
00093 log(Debug) <<"Composing ConnPolicy..." <<endlog();
00094 i = bag.getProperty("type");
00095 if ( i.ready() )
00096 result.type = i.get();
00097 else if ( bag.find("type") ){
00098 log(Error) <<"ConnPolicy: wrong property type of 'type'."<<endlog();
00099 return false;
00100 }
00101 i = bag.getProperty("lock_policy");
00102 if ( i.ready() )
00103 result.lock_policy = i.get();
00104 else if ( bag.find("lock_policy") ){
00105 log(Error) <<"ConnPolicy: wrong property type of 'lock_policy'."<<endlog();
00106 return false;
00107 }
00108 i = bag.getProperty("size");
00109 if ( i.ready() )
00110 result.size = i.get();
00111 else if ( bag.find("size") ){
00112 log(Error) <<"ConnPolicy: wrong property type of 'size'."<<endlog();
00113 return false;
00114 }
00115 i = bag.getProperty("data_size");
00116 if ( i.ready() )
00117 result.data_size = i.get();
00118 else if ( bag.find("data_size") ){
00119 log(Error) <<"ConnPolicy: wrong property type of 'data_size'."<<endlog();
00120 return false;
00121 }
00122 i = bag.getProperty("transport");
00123 if ( i.ready() )
00124 result.transport = i.get();
00125 else if ( bag.find("transport") ){
00126 log(Error) <<"ConnPolicy: wrong property type of 'transport'."<<endlog();
00127 return false;
00128 }
00129
00130 b = bag.getProperty("init");
00131 if ( b.ready() )
00132 result.init = b.get();
00133 else if ( bag.find("init") ){
00134 log(Error) <<"ConnPolicy: wrong property type of 'init'."<<endlog();
00135 return false;
00136 }
00137 b = bag.getProperty("pull");
00138 if ( b.ready() )
00139 result.pull = b.get();
00140 else if ( bag.find("pull") ){
00141 log(Error) <<"ConnPolicy: wrong property type of 'pull'."<<endlog();
00142 return false;
00143 }
00144
00145 s = bag.getProperty("name_id");
00146 if ( s.ready() )
00147 result.name_id = s.get();
00148 else if ( bag.find("name_id") ){
00149 log(Error) <<"ConnPolicy: wrong property type of 'name_id'."<<endlog();
00150 return false;
00151 }
00152 return true;
00153 }
00154
00158 void decomposeProperty(const ConnPolicy& cp, PropertyBag& targetbag)
00159 {
00160 log(Debug) <<"Decomposing ConnPolicy..." <<endlog();
00161 assert( targetbag.empty() );
00162 targetbag.setType("ConnPolicy");
00163 targetbag.ownProperty( new Property<int>("type","Data type", cp.type));
00164 targetbag.ownProperty( new Property<bool>("init","Initialize flag", cp.init));
00165 targetbag.ownProperty( new Property<int>("lock_policy","Locking Policy", cp.lock_policy));
00166 targetbag.ownProperty( new Property<bool>("pull","Fetch data over network", cp.pull));
00167 targetbag.ownProperty( new Property<int>("size","The size of a buffered connection", cp.size));
00168 targetbag.ownProperty( new Property<int>("transport","The prefered transport. Set to zero if unsure.", cp.transport));
00169 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));
00170 targetbag.ownProperty( new Property<string>("name_id","The name of the connection to be formed.",cp.name_id));
00171 }
00174 }