Port_impl.h
Go to the documentation of this file.
1 /*
2  * This file is protected by Copyright. Please refer to the COPYRIGHT file
3  * distributed with this source distribution.
4  *
5  * This file is part of REDHAWK core.
6  *
7  * REDHAWK core is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * REDHAWK core is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program. If not, see http://www.gnu.org/licenses/.
19  */
20 
21 
22 #ifndef PORT_IMPL_H
23 #define PORT_IMPL_H
24 
25 #include <iostream>
26 #include <iterator>
27 #include <string>
28 #include <vector>
29 
30 #include <boost/thread/mutex.hpp>
31 
32 #include "CF/cf.h"
33 #include "ossie/Autocomplete.h"
34 
35 namespace _seqVector {
36 
37 template<typename _Tp>
39  public:
40  typedef size_t size_type;
41  typedef ptrdiff_t difference_type;
42  typedef _Tp* pointer;
43  typedef const _Tp* const_pointer;
44  typedef _Tp& reference;
45  typedef const _Tp& const_reference;
46  typedef _Tp value_type;
47 
48  template<typename _Tp1>
49  struct rebind {
51  };
52 
53  seqVectorAllocator() throw() {
54  }
55 
57  }
58 
59  template<typename _Tp1>
61  }
62 
63  ~seqVectorAllocator() throw() {
64  }
65 
66  pointer address(reference __x) const {
67  return &__x;
68  }
69 
70  const_pointer address(const_reference __x) const {
71  return &__x;
72  }
73 
74  // NB: __n is permitted to be 0. The C++ standard says nothing
75  // about what the return value is when __n == 0.
76  pointer allocate(size_type __n, const void* = 0) {
77  if (__builtin_expect(__n > this->max_size(), false))
78  std::__throw_bad_alloc();
79  return (_Tp*) new _Tp[__n];
80  }
81 
82  // __p is not permitted to be a null pointer.
83  void deallocate(pointer __p, size_type) {
84  ::operator delete[](__p);
85  }
86 
87  size_type max_size() const throw() {
88  return size_t(-1) / sizeof(_Tp);
89  }
90 
91  // _GLIBCXX_RESOLVE_LIB_DEFECTS
92  // 402. wrong new expression in [some_] allocator::construct
93  void construct(pointer __p, const _Tp& __val) {
94  ::new (__p) _Tp(__val);
95  }
96 
97  void destroy(pointer __p) {
98  __p->~_Tp();
99  }
100  };
101 
102  template<typename _Tp>
104  const seqVectorAllocator<_Tp>&) {
105  return true;
106  }
107 
108  template<typename _Tp>
110  const seqVectorAllocator<_Tp>&) {
111  return false;
112  }
113 } // namespace _seqVector
114 
115 
117 #ifdef BEGIN_AUTOCOMPLETE_IGNORE
118 : public virtual POA_CF::Port
119 #endif
120 {
121 public:
122  Port_impl();
123  ~Port_impl();
124  void connectPort(CORBA::Object_ptr connection, const char* connectionId);
125  void disconnectPort(const char* connectionId);
126 };
127 
128 template <class PortType, class ComponentType>
130 {
131 public:
132  Port_Uses_impl(ComponentType* _parent, std::string port_name);
133  ~Port_Uses_impl();
134  void connectPort(CORBA::Object_ptr connection, const char* connectionId);
135  void disconnectPort(const char* connectionId);
136  void setActiveStatus(bool active_flag);
137  void releasePort();
138  std::vector< std::pair<class PortType::_var_type, std::string> > get_ports();
139  // Return whether this Port is connected to another Port
140  bool isActive();
141  // Return the Port name
142  std::string getName();
143 
144 protected:
145  // Pointer to the Component or Device that owns this Port
146  ComponentType* parent;
147  // Vector of all outgoing connections
148  std::vector < std::pair<class PortType::_var_type, std::string> > outPorts;
149  bool active;
150  std::string name;
151  boost::mutex updatingPortsLock;
153 };
154 
155 template <class PortType, class ComponentType>
156 Port_Uses_impl<PortType, ComponentType>::Port_Uses_impl(ComponentType* _parent, std::string port_name)
157 {
158  parent = _parent;
159  active = false;
160  name = port_name;
161 };
162 
163 template <class PortType, class ComponentType>
165 {
166 };
167 
168 template <class PortType, class ComponentType>
169 void Port_Uses_impl<PortType, ComponentType>::connectPort(CORBA::Object_ptr connection, const char* connectionId)
170 {
171  boost::mutex::scoped_lock lock(updatingPortsLock); // don't want to process while command information is coming in
172  class PortType::_var_type port = PortType::_narrow(connection);
173  outPorts.push_back(std::make_pair(port, connectionId));
174  active = true;
175  refreshSRI = true;
176 };
177 
178 template <class PortType, class ComponentType>
180 {
181  boost::mutex::scoped_lock lock(updatingPortsLock); // don't want to process while command information is coming in
182  for (unsigned int i = 0; i < outPorts.size(); i++) {
183  if (outPorts[i].second == connectionId) {
184  outPorts.erase(outPorts.begin() + i);
185  break;
186  }
187  }
188 
189  if (outPorts.size() == 0) {
190  active = false;
191  }
192 };
193 
194 template <class PortType, class ComponentType>
196 {
197  return active;
198 };
199 
200 template <class PortType, class ComponentType>
202 {
203  active = active_flag;
204 };
205 
206 template <class PortType, class ComponentType>
208 {
209 };
210 
211 template <class PortType, class ComponentType>
212 std::vector< std::pair<class PortType::_var_type, std::string> > Port_Uses_impl<PortType, ComponentType>::get_ports()
213 {
214  return outPorts;
215 };
216 
217 template <class PortType, class ComponentType>
219 {
220  return name;
221 };
222 
223 
224 
225 
226 template <class PortType, class ComponentType>
228 {
229 public:
230  Port_Provides_impl(ComponentType* _parent, std::string port_name);
232  // Return this Port's name
233  std::string getName();
234 
235 protected:
236  ComponentType* parent;
237  std::string name;
238 };
239 
240 template <class PortType, class ComponentType>
241 Port_Provides_impl<PortType, ComponentType>::Port_Provides_impl(ComponentType* _parent, std::string port_name)
242 {
243  parent = _parent;
244  name = port_name;
245 };
246 
247 template <class PortType, class ComponentType>
249 {
250 };
251 
252 template <class PortType, class ComponentType>
254 {
255  return name;
256 };
257 
258 
259 class PortBase
260 #ifdef BEGIN_AUTOCOMPLETE_IGNORE
261 : public virtual PortableServer::ServantBase
262 #endif
263 {
264 public:
265  PortBase (const std::string& name) :
266  name(name), description("")
267  {
268  }
269 
270  virtual ~PortBase ()
271  {
272  }
273 
274  virtual void setDescription(const std::string& desc)
275  {
276  description = desc;
277  }
278 
279  virtual void startPort ()
280  {
281  }
282 
283  virtual void stopPort ()
284  {
285  }
286 
287  virtual void releasePort()
288  {
289  }
290 
291  // Return the Port name
292  virtual std::string getName ()
293  {
294  return name;
295  }
296 
297  // Return the Port description
298  virtual std::string getDescription ()
299  {
300  return description;
301  }
302 
303  // Return the interface that this Port supports
304  virtual std::string getRepid () const
305  {
306  return "IDL:CORBA/Object:1.0";
307  }
308 
309  // Return the direction (uses/provides) for this Port
310  virtual std::string getDirection() const
311  {
312  return "Direction";
313  }
314 
315 protected:
316  std::string name;
317  std::string description;
318 };
319 
321 {
322 public:
323  Port_Uses_base_impl(std::string port_name) :
324  PortBase(port_name)
325  {
326  active = false;
327  }
328 
330  {
331  }
332 
333  virtual void connectPort(CORBA::Object_ptr connection, const char* connectionId)
334  {
335  }
336 
337  virtual void disconnectPort(const char* connectionId)
338  {
339  }
340 
341  virtual void setActiveStatus(bool active_flag)
342  {
343  active = active_flag;
344  }
345 
346  // Return true if this Port is connected to another Port
347  virtual bool isActive()
348  {
349  return active;
350  }
351 
352  // Return the direction (uses/provides) for this Port
353  virtual std::string getDirection () const
354  {
355  return "Uses";
356  }
357 
358 protected:
359  bool active;
360  boost::mutex updatingPortsLock;
362 };
363 
365 {
366 public:
367  Port_Provides_base_impl(std::string port_name) :
368  PortBase(port_name)
369  {
370  }
371 
373  {
374  }
375 
376  // Return the direction (uses/provides) for this Port
377  virtual std::string getDirection () const
378  {
379  return "Provides";
380  }
381 };
382 
383 
384 #endif /* */
virtual std::string getName()
Definition: Port_impl.h:292
std::string name
Definition: Port_impl.h:316
virtual ~Port_Uses_base_impl()
Definition: Port_impl.h:329
Definition: Port_impl.h:35
size_t size_type
Definition: Port_impl.h:40
virtual void startPort()
Definition: Port_impl.h:279
std::vector< std::pair< class PortType::_var_type, std::string > > outPorts
Definition: Port_impl.h:148
~Port_Uses_impl()
Definition: Port_impl.h:164
void releasePort()
Definition: Port_impl.h:207
boost::mutex updatingPortsLock
Definition: Port_impl.h:360
Port_Provides_impl(ComponentType *_parent, std::string port_name)
Definition: Port_impl.h:241
size_type max_size() const
Definition: Port_impl.h:87
void deallocate(pointer __p, size_type)
Definition: Port_impl.h:83
_Tp * pointer
Definition: Port_impl.h:42
std::string name
Definition: Port_impl.h:237
virtual ~Port_Provides_base_impl()
Definition: Port_impl.h:372
std::string description
Definition: Port_impl.h:317
virtual bool isActive()
Definition: Port_impl.h:347
bool refreshSRI
Definition: Port_impl.h:152
void construct(pointer __p, const _Tp &__val)
Definition: Port_impl.h:93
_Tp value_type
Definition: Port_impl.h:46
Port_Uses_base_impl(std::string port_name)
Definition: Port_impl.h:323
pointer allocate(size_type __n, const void *=0)
Definition: Port_impl.h:76
Definition: Port_impl.h:364
~Port_Provides_impl()
Definition: Port_impl.h:248
void disconnectPort(const char *connectionId)
virtual void setActiveStatus(bool active_flag)
Definition: Port_impl.h:341
virtual void setDescription(const std::string &desc)
Definition: Port_impl.h:274
PortBase(const std::string &name)
Definition: Port_impl.h:265
boost::mutex updatingPortsLock
Definition: Port_impl.h:151
Definition: Port_impl.h:116
std::vector< std::pair< class PortType::_var_type, std::string > > get_ports()
Definition: Port_impl.h:212
_Tp & reference
Definition: Port_impl.h:44
bool refreshSRI
Definition: Port_impl.h:361
virtual void disconnectPort(const char *connectionId)
Definition: Port_impl.h:337
std::string getName()
Definition: Port_impl.h:218
Definition: Port_impl.h:129
const_pointer address(const_reference __x) const
Definition: Port_impl.h:70
ptrdiff_t difference_type
Definition: Port_impl.h:41
virtual void connectPort(CORBA::Object_ptr connection, const char *connectionId)
Definition: Port_impl.h:333
Definition: Port_impl.h:227
virtual std::string getRepid() const
Definition: Port_impl.h:304
void disconnectPort(const char *connectionId)
Definition: Port_impl.h:179
virtual std::string getDirection() const
Definition: Port_impl.h:353
bool operator==(const seqVectorAllocator< _Tp > &, const seqVectorAllocator< _Tp > &)
Definition: Port_impl.h:103
pointer address(reference __x) const
Definition: Port_impl.h:66
virtual std::string getDirection() const
Definition: Port_impl.h:377
void connectPort(CORBA::Object_ptr connection, const char *connectionId)
Definition: Port_impl.h:169
Port_Uses_impl(ComponentType *_parent, std::string port_name)
Definition: Port_impl.h:156
bool isActive()
Definition: Port_impl.h:195
Definition: Port_impl.h:49
const _Tp * const_pointer
Definition: Port_impl.h:43
virtual void releasePort()
Definition: Port_impl.h:287
void connectPort(CORBA::Object_ptr connection, const char *connectionId)
ComponentType * parent
Definition: Port_impl.h:146
seqVectorAllocator(const seqVectorAllocator< _Tp1 > &)
Definition: Port_impl.h:60
const _Tp & const_reference
Definition: Port_impl.h:45
bool active
Definition: Port_impl.h:149
bool active
Definition: Port_impl.h:359
std::string name
Definition: Port_impl.h:150
std::string getName()
Definition: Port_impl.h:253
bool operator!=(const seqVectorAllocator< _Tp > &, const seqVectorAllocator< _Tp > &)
Definition: Port_impl.h:109
Port_Provides_base_impl(std::string port_name)
Definition: Port_impl.h:367
virtual std::string getDirection() const
Definition: Port_impl.h:310
void setActiveStatus(bool active_flag)
Definition: Port_impl.h:201
Definition: Port_impl.h:38
~seqVectorAllocator()
Definition: Port_impl.h:63
seqVectorAllocator(const seqVectorAllocator &)
Definition: Port_impl.h:56
ComponentType * parent
Definition: Port_impl.h:236
seqVectorAllocator()
Definition: Port_impl.h:53
virtual void stopPort()
Definition: Port_impl.h:283
void destroy(pointer __p)
Definition: Port_impl.h:97
Definition: Port_impl.h:259
virtual ~PortBase()
Definition: Port_impl.h:270
seqVectorAllocator< _Tp1 > other
Definition: Port_impl.h:50
Definition: Port_impl.h:320
virtual std::string getDescription()
Definition: Port_impl.h:298