5836e5f6f4fdeb18c697648f9362bb9d2b295f24
[framework/web/wrt-plugins-common.git] / src / Commons / WrtWrapper / WrtCameraManager.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
22 #include "WrtCameraManager.h"
23 #include <dpl/log/log.h>
24 #include <Commons/Exception.h>
25 #include "WrtCamera.h"
26
27 namespace WrtDeviceApis {
28 namespace Commons {
29
30 WrtCameraManager::WrtCameraManager(int widgetId,
31                                    const engine_interface_t* interface)
32     : m_widgetId(widgetId)
33 {
34     m_wrt = interface;
35
36     if (!interface) {
37         LogError("Pointer to interface is NULL");
38     }
39
40     m_cameras = WrtCamerasPtr(new WrtCameras);
41 }
42
43
44 IWrtCameraManager::WrtCamerasPtr WrtCameraManager::getCameras()
45 {
46     static bool initialized = initialize();
47     (void)initialized;
48
49     return m_cameras;
50 }
51
52 bool WrtCameraManager::initialize()
53 {
54     if (!m_wrt ||
55         !m_wrt->wrt_camera_get_cameras ||
56         !m_wrt->wrt_camera_free_webkit_cameras)
57     {
58         LogError("Error: Security error");
59         Throw(SecurityException);
60     }
61
62     webkit_cameras_array *array = m_wrt->wrt_camera_get_cameras(m_widgetId);
63     if (NULL == array) {
64         LogError("Error: Platform error when get_cameras");
65         Throw(PlatformException);
66     }
67
68     for (size_t i = 0; i < array->size; ++i) {
69         m_cameras->push_back(
70             IWrtCameraPtr(new WrtCamera(m_widgetId,
71                                         m_wrt,
72                                         array->webkit_cameras[i].camera,
73                                         array->webkit_cameras[i].type)));
74     }
75     return true;
76
77
78
79
80 }
81
82 }
83 } // WrtDeviceApisCommon