2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @author Grzegorz Krawczyk(g.krawczyk@samsung.com)
22 #ifndef WRT_PLUGINS_CAMERA_H_
23 #define WRT_PLUGINS_CAMERA_H_
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>
40 namespace WrtDeviceApis {
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)
49 typedef DPL::TypeListDecl<JobDoneTakePictureEvent,
50 JobDoneVideoRecordingEvent,
51 JobDoneCreatePreviewEvent
52 >::Type JobDoneEvents;
54 typedef DPL::Event::Controller<JobDoneEvents> CameraJobDoneController;
56 class Camera : public Api::ICamera,
57 public CameraJobDoneController
67 explicit Camera(const Commons::IWrtCameraPtr& wrtCamera);
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);
80 virtual void OnEventReceived(const JobDoneVideoRecordingEvent &event);
81 virtual void OnEventReceived(const JobDoneCreatePreviewEvent &event);
82 virtual void OnEventReceived(const JobDoneTakePictureEvent &event);
84 void OnCancelEvent(const Api::EventBeginRecordingSharedPtr& event);
85 void OnCancelEvent(const Api::EventTakePictureSharedPtr& event);
86 void OnCancelEvent(const Api::EventGetPreviewNodeSharedPtr& event);
88 void setRecordingState(CameraState state);
91 static void camCaptureImageSuccessCallback(const char* filename,
93 static void camCaptureVideoSuccessCallback(const char* filename,
95 static void camPreviewSuccessCallback(
96 Commons::IWrtCamera::CameraPreviewNode node, void* data);
98 static void camCaptureImageErrorCallback(int errorCode, void* data);
99 static void camCaptureVideoErrorCallback(int errorCode, void* data);
100 static void camPreviewErrorCallback(int errorCode, void* data);
102 template<class EventType>
103 bool checkHighResolutionRequired(const EventType& event) const
105 return event->getCaptureOptionsRef()->getImageResolution()
106 == Api::ICaptureOptions::IMAGE_RESOLUTION_HIGH;
109 template<typename EventData>
110 void OnJobDoneReceived(DPL::SharedPtr<EventData> event)
114 EventRequestReceiver<EventData>::ManualAnswer(event);
119 template<typename EventType>
120 void cancelEvent(const EventType& event)
122 LogDebug(__FUNCTION__);
124 if (event->checkPendingOperation()) {
125 m_wrtCamera->cancelAsyncOperation(event->getPendingOperation());
129 static void setPendingOperation(
130 Commons::IWrtCamera::CameraPendingOperation pendingOperation,
134 Commons::IWrtCameraPtr m_wrtCamera;
136 CameraState m_stateRecordingVideo;
140 #endif /* WRTPLUGINSCAMERA_H_ */