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