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{
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)
51 typedef DPL::TypeListDecl<JobDoneTakePictureEvent,
52 JobDoneVideoRecordingEvent,
53 JobDoneCreatePreviewEvent
54 >::Type JobDoneEvents;
56 typedef DPL::Event::Controller<JobDoneEvents> CameraJobDoneController;
58 class Camera: public Api::ICamera,
59 public CameraJobDoneController
69 explicit Camera(const Commons::IWrtCameraPtr& wrtCamera);
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);
82 virtual void OnEventReceived(const JobDoneVideoRecordingEvent &event);
83 virtual void OnEventReceived(const JobDoneCreatePreviewEvent &event);
84 virtual void OnEventReceived(const JobDoneTakePictureEvent &event);
86 void OnCancelEvent(const Api::EventBeginRecordingSharedPtr& event);
87 void OnCancelEvent(const Api::EventTakePictureSharedPtr& event);
88 void OnCancelEvent(const Api::EventGetPreviewNodeSharedPtr& event);
90 void setRecordingState(CameraState state);
93 static void camCaptureImageSuccessCallback(const char* filename,
95 static void camCaptureVideoSuccessCallback(const char* filename,
97 static void camPreviewSuccessCallback(
98 Commons::IWrtCamera::CameraPreviewNode node, void* data);
100 static void camCaptureImageErrorCallback(int errorCode, void* data);
101 static void camCaptureVideoErrorCallback(int errorCode, void* data);
102 static void camPreviewErrorCallback(int errorCode, void* data);
104 template<class EventType>
105 bool checkHighResolutionRequired(const EventType& event) const
107 return event->getCaptureOptionsRef()->getImageResolution()
108 == Api::ICaptureOptions::IMAGE_RESOLUTION_HIGH;
111 template<typename EventData>
112 void OnJobDoneReceived(DPL::SharedPtr<EventData> event)
116 EventRequestReceiver<EventData>::ManualAnswer(event);
121 template<typename EventType>
122 void cancelEvent(const EventType& event)
124 LogDebug(__FUNCTION__);
126 if (event->checkPendingOperation()) {
127 m_wrtCamera->cancelAsyncOperation(event->getPendingOperation());
131 static void setPendingOperation(
132 Commons::IWrtCamera::CameraPendingOperation pendingOperation, void* data);
135 Commons::IWrtCameraPtr m_wrtCamera;
137 CameraState m_stateRecordingVideo;
142 #endif /* WRTPLUGINSCAMERA_H_ */