RemoteHandle.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18 * @package ArmarXCore
19 * @author Raphael Grimm ( raphael dot grimm at kit dot edu)
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 #pragma once
25 
26 #include <Ice/ProxyHandle.h>
27 
28 #include <ArmarXCore/interface/core/util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.h>
29 #include <ArmarXCore/interface/core/util/distributed/RemoteHandle/RemoteHandleControlBlock.h>
30 
31 #include "../../TemplateMetaProgramming.h"
32 
33 /**
34  * \defgroup Distributed
35  * \ingroup core-utility
36  */
37 namespace armarx
38 {
39  /**
40  * @brief The RemoteHandle class wrapps a ClientSideRemoteHandleControlBlock and can be used just as a Ice proxy.
41  * It can be copied, casted, assigned, compared and dereferenced.
42  * (for more info: \ref ArmarXCore-Tutorials-RemoteHandles "RemoteHandle tutorial")
43  * \ingroup Distributed
44  */
45  template <class PrxType>
47  {
48  static_assert(
50  "PrxType has to be an Ice proxy");
51 
52  public:
53  //constructing
54  RemoteHandle() = default;
55  RemoteHandle(const RemoteHandle& other) = default;
56  RemoteHandle(RemoteHandle&& other) = default;
57  RemoteHandle(const ClientSideRemoteHandleControlBlockBasePtr& controlBlock);
58  RemoteHandle(std::nullptr_t);
59  template <class PrxTypeB>
61  ~RemoteHandle() = default;
62 
63  //assigning
64  inline RemoteHandle<PrxType>& operator=(const RemoteHandle<PrxType>& other) = default;
65  inline RemoteHandle<PrxType>& operator=(RemoteHandle<PrxType>&& other) = default;
66  inline RemoteHandle<PrxType>&
67  operator=(const ClientSideRemoteHandleControlBlockBasePtr& controlBlock);
68  inline RemoteHandle<PrxType>& operator=(std::nullptr_t);
69  template <class PrxTypeB>
71 
72  //casting
73  template <class SourceType>
74  inline static RemoteHandle<PrxType> uncheckedCast(const SourceType& proxyToCast);
75 
76  template <class SourceType>
77  inline static RemoteHandle<PrxType> checkedCast(const SourceType& proxyToCast);
78 
79  template <class TargetPrxType>
81  template <class TargetPrxType>
83 
84  explicit inline operator bool() const;
85 
86  //access
87  inline PrxType operator*();
88  inline const PrxType operator*() const;
89  inline PrxType operator->();
90  inline const PrxType operator->() const;
91  inline PrxType get();
92  inline const PrxType get() const;
93 
94  //compare
95  template <class PrxTA, class PrxTB>
96  friend bool operator==(const RemoteHandle<PrxTA>& fst, const RemoteHandle<PrxTB>& snd);
97  template <class PrxTA, class PrxTB>
98  friend bool operator!=(const RemoteHandle<PrxTA>& fst, const RemoteHandle<PrxTB>& snd);
99  template <class PrxTA, class PrxTB>
100  friend bool operator<(const RemoteHandle<PrxTA>& fst, const RemoteHandle<PrxTB>& snd);
101  template <class PrxTA, class PrxTB>
102  friend bool operator<=(const RemoteHandle<PrxTA>& fst, const RemoteHandle<PrxTB>& snd);
103  template <class PrxTA, class PrxTB>
104  friend bool operator>(const RemoteHandle<PrxTA>& fst, const RemoteHandle<PrxTB>& snd);
105  template <class PrxTA, class PrxTB>
106  friend bool operator>=(const RemoteHandle<PrxTA>& fst, const RemoteHandle<PrxTB>& snd);
107 
108  /**
109  * @return Returns the internal ClientSideRemoteHandleControlBlock.
110  * This should only be used when it has to be send per ice.
111  */
114 
115  private:
116  template <class PrxTA>
117  friend class armarx::RemoteHandle;
118 
119  PrxType objectProxy;
120  ClientSideRemoteHandleControlBlockBasePtr clientSideControlBlock;
121  };
122 
123  template <class PrxType>
125  const ClientSideRemoteHandleControlBlockBasePtr& controlBlock) :
126  objectProxy{controlBlock ? PrxType::checkedCast(controlBlock->getManagedObjectProxy())
127  : nullptr},
128  clientSideControlBlock{objectProxy ? controlBlock : nullptr}
129  {
130  assert(objectProxy ? clientSideControlBlock : !clientSideControlBlock);
131  }
132 
133  template <class PrxType>
134  template <class PrxTypeB>
136  RemoteHandle(other.clientSideControlBlock)
137  {
138  }
139 
140  template <class PrxType>
142  RemoteHandle<PrxType>::operator=(const ClientSideRemoteHandleControlBlockBasePtr& controlBlock)
143  {
144  objectProxy =
145  controlBlock ? PrxType::checkedCast(controlBlock->getManagedObjectProxy()) : nullptr;
146  clientSideControlBlock = objectProxy ? controlBlock : nullptr;
147  return *this;
148  }
149 
150  template <class PrxType>
153  {
154  objectProxy = nullptr;
155  clientSideControlBlock = nullptr;
156  return *this;
157  }
158 
159  template <class PrxType>
160  template <class PrxTypeB>
163  {
164  this = other.clientSideControlBlock;
165  return this;
166  }
167 
168  template <class PrxType>
170  {
171  }
172 
173  template <class PrxType>
174  template <class SourceType>
175  RemoteHandle<PrxType>
176  RemoteHandle<PrxType>::uncheckedCast(const SourceType& proxyToCast)
177  {
178  static_assert(
180  "proxyToCast has to be a RemoteHandle");
181  return proxyToCast.template uncheckedCast<PrxType>();
182  }
183 
184  template <class PrxType>
185  template <class SourceType>
187  RemoteHandle<PrxType>::checkedCast(const SourceType& proxyToCast)
188  {
189  static_assert(
191  "proxyToCast has to be a RemoteHandle");
192  return proxyToCast.template checkedCast<PrxType>();
193  }
194 
195  template <class PrxType>
196  template <class TargetPrxType>
199  {
200  static_assert(
202  "TargetPrxType has to be an Ice proxy");
204  casted.clientSideControlBlock = clientSideControlBlock;
205  casted.objectProxy = TargetPrxType::uncheckedCast(objectProxy);
206  return casted;
207  }
208 
209  template <class PrxType>
210  template <class TargetPrxType>
213  {
214  static_assert(
216  "TargetPrxType has to be an Ice proxy");
218  casted.objectProxy = TargetPrxType::checkedCast(objectProxy);
219  casted.clientSideControlBlock = casted.objectProxy ? clientSideControlBlock : nullptr;
220  return casted;
221  }
222 
223  template <class PrxType>
224  PrxType
226  {
227  return objectProxy;
228  }
229 
230  template <class PrxType>
231  const PrxType
233  {
234  return objectProxy;
235  }
236 
237  template <class PrxType>
238  PrxType
240  {
241  return objectProxy;
242  }
243 
244  template <class PrxType>
245  const PrxType
247  {
248  return objectProxy;
249  }
250 
251  template <class PrxType>
252  PrxType
254  {
255  return objectProxy;
256  }
257 
258  template <class PrxType>
259  const PrxType
261  {
262  return objectProxy;
263  }
264 
265  template <class PrxType>
267  {
268  return objectProxy;
269  }
270 
271  template <class PrxType>
274  {
275  return clientSideControlBlock;
276  }
277 
278  template <class PrxTA, class PrxTB>
279  bool
281  {
282  return fst.clientSideControlBlock->getManagedObjectProxy() ==
283  snd.clientSideControlBlock->getManagedObjectProxy();
284  }
285 
286  template <class PrxTA, class PrxTB>
287  bool
289  {
290  return fst.clientSideControlBlock->getManagedObjectProxy() !=
291  snd.clientSideControlBlock->getManagedObjectProxy();
292  }
293 
294  template <class PrxTA, class PrxTB>
295  bool
297  {
298  return fst.clientSideControlBlock->getManagedObjectProxy() <
299  snd.clientSideControlBlock->getManagedObjectProxy();
300  }
301 
302  template <class PrxTA, class PrxTB>
303  bool
305  {
306  return fst.clientSideControlBlock->getManagedObjectProxy() <=
307  snd.clientSideControlBlock->getManagedObjectProxy();
308  }
309 
310  template <class PrxTA, class PrxTB>
311  bool
313  {
314  return fst.clientSideControlBlock->getManagedObjectProxy() >
315  snd.clientSideControlBlock->getManagedObjectProxy();
316  }
317 
318  template <class PrxTA, class PrxTB>
319  bool
321  {
322  return fst.clientSideControlBlock->getManagedObjectProxy() >=
323  snd.clientSideControlBlock->getManagedObjectProxy();
324  }
325 } // namespace armarx
armarx::operator!=
bool operator!=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:288
armarx::RemoteHandle::RemoteHandle
RemoteHandle()=default
armarx::RemoteHandle::operator*
PrxType operator*()
Definition: RemoteHandle.h:225
armarx::RemoteHandle::operator<
friend bool operator<(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:296
armarx::RemoteHandle::operator>=
friend bool operator>=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:320
armarx::RemoteHandle::get
PrxType get()
Definition: RemoteHandle.h:253
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::RemoteHandle::operator==
friend bool operator==(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:280
armarx::detail::operator*
StreamPrinter< Fnc > operator*(StreamPrinterTag, Fnc &&f)
Definition: LoggingUtil.h:48
armarx::RemoteHandle::operator>
friend bool operator>(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:312
armarx::operator>=
bool operator>=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:320
armarx::operator==
bool operator==(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:280
armarx::RemoteHandle::getclientSideControlBlock
const IceInternal::Handle< const ClientSideRemoteHandleControlBlockBase > getclientSideControlBlock() const
Definition: RemoteHandle.h:273
armarx::RemoteHandle::operator->
PrxType operator->()
Definition: RemoteHandle.h:239
armarx::RemoteHandle::uncheckedCast
RemoteHandle< TargetPrxType > uncheckedCast() const
Definition: RemoteHandle.h:198
armarx::RemoteHandle::operator!=
friend bool operator!=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:288
armarx::operator<
bool operator<(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:296
armarx::RemoteHandle::~RemoteHandle
~RemoteHandle()=default
armarx::RemoteHandle
The RemoteHandle class wrapps a ClientSideRemoteHandleControlBlock and can be used just as a Ice prox...
Definition: RemoteHandle.h:46
armarx::operator<=
bool operator<=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:304
armarx::RemoteHandle::operator<=
friend bool operator<=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:304
armarx::meta::TypeTemplateTraits::IsInstanceOf
Whether a type T is the instance of a given template Template.
Definition: TemplateMetaProgramming.h:75
armarx::RemoteHandle::operator=
RemoteHandle< PrxType > & operator=(const RemoteHandle< PrxType > &other)=default
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::RemoteHandle::checkedCast
RemoteHandle< TargetPrxType > checkedCast() const
Definition: RemoteHandle.h:212
armarx::operator>
bool operator>(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
Definition: RemoteHandle.h:312