32e0a3da3b64257f75be0cefc6764d8154c4c283
[framework/web/wrt-plugins-common.git] / src / modules / tizen / DEPRACATED / Camera / 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      Karol Majewski (k.majewski@samsung.com)
18  * @version     0.1
19  * @brief
20  */
21
22 #include "CameraManager.h"
23 #include "mm_camcorder.h"
24 #include <commons/Exception.h>
25 #include <API/Camera/EventGetCameras.h>
26 #include <API/Camera/ICamera.h>
27 #include "Camera.h"
28
29 namespace WrtPlugins {
30 namespace Platform {
31 namespace Camera {
32 //.............................................................................
33 void CameraManager::OnRequestReceived(
34         const Api::Camera::EventGetCamerasPtr &event)
35 {
36     LogDebug(__FUNCTION__);
37     try
38     {
39         DPL::Mutex::ScopedLock lock(&m_accessMutex);
40         {
41             if (m_cameras.empty()) {
42                 for (int i = (MM_VIDEO_DEVICE_NONE + 1);
43                      i < MM_VIDEO_DEVICE_NUM;
44                      ++i) {
45                     LogDebug(
46                         "current camera i=" << i <<
47                         " (mm_video_device_num: " << MM_VIDEO_DEVICE_NUM);
48                     MMCamPreset cam_info;
49                     cam_info.videodev_type = static_cast<MMVideoDeviceType>(i);
50                     Camera *icamera = new Camera();
51                     m_cameras.push_back(Api::Camera::ICameraSharedPtr(icamera));
52                     icamera->init(cam_info);
53                 }
54             }
55             event->setCamerasRef(m_cameras, MM_VIDEO_DEVICE_CAMERA0);
56         }
57         LogDebug("Nr of cameras: " << m_cameras.size());
58         return;
59     }
60     catch (Commons::Exception &exc)
61     {
62         LogError("Exception has occurred: " << std::hex << exc.getCode());
63         event->setExceptionCode(exc.getCode());
64     }
65 }
66 //.............................................................................
67 }
68 }
69 }