tizen beta release
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Camera-Webkit / Camera.h
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 #ifndef WRT_PLUGINS_CAMERA_H_
23 #define WRT_PLUGINS_CAMERA_H_
24
25 #include <string>
26 #include <dpl/log/log.h>
27 #include <dpl/generic_event.h>
28 #include <dpl/event/controller.h>
29 #include <dpl/type_list.h>
30 #include <dpl/shared_ptr.h>
31 #include <API/Camera/ICamera.h>
32 #include <API/Camera/ICaptureOptions.h>
33 #include <API/Camera/EventTakePicture.h>
34 #include <API/Camera/EventBeginRecording.h>
35 #include <API/Camera/EventEndRecording.h>
36 #include <API/Camera/EventGetPreviewNode.h>
37 #include <Commons/Dimension.h>
38 #include <Commons/WrtWrapper/IWrtCamera.h>
39
40 namespace WrtDeviceApis{
41 namespace Camera{
42
43 DECLARE_GENERIC_EVENT_1(JobDoneTakePictureEvent,
44                         Camera::Api::EventTakePictureSharedPtr)
45 DECLARE_GENERIC_EVENT_1(JobDoneVideoRecordingEvent,
46                         Camera::Api::EventBeginRecordingSharedPtr)
47 DECLARE_GENERIC_EVENT_1(JobDoneCreatePreviewEvent,
48                         Camera::Api::EventGetPreviewNodeSharedPtr)
49
50
51 typedef DPL::TypeListDecl<JobDoneTakePictureEvent,
52                           JobDoneVideoRecordingEvent,
53                           JobDoneCreatePreviewEvent
54                               >::Type JobDoneEvents;
55
56 typedef DPL::Event::Controller<JobDoneEvents> CameraJobDoneController;
57
58 class Camera: public Api::ICamera,
59               public CameraJobDoneController
60 {
61 public:
62     enum CameraState{
63         IDLE,
64         PROCESSING,
65         COMPLETED
66     };
67
68 public:
69     explicit Camera(const Commons::IWrtCameraPtr& wrtCamera);
70
71     virtual ~Camera();
72
73     virtual void OnRequestReceived(
74         const Api::EventTakePictureSharedPtr &event);
75     virtual void OnRequestReceived(
76         const Api::EventBeginRecordingSharedPtr &event);
77     virtual void OnRequestReceived(
78         const Api::EventEndRecordingSharedPtr &event);
79     virtual void OnRequestReceived(
80         const Api::EventGetPreviewNodeSharedPtr &event);
81
82     virtual void OnEventReceived(const JobDoneVideoRecordingEvent &event);
83     virtual void OnEventReceived(const JobDoneCreatePreviewEvent &event);
84     virtual void OnEventReceived(const JobDoneTakePictureEvent &event);
85
86     void OnCancelEvent(const Api::EventBeginRecordingSharedPtr& event);
87     void OnCancelEvent(const Api::EventTakePictureSharedPtr& event);
88     void OnCancelEvent(const Api::EventGetPreviewNodeSharedPtr& event);
89
90     void setRecordingState(CameraState state);
91
92 private:
93     static void camCaptureImageSuccessCallback(const char* filename,
94                                                void* data);
95     static void camCaptureVideoSuccessCallback(const char* filename,
96                                                void* data);
97     static void camPreviewSuccessCallback(
98             Commons::IWrtCamera::CameraPreviewNode node, void* data);
99
100     static void camCaptureImageErrorCallback(int errorCode, void* data);
101     static void camCaptureVideoErrorCallback(int errorCode, void* data);
102     static void camPreviewErrorCallback(int errorCode, void* data);
103
104     template<class EventType>
105     bool checkHighResolutionRequired(const EventType& event) const
106     {
107         return event->getCaptureOptionsRef()->getImageResolution()
108             == Api::ICaptureOptions::IMAGE_RESOLUTION_HIGH;
109     }
110
111     template<typename EventData>
112     void OnJobDoneReceived(DPL::SharedPtr<EventData> event)
113     {
114         LogDebug("enter");
115         if (event) {
116             EventRequestReceiver<EventData>::ManualAnswer(event);
117         }
118         LogDebug("post");
119     }
120
121     template<typename EventType>
122     void cancelEvent(const EventType& event)
123     {
124         LogDebug(__FUNCTION__);
125
126         if (event->checkPendingOperation()) {
127             m_wrtCamera->cancelAsyncOperation(event->getPendingOperation());
128         }
129     }
130
131     static void setPendingOperation(
132         Commons::IWrtCamera::CameraPendingOperation pendingOperation, void* data);
133
134 private:
135     Commons::IWrtCameraPtr m_wrtCamera;
136
137     CameraState m_stateRecordingVideo;
138 };
139
140 }
141 }
142 #endif /* WRTPLUGINSCAMERA_H_ */