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