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::data(int lock_policy , bool init_connection , bool pull )
00064 {
00065 ConnPolicy result(DATA, lock_policy);
00066 result.init = init_connection;
00067 result.pull = pull;
00068 return result;
00069 }
00070
00071 ConnPolicy::ConnPolicy(int type , int lock_policy )
00072 : type(type), init(false), lock_policy(lock_policy), pull(false), size(0), transport(0), data_size(0) {}
00073
00077 bool composeProperty(const PropertyBag& bag, ConnPolicy& result)
00078 {
00079 Property<int> i;
00080 Property<bool> b;
00081 Property<string> s;
00082 if ( bag.getType() != "ConnPolicy")
00083 return false;
00084 log(Debug) <<"Composing ConnPolicy..." <<endlog();
00085 i = bag.getProperty("type");
00086 if ( i.ready() )
00087 result.type = i.get();
00088 else if ( bag.find("type") ){
00089 log(Error) <<"ConnPolicy: wrong property type of 'type'."<<endlog();
00090 return false;
00091 }
00092 i = bag.getProperty("lock_policy");
00093 if ( i.ready() )
00094 result.lock_policy = i.get();
00095 else if ( bag.find("lock_policy") ){
00096 log(Error) <<"ConnPolicy: wrong property type of 'lock_policy'."<<endlog();
00097 return false;
00098 }
00099 i = bag.getProperty("size");
00100 if ( i.ready() )
00101 result.size = i.get();
00102 else if ( bag.find("size") ){
00103 log(Error) <<"ConnPolicy: wrong property type of 'size'."<<endlog();
00104 return false;
00105 }
00106 i = bag.getProperty("data_size");
00107 if ( i.ready() )
00108 result.data_size = i.get();
00109 else if ( bag.find("data_size") ){
00110 log(Error) <<"ConnPolicy: wrong property type of 'data_size'."<<endlog();
00111 return false;
00112 }
00113 i = bag.getProperty("transport");
00114 if ( i.ready() )
00115 result.transport = i.get();
00116 else if ( bag.find("transport") ){
00117 log(Error) <<"ConnPolicy: wrong property type of 'transport'."<<endlog();
00118 return false;
00119 }
00120
00121 b = bag.getProperty("init");
00122 if ( b.ready() )
00123 result.init = b.get();
00124 else if ( bag.find("init") ){
00125 log(Error) <<"ConnPolicy: wrong property type of 'init'."<<endlog();
00126 return false;
00127 }
00128 b = bag.getProperty("pull");
00129 if ( b.ready() )
00130 result.pull = b.get();
00131 else if ( bag.find("pull") ){
00132 log(Error) <<"ConnPolicy: wrong property type of 'pull'."<<endlog();
00133 return false;
00134 }
00135
00136 s = bag.getProperty("name_id");
00137 if ( s.ready() )
00138 result.name_id = s.get();
00139 else if ( bag.find("name_id") ){
00140 log(Error) <<"ConnPolicy: wrong property type of 'name_id'."<<endlog();
00141 return false;
00142 }
00143 return true;
00144 }
00145
00149 void decomposeProperty(const ConnPolicy& cp, PropertyBag& targetbag)
00150 {
00151 log(Debug) <<"Decomposing ConnPolicy..." <<endlog();
00152 assert( targetbag.empty() );
00153 targetbag.setType("ConnPolicy");
00154 targetbag.ownProperty( new Property<int>("type","Data type", cp.type));
00155 targetbag.ownProperty( new Property<bool>("init","Initialize flag", cp.init));
00156 targetbag.ownProperty( new Property<int>("lock_policy","Locking Policy", cp.lock_policy));
00157 targetbag.ownProperty( new Property<bool>("pull","Fetch data over network", cp.pull));
00158 targetbag.ownProperty( new Property<int>("size","The size of a buffered connection", cp.size));
00159 targetbag.ownProperty( new Property<int>("transport","The prefered transport. Set to zero if unsure.", cp.transport));
00160 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));
00161 targetbag.ownProperty( new Property<string>("name_id","The name of the connection to be formed.",cp.name_id));
00162 }
00165 }