9e62143186399df01e04e48076af60dcc63b9842
[framework/web/wrt-plugins-common.git] / src / Commons / WrtWrapper / WrtCamera.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 "WrtCamera.h"
23 #include <dpl/log/log.h>
24 #include <Commons/Exception.h>
25
26 namespace WrtDeviceApis {
27 namespace Commons {
28
29 WrtCamera::WrtCamera(int widgetId,
30                      const engine_interface_t* interface,
31                      CameraInstance camera,
32                      camera_type /*type*/) :
33     m_widgetId(widgetId),
34     m_wrt(interface),
35     m_camera(camera)
36 {
37     if (!interface) {
38         LogError("Pointer to interface is NULL");
39     }
40 }
41
42 void WrtCamera::createPreviewNode(CameraPreviewSuccessCb successCallback,
43                                   CameraErrorCb errorCallback,
44                                   SetPendingOperationCb setPendingOperationCb,
45                                   void* user_data)
46 {
47     if (!m_wrt ||
48         !m_wrt->wrt_camera_create_preview_node)
49     {
50         LogError("Error: Security error");
51         Throw(SecurityException);
52     }
53
54     if (m_wrt->wrt_camera_create_preview_node(
55            m_widgetId,
56            m_camera,
57            successCallback,
58            errorCallback,
59            setPendingOperationCb,
60            user_data))
61     {
62         LogError("Error: Platform error when create_preview_node");
63         Throw(PlatformException);
64     }
65 }
66
67 void WrtCamera::captureImage(const std::string& filename,
68                              bool highRes,
69                              CameraCaptureSuccessCb successCallback,
70                              CameraErrorCb errorCallback,
71                              SetPendingOperationCb setPendingOperationCb,
72                              void* user_data)
73 {
74     if (!m_wrt ||
75         !m_wrt->wrt_camera_capture_image)
76     {
77         LogError("Error: Security error");
78         Throw(SecurityException);
79     }
80
81     if (m_wrt->wrt_camera_capture_image(
82            m_widgetId,
83            m_camera,
84            filename.c_str(),
85            highRes,
86            successCallback,
87            errorCallback,
88            setPendingOperationCb,
89            user_data))
90     {
91         LogError("Error: Platform error when capture_image");
92         Throw(PlatformException);
93     }
94 }
95
96 void WrtCamera::startVideoCapture(const std::string& filename,
97                                   bool highRes,
98                                   CameraCaptureSuccessCb successCallback,
99                                   CameraErrorCb errorCallback,
100                                   SetPendingOperationCb setPendingOperationCb,
101                                   void* user_data)
102 {
103     if (!m_wrt ||
104         !m_wrt->wrt_camera_start_video_capture)
105     {
106         LogError("Error: Security error");
107         Throw(SecurityException);
108     }
109
110     if (m_wrt->wrt_camera_start_video_capture(
111            m_widgetId,
112            m_camera,
113            filename.c_str(),
114            highRes,
115            successCallback,
116            errorCallback,
117            setPendingOperationCb,
118            user_data))
119     {
120         LogError("Error: Platform error when start video");
121         Throw(PlatformException);
122     }
123 }
124
125 void WrtCamera::stopVideoCapture()
126 {
127     if (!m_wrt ||
128         !m_wrt->wrt_camera_stop_video_capture)
129     {
130         LogError("Error: Security error");
131         Throw(SecurityException);
132     }
133
134     if (m_wrt->wrt_camera_stop_video_capture(m_widgetId, m_camera)) {
135         LogError("Error: Platform error when start video");
136         Throw(PlatformException);
137     }
138 }
139
140 void WrtCamera::cancelAsyncOperation (
141     const IWrtCamera::CameraPendingOperation& pendingOperation)
142 {
143     if (!m_wrt ||
144         !m_wrt->wrt_camera_cancel_async_operation)
145     {
146         LogError("Error: Security error");
147         Throw(SecurityException);
148     }
149
150     if (m_wrt->wrt_camera_cancel_async_operation(m_widgetId,
151                                                  m_camera,
152                                                  pendingOperation))
153     {
154         LogError("Error: Platform error when start video");
155         Throw(PlatformException);
156     }
157 }
158
159 WrtCamera::~WrtCamera()
160 {
161     if (!m_wrt ||
162         !m_wrt->wrt_camera_remove_camera)
163     {
164         LogError("Error: Security error");
165         Throw(SecurityException);
166     }
167
168     if (m_wrt->wrt_camera_remove_camera(m_widgetId, m_camera)) {
169         LogError("Error: Platform error when removing camera");
170         //DPL::Assert(0);
171        // Throw(PlatformException);
172     }
173
174     LogDebug("Camera instance removed");
175 }
176
177 }
178 } // WrtDeviceApisCommon