1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #ifndef _ObjectManager_H_
22 #define _ObjectManager_H_
24 #include "PlatformLayer.h"
25 #include "SSMInterface/SSMCore.h"
27 /* Define NULL pointer value */
32 #define NULL ((void *)0)
41 unsigned char data4[8];
44 const OID OID_IBase = {0x3b465976, 0x6486, 0x4c1f, {0x84, 0xb9, 0xeb, 0x80, 0x79, 0x78, 0x2b, 0x8}};
48 * @brief Compare both OID
50 * @param [in] SSMRESULT res - return code
52 * @return Return positive value if both equal
57 inline int IsEqualOID(const OID &oid1, const OID &oid2)
59 return (( oid1.data1 == oid2.data1) &&
60 ( oid1.data2 == oid2.data2) &&
61 ( oid1.data3 == oid2.data3) &&
62 ( oid1.data4[0] == oid2.data4[0]) &&
63 ( oid1.data4[1] == oid2.data4[1]) &&
64 ( oid1.data4[2] == oid2.data4[2]) &&
65 ( oid1.data4[3] == oid2.data4[3]) &&
66 ( oid1.data4[4] == oid2.data4[4]) &&
67 ( oid1.data4[5] == oid2.data4[5]) &&
68 ( oid1.data4[6] == oid2.data4[6]) &&
69 ( oid1.data4[7] == oid2.data4[7]));
74 * @brief IBase Interface
75 * This class represents top interface of managed Object's interface\n
76 * If any class wants to work as managed Object, must inherit this interface.
85 * @brief Query if requested interface support calling instance
87 * @param [in] const OID& interfaceID - Interface Id looking for
88 * @param [out] IBase** ppObject - Interface pointer holds the object
95 virtual SSMRESULT queryInterface(IN const OID &interfaceID, OUT IBase **ppObject) = 0;
99 * @brief Add reference counter, returns current counter value
103 * @return unsigned long
108 virtual unsigned long addRef() = 0;
112 * @brief Release reference counter, returns current counter value and self destroyed if zero
116 * @return unsigned long
121 virtual unsigned long release() = 0;
125 class CObjectMultiThreadModel;
128 * @brief CObjectRoot Interface
129 * This class represents top class of managed Object\n
130 * If any class wants to work as managed Object, must inherit this class.
134 template <class ThreadModel = CObjectMultiThreadModel>
138 volatile unsigned long m_dwRef;
152 * @brief Add reference counter, returns current counter value
156 * @return unsigned long
161 unsigned long internalAddRef()
163 return ThreadModel::increment(&m_dwRef);
167 * @fn internalRelease
168 * @brief Release reference counter, returns current counter value
172 * @return unsigned long
177 unsigned long internalRelease()
179 return ThreadModel::decrement(&m_dwRef);
185 * @brief CObject Interface
186 * This class provides a way to declare instance of managed Object\n
187 * If user wants to declare instance of managed Object, must use this class.
191 template <class Base>
206 * @brief Add reference counter, returns current counter value
210 * @return unsigned long
215 unsigned long addRef()
217 return this->internalAddRef();
222 * @brief Release reference counter, returns current counter value and self destroyed if zero
226 * @return unsigned long
231 unsigned long release()
233 unsigned long ref = this->internalRelease();
236 this->finalRelease();
244 * @brief Create instance of current template class
246 * @param [out] CObject<Base>** pp - reference pointer to get instance pointer
253 static SSMRESULT createInstance(CObject<Base> **pp)
255 SSMRESULT res = SSM_E_FAIL;
259 return SSM_E_POINTER;
264 CObject<Base> *p = new CObject<Base>();
268 return SSM_E_OUTOFMEMORY;
271 res = p->finalConstruct();
288 * @class _noAddRefReleaseOnCObjectPtr
289 * @brief _noAddRefReleaseOnCObjectPtr Interface
290 * This class used for CObject's Smart pointer mechanism. Internal use only
295 class _noAddRefReleaseOnCObjectPtr :
299 virtual unsigned long addRef() = 0;
300 virtual unsigned long release() = 0;
305 * @brief CObjectPtr Interface
306 * This class used for declaring CObject's interface to work as Smart Pointer
326 _noAddRefReleaseOnCObjectPtr<T> *operator->() const
328 return (_noAddRefReleaseOnCObjectPtr<T> *)p;
348 CObjectPtr(const CObjectPtr<T>& lp)
363 T* operator=(CObjectPtr<T>& lp)
368 bool operator!() const
373 bool operator<(T* pT) const
375 return !operator==(pT);
378 bool operator==(T* pT) const
386 * @fn CreateNewObject
387 * @brief Create instance of declared template
389 * @param [in] const OID& interfaceID - Interface Id looking for
390 * @param [out] IBase** ppObject - reference pointer to get instance pointer
397 SSMRESULT CreateNewObject(IN const OID &objectID, OUT IBase **ppObject)
399 SSMRESULT res = SSM_E_OUTOFMEMORY;
401 CObject<T> *p = new CObject<T>();
408 res = p->finalConstruct();
417 res = p->queryInterface(objectID, ppObject);