53d26dd756c592e961cb76eb3a8e198bcd9414cd
[framework/web/wrt-plugins-common.git] / src / modules / tizen / 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
31 void CameraManager::OnRequestReceived(
32     const Api::EventGetCamerasPtr &event)
33 {
34     LogDebug(__FUNCTION__);
35     try
36     {
37         if (m_cameras.empty()) {
38             DPL::Mutex::ScopedLock lock(&m_accessMutex);
39
40             if (m_cameras.empty()) {
41                 Commons::IWrtCameraManager::WrtCamerasPtr cameras;
42                 cameras = event->
43                     getConfiguration()->
44                         getWrtWrapper()->
45                             getCameraManagerInterface()->
46                                 getCameras();
47
48                 FOREACH(it, *cameras)
49                 {
50                     Api::ICameraSharedPtr icamera(new Camera(*it));
51                     m_cameras.push_back(icamera);
52                 }
53             }
54         }
55         event->setCamerasRef(m_cameras,0);
56         LogDebug("Nr of cameras: " << m_cameras.size());
57     }
58     catch(const Commons::Exception &exc)
59     {
60         LogError("Exception has occurred: " << std::hex << exc.getCode());
61         event->setExceptionCode(exc.getCode());
62     }
63 }
64
65 }
66 }