ADTF  3.18.2
lockedobject_intf.h
Go to the documentation of this file.
1 
8 #ifndef _ADTF_UCOM_ANT_LOCKED_OBJECT_INTERFACE_INCLUDES_HEADER_
9 #define _ADTF_UCOM_ANT_LOCKED_OBJECT_INTERFACE_INCLUDES_HEADER_
10 
11 namespace adtf
12 {
13 namespace ucom
14 {
15 namespace ant
16 {
17 
23 class DOEXPORT ILockedObject : public IObject
24 {
25  public:
30  ADTF_IID(ILockedObject, "lockedobject.ant.ucom.adtf.iid");
31 
32  public:
40  virtual tResult Lock() const = 0;
47  virtual tResult Unlock() const = 0;
48 
49  protected:
51  ~ILockedObject() = default;
52 };
53 
59 class DOEXPORT ISharedLockedObject : public ILockedObject
60 {
61  public:
66  ADTF_IID(ISharedLockedObject, "sharedlockedobject.ant.ucom.adtf.iid");
67 
68  public:
76  virtual tResult LockShared() const = 0;
83  virtual tResult UnlockShared() const = 0;
84 
85  protected:
87  ~ISharedLockedObject() = default;
88 };
89 
90 
96 template <typename T>
98 {
99  public:
102  virtual T* Get() const = 0;
103 
107  virtual tResult Reset(const iobject_ptr<T>& i_oOther) = 0;
108 };
109 
115 template <typename T>
117 {
118  public:
121  virtual T* Get() const = 0;
125  virtual tResult Reset(const iobject_ptr<T>& i_oOther) = 0;
126 };
127 
128 namespace detail
129 {
132 template <typename T>
134 {
135  protected:
136  object_ptr<T> m_pObjectPtr;
137 
138  object_ptr_locked_common() = default;
140  {
141  m_pObjectPtr.Swap(o_oOther.m_pObjectPtr);
142  }
143 
144  public:
146  T* operator->() const
147  {
148  return m_pObjectPtr.Get();
149  }
150 
151  T& operator*() const
152  {
153  return *m_pObjectPtr.Get();
154  }
155 
156  explicit operator bool() const
157  {
158  return static_cast<bool>(m_pObjectPtr);
159  }
160 
161  protected:
162  virtual void UnlockObject() = 0;
163 
164  tResult Reset(const iobject_ptr<T>& i_oOther)
165  {
166  Release();
167  return m_pObjectPtr.Reset(i_oOther);
168  }
169 
170  void Release()
171  {
172  if (m_pObjectPtr)
173  {
174  UnlockObject();
175  m_pObjectPtr = nullptr;
176  }
177  }
178 
179  void Swap(object_ptr_locked_common& i_oOther)
180  {
181  m_pObjectPtr.Swap(i_oOther.m_pObjectPtr);
182  }
183 
184  T* GetPtr() const
185  {
186  return m_pObjectPtr.Get();
187  }
188 
189  private:
190  object_ptr_locked_common(const object_ptr_locked_common&) = delete;
191  object_ptr_locked_common& operator=(const object_ptr_locked_common&) = delete;
192 
193 };
194 
195 }
196 
203 template <typename T>
205  public iobject_ptr_locked<T>,
207 {
208  private:
210 
211  public:
213  object_ptr_locked() = default;
214 
217  object_ptr_locked(object_ptr_locked&& o_oOther) = default;
218 
221  {
222  base_type::Release();
223  }
224 
228  {
229  base_type::Swap(o_oOther);
230  return *this;
231  }
232 
234  object_ptr_locked& operator=(std::nullptr_t)
235  {
236  base_type::Release();
237  return *this;
238  }
239 
240  virtual T* Get() const
241  {
242  return base_type::GetPtr();;
243  }
244 
245  virtual tResult Reset(const iobject_ptr<T>& i_oOther)
246  {
247  return base_type::Reset(i_oOther);
248  }
249 
250  protected:
252  void UnlockObject() override
253  {
254  const ILockedObject* pLockedObject = ucom_cast<const ILockedObject*>(base_type::GetPtr());
255  if (pLockedObject)
256  {
257  pLockedObject->Unlock();
258  }
259  }
260 
261 };
262 
269 template <typename T>
271  public iobject_ptr_shared_locked<T>,
273 {
274  private:
276 
277  public:
280 
284 
287  {
288  base_type::Release();
289  }
290 
294  {
295  base_type::Swap(o_oOther);
296  return *this;
297  }
298 
301  {
302  base_type::Release();
303  return *this;
304  }
305 
306  virtual T* Get() const
307  {
308  return base_type::GetPtr();;
309  }
310 
311  virtual tResult Reset(const iobject_ptr<T>& i_oOther)
312  {
313  return base_type::Reset(i_oOther);
314  }
315 
316  protected:
318  void UnlockObject() override
319  {
320  const ISharedLockedObject* pLockedObject = ucom_cast<const ISharedLockedObject*>(base_type::GetPtr());
321  if (pLockedObject)
322  {
323  pLockedObject->UnlockShared();
324  }
325  }
326 
327 };
328 
329 }//namespace ant
330 
332 using ant::ILockedObject;
333 using ant::ISharedLockedObject;
334 
335 using ant::iobject_ptr_locked;
336 using ant::object_ptr_locked;
337 using ant::iobject_ptr_shared_locked;
338 using ant::object_ptr_shared_locked;
339 
340 }//namespace ucom
341 }//namespace adtf
342 
343 //*************************************************************************************************
344 #endif //_ADTF_UCOM_ANT_LOCKED_OBJECT_INTERFACE_INCLUDES_HEADER_
The ILockedObject interface defines exclusive locking of an object.
ADTF_IID(ILockedObject, "lockedobject.ant.ucom.adtf.iid")
Marks the ILockedObject to be castable with the ucom_cast<>
virtual tResult Lock() const =0
Locks the object for exclusive use.
virtual tResult Unlock() const =0
Unlocks the object for exclusive use.
~ILockedObject()=default
Protected destructor --> Use implemented Destroy() instead of delete!
Base class for every interface type within the uCOM.
Definition: object_intf.h:31
The ISharedLockedObject interface defines shared locking of an object.
ADTF_IID(ISharedLockedObject, "sharedlockedobject.ant.ucom.adtf.iid")
Marks the ISharedLockedObject to be castable with the ucom_cast<>
virtual tResult UnlockShared() const =0
Unlocks the object for shared use.
~ISharedLockedObject()=default
Protected destructor --> Use implemented Destroy() instead of delete!
virtual tResult LockShared() const =0
Locks the object for shared use.
basic template for locked object tparam T value type
Interfaces for a guarded exclusive lock.
virtual tResult Reset(const iobject_ptr< T > &i_oOther)=0
Sets the value as pointer.
virtual T * Get() const =0
returns the value as pointer
Interfaces for a guarded shared lock.
virtual tResult Reset(const iobject_ptr< T > &i_oOther)=0
Sets the value as pointer.
virtual T * Get() const =0
returns the value as pointer
Base object pointer to realize binary compatible reference counting in interface methods.
Implementation for a exclusive lock guard.
virtual tResult Reset(const iobject_ptr< T > &i_oOther)
Sets the value as pointer.
object_ptr_locked & operator=(std::nullptr_t)
null assignment-operator to Reset the value
void UnlockObject() override
unlock the object
object_ptr_locked & operator=(object_ptr_locked &&o_oOther)
move-assignment-operator
virtual T * Get() const
returns the value as pointer
object_ptr_locked(object_ptr_locked &&o_oOther)=default
move-CTOR
Implementation for a shared lock guard.
virtual tResult Reset(const iobject_ptr< T > &i_oOther)
Sets the value as pointer.
object_ptr_shared_locked(object_ptr_shared_locked &&o_oOther)=default
move-CTOR
void UnlockObject() override
unlocks the object
virtual T * Get() const
returns the value as pointer
object_ptr_shared_locked & operator=(std::nullptr_t)
null assignment-operator to Reset the value
object_ptr_shared_locked & operator=(object_ptr_shared_locked &&o_oOther)
move-assignment-operator
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
void Reset()
Reset this object_ptr.
Definition: object_ptr.h:361
virtual T * Get() const
Get pointer to shared object.
Definition: object_ptr.h:381
void Swap(object_ptr &o_oOther)
Swap content of *this with o_oOther (only shallow copies are performed!)
Definition: object_ptr.h:371
Namespace for entire ADTF SDK.