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 #include <boost/lexical_cast.hpp>
51 #include <iostream>
52 
53 using namespace std;
54 
55 namespace RTT
56 {
59  : type(DATA)
60  , size(0)
61  , lock_policy(LOCK_FREE)
62  , init(false)
63  , pull(false)
64  , buffer_policy(PerConnection)
65  , max_threads(0)
66  , mandatory(true)
67  , transport(0)
68  , data_size(0)
69  {}
70 
72  {
73  static ConnPolicy *s_default_policy = new ConnPolicy(ConnPolicyDefault());
74  return *s_default_policy;
75  }
76 
77  ConnPolicy ConnPolicy::buffer(int size, int lock_policy /*= LOCK_FREE*/, bool init_connection /*= false*/, bool pull /*= false*/)
78  {
79  ConnPolicy result;
80  result.type = BUFFER;
81  result.size = size;
82  result.lock_policy = lock_policy;
83  result.init = init_connection;
84  result.pull = pull;
85  return result;
86  }
87 
88  ConnPolicy ConnPolicy::circularBuffer(int size, int lock_policy /*= LOCK_FREE*/, bool init_connection /*= false*/, bool pull /*= false*/)
89  {
90  ConnPolicy result;
91  result.type = CIRCULAR_BUFFER;
92  result.size = size;
93  result.lock_policy = lock_policy;
94  result.init = init_connection;
95  result.pull = pull;
96  return result;
97  }
98 
99  ConnPolicy ConnPolicy::data(int lock_policy /*= LOCK_FREE*/, bool init_connection /*= true*/, bool pull /*= false*/)
100  {
101  ConnPolicy result;
102  result.type = DATA;
103  result.lock_policy = lock_policy;
104  result.init = init_connection;
105  result.pull = pull;
106  return result;
107  }
108 
110  : type(Default().type)
111  , size(Default().size)
113  , init(Default().init)
114  , pull(Default().pull)
120  {}
121 
123  : type(type)
124  , size(Default().size)
126  , init(Default().init)
127  , pull(Default().pull)
133  {}
134 
136  : type(type)
137  , size(Default().size)
138  , lock_policy(lock_policy)
139  , init(Default().init)
140  , pull(Default().pull)
146  {}
147 
148  std::ostream &operator<<(std::ostream &os, const ConnPolicy &cp)
149  {
150  std::string type;
151  switch(cp.type) {
152  case ConnPolicy::UNBUFFERED: type = "UNBUFFERED"; break;
153  case ConnPolicy::DATA: type = "DATA"; break;
154  case ConnPolicy::BUFFER: type = "BUFFER"; break;
155  case ConnPolicy::CIRCULAR_BUFFER: type = "CIRCULAR_BUFFER"; break;
156  default: type = "(unknown type)"; break;
157  }
158  if (cp.size > 0) {
159  type += "[" + boost::lexical_cast<std::string>(cp.size) + "]";
160  }
161 
162  std::string lock_policy;
163  switch(cp.lock_policy) {
164  case ConnPolicy::UNSYNC: lock_policy = "UNSYNC"; break;
165  case ConnPolicy::LOCKED: lock_policy = "LOCKED"; break;
166  case ConnPolicy::LOCK_FREE: lock_policy = "LOCK_FREE"; break;
167  default: lock_policy = "(unknown lock policy)"; break;
168  }
169 
170  std::string pull;
171  // note: cast to int to suppress clang "warning: switch condition has boolean value"
172  switch(int(cp.pull)) {
173  case int(ConnPolicy::PUSH): pull = "PUSH"; break;
174  case int(ConnPolicy::PULL): pull = "PULL"; break;
175  }
176 
177  os << pull << " ";
178  os << BufferPolicy(cp.buffer_policy) << " ";
179  os << lock_policy << " ";
180  os << type;
181  if (!cp.name_id.empty()) os << " (name_id=" << cp.name_id << ")";
182  if (cp.max_threads > 0) os << " (max_threads=" << cp.max_threads << ")";
183 
184  return os;
185  }
186 }
static ConnPolicy data(int lock_policy=LOCK_FREE, bool init_connection=true, bool pull=false)
Definition: ConnPolicy.cpp:99
static const int CIRCULAR_BUFFER
Definition: ConnPolicy.hpp:113
static const bool PULL
Definition: ConnPolicy.hpp:120
Definition: mystd.hpp:163
static const int LOCKED
Definition: ConnPolicy.hpp:116
static const bool PUSH
Definition: ConnPolicy.hpp:119
static const int DATA
Definition: ConnPolicy.hpp:111
static ConnPolicy circularBuffer(int size, int lock_policy=LOCK_FREE, bool init_connection=false, bool pull=false)
Definition: ConnPolicy.cpp:88
static ConnPolicy buffer(int size, int lock_policy=LOCK_FREE, bool init_connection=false, bool pull=false)
Definition: ConnPolicy.cpp:77
static const int LOCK_FREE
Definition: ConnPolicy.hpp:117
std::ostream & operator<<(std::ostream &os, const BufferPolicy &bp)
BufferPolicy
static ConnPolicy & Default()
Definition: ConnPolicy.cpp:71
static const int UNSYNC
Definition: ConnPolicy.hpp:115
static const int BUFFER
Definition: ConnPolicy.hpp:112
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
std::string name_id
Definition: ConnPolicy.hpp:256
static const int UNBUFFERED
Definition: ConnPolicy.hpp:110


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:32