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