[Release] wrt-plugins-common_0.3.74
[platform/framework/web/wrt-plugins-common.git] / src / modules / tizen / DEPRACATED / Camera-Webkit / CameraManager.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
18  * @version     0.1
19  * @brief
20  */
21 #include <dpl/foreach.h>
22 #include "CameraManager.h"
23 #include <Commons/Exception.h>
24 #include <API/Camera/EventGetCameras.h>
25 #include <API/Camera/ICamera.h>
26 #include "Camera.h"
27
28 namespace WrtDeviceApis {
29 namespace Camera {
30 void CameraManager::OnRequestReceived(
31     const Api::EventGetCamerasPtr &event)
32 {
33     LogDebug(__FUNCTION__);
34     try {
35         if (m_cameras.empty()) {
36             DPL::Mutex::ScopedLock lock(&m_accessMutex);
37
38             if (m_cameras.empty()) {
39                 Commons::IWrtCameraManager::WrtCamerasPtr cameras;
40                 cameras = event->
41                         getConfiguration()->
42                         getWrtWrapper()->
43                         getCameraManagerInterface()->
44                         getCameras();
45
46                 FOREACH(it, *cameras)
47                 {
48                     Api::ICameraSharedPtr icamera(new Camera(*it));
49                     m_cameras.push_back(icamera);
50                 }
51             }
52         }
53         event->setCamerasRef(m_cameras, 0);
54         LogDebug("Nr of cameras: " << m_cameras.size());
55     } catch (const Commons::Exception &exc) {
56         LogError("Exception has occurred: " << std::hex << exc.getCode());
57         event->setExceptionCode(exc.getCode());
58     }
59 }
60 }
61 }