ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lockedobject_intf.h
Go to the documentation of this file.
1
7
8#ifndef _ADTF_UCOM_ANT_LOCKED_OBJECT_INTERFACE_INCLUDES_HEADER_
9#define _ADTF_UCOM_ANT_LOCKED_OBJECT_INTERFACE_INCLUDES_HEADER_
10
11namespace adtf
12{
13namespace ucom
14{
15namespace ant
16{
17
23class 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
59class 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:
88};
89
90
96template <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
115template <typename T>
117{
118 public:
121 virtual T* Get() const = 0;
125 virtual tResult Reset(const iobject_ptr<T>& i_oOther) = 0;
126};
127
128namespace detail
129{
132template <typename T>
133class object_ptr_locked_common
134{
135 protected:
136 object_ptr<T> m_pObjectPtr;
137
138 object_ptr_locked_common() = default;
139 object_ptr_locked_common(object_ptr_locked_common&& o_oOther)
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
203template <typename T>
205 public iobject_ptr_locked<T>,
207{
208 private:
209 typedef detail::object_ptr_locked_common<T> base_type;
210
211 public:
213 object_ptr_locked() = default;
214
218
221 {
222 base_type::Release();
223 }
224
228 {
229 base_type::Swap(o_oOther);
230 return *this;
231 }
232
235 {
236 base_type::Release();
237 return *this;
238 }
239
240 virtual T* Get() const override
241 {
242 return base_type::GetPtr();;
243 }
244
245 virtual tResult Reset(const iobject_ptr<T>& i_oOther) override
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
269template <typename T>
273{
274 private:
275 typedef detail::object_ptr_locked_common<T> base_type;
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 override
307 {
308 return base_type::GetPtr();;
309 }
310
311 virtual tResult Reset(const iobject_ptr<T>& i_oOther) override
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
332using ant::ILockedObject;
333using ant::ISharedLockedObject;
334
335using ant::iobject_ptr_locked;
336using ant::object_ptr_locked;
337using ant::iobject_ptr_shared_locked;
338using ant::object_ptr_shared_locked;
339
340}//namespace ucom
341}//namespace adtf
342
343//*************************************************************************************************
344#endif //_ADTF_UCOM_ANT_LOCKED_OBJECT_INTERFACE_INCLUDES_HEADER_
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
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 --> Only the final implementation can be destroyed!
Base class for every interface type within the uCOM.
Definition object_intf.h:33
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 --> Only the final implementation can be destroyed!
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 T * Get() const =0
returns the value as pointer
virtual tResult Reset(const iobject_ptr< T > &i_oOther)=0
Sets the value as pointer.
Interfaces for a guarded shared lock.
virtual T * Get() const =0
returns the value as pointer
virtual tResult Reset(const iobject_ptr< T > &i_oOther)=0
Sets the value as pointer.
Base object pointer to realize binary compatible reference counting in interface methods.
virtual T * Get() const override
returns the value as pointer
void UnlockObject() override
unlock the object
virtual tResult Reset(const iobject_ptr< T > &i_oOther) override
Sets the value as pointer.
object_ptr_locked & operator=(object_ptr_locked &&o_oOther)
move-assignment-operator
object_ptr_locked(object_ptr_locked &&o_oOther)=default
move-CTOR
object_ptr_locked & operator=(std::nullptr_t)
null assignment-operator to Reset the value
object_ptr_shared_locked & operator=(std::nullptr_t)
null assignment-operator to Reset the value
object_ptr_shared_locked(object_ptr_shared_locked &&o_oOther)=default
move-CTOR
virtual T * Get() const override
returns the value as pointer
void UnlockObject() override
unlocks the object
virtual tResult Reset(const iobject_ptr< T > &i_oOther) override
Sets the value as pointer.
object_ptr_shared_locked & operator=(object_ptr_shared_locked &&o_oOther)
move-assignment-operator
Namespace for all internally used uCOM functionality implemented.
Namespace for all functionality provided since v3.0.
InterfacePointerType ucom_cast(ObjectPointerType i_pObject)
Used to cast arbitrary interface types within the UCOM.
Definition ucom_cast.h:126
Namespace for the ADTF uCOM3 SDK.
ant::iobject_ptr< T > iobject_ptr
Alias always bringing the latest version of ant::iobject_ptr into scope.
Namespace for entire ADTF SDK.