ConnPolicy.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Oct 22 11:59:08 CEST 2009  ConnPolicy.cpp
00003 
00004                         ConnPolicy.cpp -  description
00005                            -------------------
00006     begin                : Thu October 22 2009
00007     copyright            : (C) 2009 Peter Soetens
00008     email                : peter@thesourcworks.com
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 /*
00040  * ConnPolicy.cpp
00041  *
00042  *  Created on: Oct 20, 2009
00043  *      Author: kaltan
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 /*= LOCK_FREE*/, bool init_connection /*= false*/, bool pull /*= false*/)
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 /*= LOCK_FREE*/, bool init_connection /*= false*/, bool pull /*= false*/)
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 /*= LOCK_FREE*/, bool init_connection /*= true*/, bool pull /*= false*/)
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 /* = DATA*/, int lock_policy /*= LOCK_FREE*/)
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 }


rtt
Author(s): RTT Developers
autogenerated on Mon Oct 6 2014 03:13:34