8f24f7ed00cc2b794dc68b9ff39e8674232d6c9d
[framework/web/wrt-plugins-common.git] / src / modules / API / Camera / EventGetCameras.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      Karol Majewski (k.majewski@samsung.com)
18  * @version     0.1
19  * @brief
20  */
21
22 #ifndef WRTPLUGINSIEVENTGETCAMERAS_H_
23 #define WRTPLUGINSIEVENTGETCAMERAS_H_
24
25 #include <vector>
26 #include <cstddef>
27 #include <dpl/shared_ptr.h>
28 #include <Commons/Exception.h>
29 #include <Commons/IEvent.h>
30 #include "ICamera.h"
31 #include <Commons/WidgetConfiguration/ConfigurationSupport.h>
32
33 namespace WrtDeviceApis {
34 namespace Camera {
35 namespace Api {
36
37 class EventGetCameras :
38     public WrtDeviceApis::Commons::ConfigurationSupport,
39     public WrtDeviceApis::Commons::IEvent<EventGetCameras>
40 {
41 public:
42     EventGetCameras() : m_defaultCameraIndex(0) {}
43
44     void setCamerasRef(const std::vector< ICameraSharedPtr > &cameras,
45                        std::size_t defaultCameraIndex)
46     {
47         m_cameras = cameras;
48         m_defaultCameraIndex = defaultCameraIndex;
49     }
50
51     ICameraSharedPtr getCamera(std::size_t index)
52     {
53         if (index >= m_cameras.size() || m_cameras.size() == 0) {
54             Throw(Commons::InvalidArgumentException);
55         }
56         return m_cameras[index];
57     }
58
59     ICameraSharedPtr getDefaultCamera()
60     {
61         if (m_cameras.empty()) {
62             LogError("There are no cameras to choose from");
63             Throw(Commons::OutOfRangeException);
64         }
65         if (m_defaultCameraIndex >= m_cameras.size()) {
66             LogError("Default camera index is out of range");
67             Throw(Commons::InvalidArgumentException);
68         }
69         return m_cameras[m_defaultCameraIndex];
70     }
71
72     std::size_t getNumberOfCameras(){ return m_cameras.size(); }
73
74 private:
75     std::vector< ICameraSharedPtr > m_cameras;
76     std::size_t m_defaultCameraIndex;
77 };
78
79 typedef DPL::SharedPtr<EventGetCameras> EventGetCamerasPtr;
80 }
81 }
82 }
83 #endif /* */