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_CameraRef.cpp
20 * @brief This file contains the implementation of the %_CameraRef class.
24 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseColArrayListT.h>
28 #include "FMedia_CameraRef.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
33 namespace Tizen { namespace Media
36 IListT<_CameraDeviceType>* _CameraRef::__pList = null;
38 _CameraRef::_CameraRef(void)
39 :__deviceType(_CAMERA_DEVICE_NONE)
43 _CameraRef::~_CameraRef(void)
45 UnRegisterCamera(__deviceType);
49 _CameraRef::Construct(const Tizen::Base::Object& obj, _CameraDeviceType deviceType)
53 r = _CamRef::Construct(obj);
54 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
56 r = RegisterCamera(deviceType);
57 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
59 __deviceType = deviceType;
64 _CameraRef::InitSingleton(void)
67 std::unique_ptr <ArrayListT<_CameraDeviceType> > pList (new (std::nothrow) ArrayListT<_CameraDeviceType>());
68 SysTryReturnVoidResult(NID_MEDIA, pList.get() != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed. The object is not created.");
70 r = pList->Construct();
71 SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
73 __pList = pList.release();
74 std::atexit(DestroySingleton);
78 _CameraRef::DestroySingleton(void)
84 _CameraRef::RegisterCamera(_CameraDeviceType deviceType)
88 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
91 pthread_once(&once_block, InitSingleton);
93 SysTryReturn(NID_MEDIA, __pList != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
96 // Duplicate camera devices cannot be created.
97 // Separate camera devices can be created.
98 SysTryReturn(NID_MEDIA, __pList->Contains(deviceType) != true, E_DEVICE_BUSY, E_DEVICE_BUSY
99 , "[E_DEVICE_BUSY] The camera%d is under use by other application or already used in this application.", deviceType);
101 r = __pList->Add(deviceType);
102 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
107 _CameraRef::UnRegisterCamera(_CameraDeviceType deviceType)
109 result r = E_SUCCESS;
110 SysTryReturnVoidResult(NID_MEDIA, __pList != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] No object has been registered.");
112 r = __pList->Remove(deviceType);
113 SysTryReturnVoidResult(NID_MEDIA, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));