f3f89dc2dd3339e7458b4b3549eb4a7df0f08249
[qtmeetings] / src / IO / DeviceControl / DeviceManager.h
1 #ifndef DEVICEMANAGER_H_
2 #define DEVICEMANAGER_H_
3
4 #include <QObject>
5 #include <QStringList>
6
7 class AlarmSender;
8 class HWKeyListener;
9 class StartupSettings;
10 class DeviceDataStorage;
11 class DeviceConfigurator;
12
13 static const int ERROR_BASE=200;
14
15 //! DeviceControl class. The main class of the DeviceControl.
16 /*!
17  * DeviceControl class. The main class of the DeviceControl. Responsible to communicate between the
18  * BusinessLogic and the device. Takes care of the operation mode changes of the application.
19  */
20 class DeviceManager : public QObject
21 {
22         Q_OBJECT
23
24 public:
25         //! Enumeration of device modes
26         /*!
27          * Enumeration of device modes
28          */
29         enum OperationMode
30         {
31                 KioskMode, /*!< Device is in kiosk mode. */
32                 StandAloneModeInProgress, /*!< Device is in stand alone mode. */
33                 StandAloneMode, /*!< Device is in stand alone mode. */
34                 EmptyMode /*!< Application cannot read the mode. */
35         };
36
37         //! Enumeration of errors
38         /*!
39          * Enumeration of errors
40          */
41         enum ErrorCode
42         {
43                 FileCreationFailed, /*!< File couldn't be created. */
44                 OldAlarmsNotRemoved, /*!< Previously sent old alarm events cannot be removed. */
45                 NewAlarmsNotSent, /*!< New alarms cannot be sent. */
46                 NewAlarmsNotStored, /*!< Information about new sent alarms cannot be stored. */
47                 ScreenSettingsNotStored, /*!< Configuration parameters of screen options cannot be stored. */
48                 ScreenSettingsNotFetched, /*!< Configuration parameters of screen options cannot be fetched. */
49                 ScreenSettingsNotChanged, /*!< Configuration parameters of screen options cannot be changed. */
50                 KeySettingsNotFetched, /*!< Configuration parameters of hw key options cannot be fetched. */
51                 KeySettingsNotStored, /*!< Configuration parameters of hw key options cannot be stored. */
52                 KeySettingsNotChanged, /*!< Configuration parameters of hw key options cannot be changed. */
53                 InitScriptNotChanged, /*!< Init script to auto launch the application was not registered/unregistered */
54                 ModeNotFetched, /*!< Information about the current operation mode cannot be fetched */
55                 ModeNotStored, /*!< Information about the new opration mode cannot be stored */
56                 DeviceNotRestarted /*!< Device cannot be restarted */
57         };
58
59 public:
60         //! Constructor.
61         /*!
62          * Constructor to initialize a DeviceManager instance.
63          * \param aSettings Pointer to the start up configuration settings.
64          */
65         DeviceManager( StartupSettings *aSettings );
66         //! Destructor.
67         virtual ~DeviceManager();
68         //! Creates instances of AlarmSender, DeviceConfigurator, DeviceDataStorage and HWKeyListener classes.
69         /*!
70          * Creates instances of AlarmSender, DeviceConfigurator, DeviceDataStorage and HWKeyListener classes.
71          * Connects their signals to the correct errorSender( ... ) slot.
72          */
73         void initDeviceManager();
74         //! Gets the current operation mode.
75         /*!
76          * Gets the current operation mode of the application.
77          * \return enum value of the current operation mode.
78          */
79         DeviceManager::OperationMode currentOperationMode();
80         //! Gets the string value of an operation mode.
81         /*!
82          * Gets the string value of an operation mode.
83          * \param aMode The enum value of the operation mode.
84          * \return QString value of the current operation mode.
85          */
86         QString operationModeToString( OperationMode aMode );
87
88 signals:
89         //! Signal. Emitted if user tries to change the operation mode.
90         /*!
91          * Signal. Emitted if user tries to change the operation mode.
92          * \param aMode The operation mode that user wants to activate.
93          */
94         void changeModeOrdered( DeviceManager::OperationMode aMode );
95         //! Signal. Emitted if an error happens.
96         /*!
97          * Signal. Emitted if an error happens.
98          * \param aCode An error code defined by DeviceManager.
99          * \param aAddInfo Possible additional information.
100          */
101         void error( int aCode, const QString &aAddInfo );
102
103 public slots:
104         //! Slot. Changes the operation mode.
105         /*!
106          * Slot. Changes the operation mode.
107          * \param aChange To indicate if the mode should be changed or not
108          */
109         void changeMode( bool aChange );
110
111 private slots:
112         //! Slot. Handles "full screen"-hardware key presses.
113         /*!
114          * Slot. Handles "full screen"-hardware key presses. Checks the current operation mode and concludes
115          * the next (desired) operation mode to be set. Emits a changeModeOrdered( DeviceManager::OperationMode )
116          * signal.
117          */
118         void HWKeyFullScreenPressed();
119         //! Slot. Sends errors.
120         /*!
121          * Slot. Sends errors.
122          * \param aErrorCode The error code.
123          * \param aAddInfo The possible additional error text.
124          */
125         void errorSender( DeviceManager::ErrorCode aErrorCode, const QString &aAddInfo = "" );
126
127 private:
128         //! Updates the internal indicator of the current operation mode.
129         /*!
130          * Updates the internal indicator of the current operation mode by asking the DeviceDataStorage to
131          * read it from the internal data storage. Calls finalizeStandAloneMode() method in case the mode is
132          * StandAloneModeInProgress.
133          * \return True if operation mode fetching succeeds; otherwise, false.
134          */
135         bool setCurrentOperationMode();
136         //! Stores the current operation mode.
137         /*!
138          * Stores the current operation mode by asking the DeviceDataStorage to write it to the internal
139          * data storage.
140          * \param aMode The operation mode that user wants to activate.
141          * \return True if operation mode storing succeeds; otherwise, false.
142          */
143         bool storeOperationMode( OperationMode aMode );
144         //! Asks DeviceConfigurator to remove the deactivate script of the application.
145         /*!
146          * Asks DeviceConfigurator to remove the deactivate script of the application. Also asks
147          * DeviceDataStorage to store the current operation mode (StandAloneMode) .
148          * \return True if operation mode storing and deactivation of the init script succeed; otherwise, false.
149          */
150         bool finalizeStandAloneMode();
151         //! Connects/disconnects the HWKeyListener signals to the private HWKeyFullScreenPressed() slot.
152         /*!
153          * Connects/disconnects the HWKeyListener signals to the private HWKeyFullScreenPressed() slot. In case
154          * a signal is caught the connection is disabled until the signal handling is finished.
155          * \param aHandle indicates if the signals should be connected or not.
156          */
157         void handleKeyPresses( bool aHandle );
158
159 private:
160         AlarmSender *iAlarmSender;
161         HWKeyListener *iHWKeyListener;
162         StartupSettings *iSettings;
163         DeviceDataStorage *iDataStorage;
164         DeviceConfigurator *iConfigurator;
165
166         OperationMode iMode;
167         bool iSendErrorMessages;
168
169 };
170
171 #endif /*DEVICEMANAGER_H_*/