2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FMedia_CamRef.cpp
20 * @brief This file contains the implementation of the %_CamRef class.
24 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
27 #include "FMedia_CamRef.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
32 namespace Tizen { namespace Media
35 IList* _CamRef::__pList = null;
37 _CamRef::_CamRef(void)
42 _CamRef::~_CamRef(void)
46 UnRegisterObject(*__pObj);
51 _CamRef::Construct(const Tizen::Base::Object& obj)
54 r = RegisterObject(obj);
55 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
56 __pObj = const_cast<Tizen::Base::Object*>(&obj);
61 _CamRef::InitSingleton()
64 std::unique_ptr <ArrayList> pList (new (std::nothrow) ArrayList());
65 SysTryReturnVoidResult(NID_MEDIA, pList.get() != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
67 r = pList->Construct();
68 SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
70 __pList = pList.release();
71 std::atexit(DestroySingleton);
75 _CamRef::DestroySingleton(void)
81 _CamRef::IsAlive(const Tizen::Base::Object& obj)
83 SysTryReturn(NID_MEDIA, __pList != null, false, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Any object was not found.");
84 return __pList->Contains(obj);
88 _CamRef::RegisterObject(const Tizen::Base::Object& obj)
92 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
95 pthread_once(&once_block, InitSingleton);
97 SysTryReturn(NID_MEDIA, __pList != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
100 r = __pList->Add(const_cast<Tizen::Base::Object*>(&obj));
101 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
106 _CamRef::UnRegisterObject(const Tizen::Base::Object& obj)
108 result r = E_SUCCESS;
109 SysTryReturnVoidResult(NID_MEDIA, __pList != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] No object has been registered.");
111 r = __pList->Remove(obj);
112 SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));