f4c8ec8ecb581ef82c925c644c99e4425f4eafd5
[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         //! Signal. Emitted during the operation mode change to explain the current sub-change.
110         /*!
111          * Signal. Emitted during the operation mode change to explain the current sub-change. 
112          * \param aMessage Explains the sub-change
113          */
114         void changingMode( const QString &aMessage );
115
116 private slots:
117         //! Slot. Handles "full screen"-hardware key presses.
118         /*!
119          * Slot. Handles "full screen"-hardware key presses. Checks the current operation mode and concludes
120          * the next (desired) operation mode to be set. Emits a changeModeOrdered( DeviceManager::OperationMode )
121          * signal.
122          */
123         void HWKeyFullScreenPressed();
124         //! Slot. Sends errors.
125         /*!
126          * Slot. Sends errors.
127          * \param aErrorCode The error code.
128          * \param aAddInfo The possible additional error text.
129          */
130         void errorSender( DeviceManager::ErrorCode aErrorCode, const QString &aAddInfo = "" );
131         //! Slot. Is called after the operation mode changing is finished.
132         /*!
133          * Slot. Is called after the operation mode changing is finished. If everything went fine, restarts
134          * the device. 
135          */
136         void modeChanged();
137         //! Slot. Toggles an attribute that indicates whether the errors should be sent.
138         /*!
139          * Slot. Toggles an attribute that indicates whether the errors should be sent.
140          * \param aToggle Indicates if the errors are wanted to be shown.
141          */
142         void toggleErrorSending( bool aToggle );
143
144 private:
145         //! Updates the internal indicator of the current operation mode.
146         /*!
147          * Updates the internal indicator of the current operation mode by asking the DeviceDataStorage to
148          * read it from the internal data storage. Calls finalizeStandAloneMode() method in case the mode is
149          * StandAloneModeInProgress.
150          * \return True if operation mode fetching succeeds; otherwise, false.
151          */
152         bool setCurrentOperationMode();
153         //! Asks DeviceConfigurator to remove the deactivate script of the application.
154         /*!
155          * Asks DeviceConfigurator to remove the deactivate script of the application. Also asks
156          * DeviceDataStorage to store the current operation mode (StandAloneMode) .
157          * \return True if operation mode storing and deactivation of the init script succeed; otherwise, false.
158          */
159         bool finalizeStandAloneMode();
160         //! Connects/disconnects the HWKeyListener signals to the private HWKeyFullScreenPressed() slot.
161         /*!
162          * Connects/disconnects the HWKeyListener signals to the private HWKeyFullScreenPressed() slot. In case
163          * a signal is caught the connection is disabled until the signal handling is finished.
164          * \param aHandle indicates if the signals should be connected or not.
165          */
166         void handleKeyPresses( bool aHandle );
167
168 private:
169         AlarmSender *iAlarmSender;
170         HWKeyListener *iHWKeyListener;
171         StartupSettings *iSettings;
172         DeviceDataStorage *iDataStorage;
173         DeviceConfigurator *iConfigurator;
174         OperationModeToggler *iModeToggler;
175
176         OperationMode iMode;
177         bool iSendErrorMessages;
178
179 };
180
181 #endif /*DEVICEMANAGER_H_*/