Removed unneeded mutex.
[harmattan/cameraplus] / src / cameraresources.h
1 // -*- c++ -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef CAMERA_RESOURCES_H
24 #define CAMERA_RESOURCES_H
25
26 #include <QObject>
27 #include <QThread>
28 #include <policy/resource-set.h>
29
30 class CameraResourcesWorker;
31
32 class CameraResources : public QObject {
33   Q_OBJECT
34
35   Q_PROPERTY(bool acquired READ acquired NOTIFY acquiredChanged);
36   Q_PROPERTY(bool hijacked READ hijacked NOTIFY hijackedChanged);
37
38   Q_ENUMS(Mode);
39   Q_ENUMS(ResourceType);
40
41 public:
42   typedef enum {
43     None,
44     Image,
45     Video,
46     Recording,
47     PostCapture,
48   } Mode;
49
50   typedef enum {
51     AudioPlaybackType = ResourcePolicy::AudioPlaybackType,
52     VideoPlaybackType = ResourcePolicy::VideoPlaybackType,
53     AudioRecorderType = ResourcePolicy::AudioRecorderType,
54     VideoRecorderType = ResourcePolicy::VideoRecorderType,
55     ScaleButtonType = ResourcePolicy::ScaleButtonType,
56     SnapButtonType = ResourcePolicy::SnapButtonType,
57     LensCoverType = ResourcePolicy::LensCoverType,
58   } ResourceType;
59
60   CameraResources(QObject *parent = 0);
61   ~CameraResources();
62
63   Q_INVOKABLE bool acquire(const Mode& mode);
64
65   Q_INVOKABLE bool isResourceGranted(const ResourceType& resource);
66
67   bool acquired() const;
68   bool hijacked() const;
69
70 signals:
71   void acquiredChanged();
72   void hijackedChanged();
73   void updated();
74
75 private:
76   CameraResourcesWorker *m_worker;
77   QThread m_thread;
78 };
79
80 class CameraResourcesWorker : public QObject {
81   Q_OBJECT
82
83 public:
84   CameraResourcesWorker(QObject *parent = 0);
85   ~CameraResourcesWorker();
86
87 public slots:
88   void acquire(bool *ok, const CameraResources::Mode& mode);
89   void acquired(bool *ok);
90   void hijacked(bool *ok);
91   void isResourceGranted(bool *ok, const CameraResources::ResourceType& resource);
92
93 signals:
94   void acquiredChanged();
95   void hijackedChanged();
96   void updated();
97
98 private slots:
99   void init();
100
101   void resourcesReleased();
102   void lostResources();
103   void resourcesGranted(const QList<ResourcePolicy::ResourceType>& optional);
104   void resourcesDenied();
105
106 private:
107   bool release();
108
109   bool updateSet(const QList<ResourcePolicy::ResourceType>& required,
110                  const QList<ResourcePolicy::ResourceType>& optional =
111                  QList<ResourcePolicy::ResourceType>());
112
113   QList<ResourcePolicy::ResourceType> listSet();
114
115   void setAcquired(bool acquired);
116   void setHijacked(bool hijacked);
117
118   ResourcePolicy::ResourceSet *m_set;
119
120   CameraResources::Mode m_mode;
121   bool m_acquired;
122   bool m_acquiring;
123   bool m_hijacked;
124 };
125
126 #endif /* CAMERA_RESOURCES_H */