src/UserInterface/Components/ \
src/UserInterface/Utils/ \
src/UserInterface/Views/
-HEADERS += src/UserInterface/Utils/ProgressBar.h \
+HEADERS += src/IO/DeviceControl/OperationModeToggler.h \
+ src/UserInterface/Utils/ProgressBar.h \
src/Domain/Room.h \
src/Domain/Meeting.h \
src/Domain/Configuration/ConnectionSettings.h \
src/UserInterface/Views/MeetingInfoDialog.h \
src/UserInterface/Views/SettingsView.h \
src/UserInterface/WindowManager.h
-SOURCES += src/UserInterface/Utils/ProgressBar.cpp \
+SOURCES += src/IO/DeviceControl/OperationModeToggler.cpp \
+ src/UserInterface/Utils/ProgressBar.cpp \
src/Domain/Room.cpp \
src/Domain/Meeting.cpp \
src/Domain/Configuration/ConnectionSettings.cpp \
resources/UserInterface.qrc
CONFIG += link_pkgconfig
PKGCONFIG += libalarm
-
//DEFINES += DEBUG_OUTPUT_TO_FILE
executable.files = qtmeetings
executable.path = /usr/bin/
<error code="210">Error storing data of original automatic screen switching-off and dimming parameter values. Using the default values instead.</error>
<error code="211">Error fetching data of original automatic screen switching-off and dimming parameter values. Using the default values instead.</error>
<error code="212">Failed to change the operation mode. Error changing automatic screen switching-off and dimming parameter values.</error>
- <error code="213">Failed to change the operation mode. Error restarting the device.</error>
+ <error code="213">Failed to change the operation mode. Error restarting the device. Restart device manually.</error>
</errors>
#include "StartupSettings.h"
#include "DeviceDataStorage.h"
#include "DeviceConfigurator.h"
+#include "OperationModeToggler.h"
#include <QtDebug>
#include <QStringList>
DeviceManager::~DeviceManager()
{
qDebug() << "DeviceManager::~DeviceManager()";
+ delete iDataStorage;
+ iDataStorage = 0;
+ delete iAlarmSender;
+ iAlarmSender = 0;
+ delete iConfigurator;
+ iConfigurator = 0;
+ delete iDataStorage;
+ iDataStorage = 0;
+ delete iHWKeyListener;
+ iHWKeyListener = 0;
}
void DeviceManager::initDeviceManager()
handleKeyPresses( true );
return;
}
-
- switch ( iMode )
- {
- case EmptyMode:
- // error occured. Mode cannot be changed
- errorSender( ModeNotFetched );
- handleKeyPresses( true );
- break;
- case StandAloneMode:
-
- // change to KioskMode
- emit changingMode( "Changing to Kiosk mode" );
- while( 1 );
-
- // check if auto turn on/off functionality enabled and send turn on/off alarm events to alarm daemon
- if ( iSettings->isPowersavingEnabled() )
- {
- if ( !iAlarmSender->sendAlarms( iSettings->turnOnAt(), iSettings->turnOffAt() ) )
- {
- handleKeyPresses( true );
- return; //this is critical so returning if no success
- }
- }
-
- // - disable the certain hw keys (only "home"-hw-key at the moment)
- // - register init script to launch the application when ever the device is launched
- // - disable the screen "auto-switch-off" and "dimming"
- // - store info about the new operation mode
- if ( !iConfigurator->toggleHWKeys( false ) ||
- !iConfigurator->toggleInitScript( true ) ||
- !iConfigurator->toggleScreenSwitchOff( false ) ||
- !this->storeOperationMode( KioskMode ) ||
- !iConfigurator->restartDevice() )
- {
-
- // we have to roll back if something fails
- // of course rolling back may fail as well but it is impossible to catch
- iSendErrorMessages = false;
- iAlarmSender->removeAlarms();
- iConfigurator->toggleHWKeys( true );
- iConfigurator->toggleInitScript( false );
- iConfigurator->toggleScreenSwitchOff( true );
- iSendErrorMessages = true;
- handleKeyPresses( true );
- return;
- }
- break;
-
- case KioskMode:
- // change to StandAloneInProgress mode
-
- // - enable the certain hw keys (only "home"-hw-key at the moment)
- // - unregister the init script
- // - enable the screen "auto-switch-off" and "dimming"
- // - store info about the new operation mode
- if ( !iConfigurator->toggleHWKeys( true ) ||
- !iConfigurator->toggleScreenSwitchOff( true ) ||
- !this->storeOperationMode( StandAloneModeInProgress ) ||
- !iAlarmSender->removeStoredAlarms() ||
- !iConfigurator->restartDevice() )
- {
- // we have to roll back if something fails
- // of course rolling back may fail as well but it is impossible to catch
- iSendErrorMessages = false;
- iConfigurator->toggleHWKeys( false );
- iConfigurator->toggleInitScript( true );
- iConfigurator->toggleScreenSwitchOff( false );
- this->storeOperationMode( KioskMode );
- iSendErrorMessages = true;
- handleKeyPresses( true );
- return;
- }
-
- break;
- default: // StandAloneModeInProgress should never come in question
- break;
- }
+ iModeToggler = new OperationModeToggler( iMode, iSettings, iAlarmSender, iConfigurator, iDataStorage );
+ connect( iModeToggler, SIGNAL( finished() ), this, SLOT( modeChanged() ) );
+ connect( iModeToggler, SIGNAL( error( DeviceManager::ErrorCode ) ), this, SLOT( errorSender( DeviceManager::ErrorCode ) ) );
+ connect( iModeToggler, SIGNAL( changingMode( const QString & ) ), this, SIGNAL( changingMode( const QString & ) ) );
+ connect( iModeToggler, SIGNAL( toggleErrorSending( bool ) ), this, SLOT( toggleErrorSending( bool ) ) );
+ iModeToggler->start();
}
bool DeviceManager::setCurrentOperationMode()
return true;
}
-bool DeviceManager::storeOperationMode( OperationMode aMode )
-{
- qDebug() << "DeviceManager::storeOperationMode( const OperationMode & )";
- QStringList modeStrList;
- QString str;
- modeStrList.append( str.append( QString( "%1" ).arg( aMode ) ) );
- if ( !iDataStorage->storeData( iDataStorage->dataSectionToString( DeviceDataStorage::DeviceMode ), modeStrList ) )
- {
- errorSender( ModeNotStored );
- return false;
- }
- return true;
-}
-
bool DeviceManager::finalizeStandAloneMode()
{
qDebug() << "DeviceManager::finalizeStandAloneMode()";
- if ( !storeOperationMode( StandAloneMode ) || !iConfigurator->toggleInitScript( false ) )
+ if ( !OperationModeToggler::storeOperationMode( StandAloneMode, iDataStorage ) || !iConfigurator->toggleInitScript( false ) ) {
+ errorSender( DeviceManager::ModeNotStored );
return false;
+ }
return true;
}
emit error( ERROR_BASE + ( int )aErrorCode, aAddInfo );
}
+
+void DeviceManager::toggleErrorSending( bool aToggle )
+{
+ iSendErrorMessages = aToggle;
+}
+
+void DeviceManager::modeChanged()
+{
+ if( iModeToggler != 0 ) {
+ if ( iModeToggler->success() ) { //mode changing went well
+ delete iModeToggler;
+ iModeToggler = 0;
+ iConfigurator->restartDevice();
+ }
+ }
+
+ //in case device restarting fails we just continue
+ handleKeyPresses( true );
+}
\ No newline at end of file
class StartupSettings;
class DeviceDataStorage;
class DeviceConfigurator;
+class OperationModeToggler;
static const int ERROR_BASE=200;
* \param aAddInfo The possible additional error text.
*/
void errorSender( DeviceManager::ErrorCode aErrorCode, const QString &aAddInfo = "" );
+ void modeChanged();
private:
//! Updates the internal indicator of the current operation mode.
* \return True if operation mode fetching succeeds; otherwise, false.
*/
bool setCurrentOperationMode();
- //! Stores the current operation mode.
- /*!
- * Stores the current operation mode by asking the DeviceDataStorage to write it to the internal
- * data storage.
- * \param aMode The operation mode that user wants to activate.
- * \return True if operation mode storing succeeds; otherwise, false.
- */
- bool storeOperationMode( OperationMode aMode );
//! Asks DeviceConfigurator to remove the deactivate script of the application.
/*!
* Asks DeviceConfigurator to remove the deactivate script of the application. Also asks
* \param aHandle indicates if the signals should be connected or not.
*/
void handleKeyPresses( bool aHandle );
+ void toggleErrorSending( bool aToggle );
private:
AlarmSender *iAlarmSender;
StartupSettings *iSettings;
DeviceDataStorage *iDataStorage;
DeviceConfigurator *iConfigurator;
+ OperationModeToggler *iModeToggler;
OperationMode iMode;
bool iSendErrorMessages;
--- /dev/null
+#include "OperationModeToggler.h"
+#include "DeviceManager.h"
+#include "StartupSettings.h"
+#include "AlarmSender.h"
+#include "DeviceConfigurator.h"
+#include "DeviceDataStorage.h"
+
+#include <QtDebug>
+
+OperationModeToggler::OperationModeToggler(
+ DeviceManager::OperationMode aMode,
+ StartupSettings *aSettings,
+ AlarmSender *aAlarmSender,
+ DeviceConfigurator *aConfigurator,
+ DeviceDataStorage *aDataStorage
+ ) :
+ iMode( aMode ),
+ iSettings( aSettings ),
+ iAlarmSender( aAlarmSender ),
+ iConfigurator( aConfigurator ),
+ iDataStorage( aDataStorage ),
+ iSuccess( true )
+{
+ qDebug() << "OperationModeToggler::OperationModeToggler( ... )";
+}
+
+OperationModeToggler::~OperationModeToggler()
+{
+ qDebug() << "OperationModeToggler::~OperationModeToggler()";
+}
+
+void OperationModeToggler::run()
+{
+ switch ( iMode )
+ {
+ case DeviceManager::EmptyMode:
+ // error occured. Mode cannot be changed
+ emit error( DeviceManager::ModeNotFetched );
+ iSuccess = false;
+ return;
+ case DeviceManager::StandAloneMode:
+
+ // change to KioskMode
+
+ // check if auto turn on/off functionality enabled and send turn on/off alarm events to alarm daemon
+ if ( iSettings->isPowersavingEnabled() )
+ {
+ emit changingMode( "Sending the auto launch alarms to alarm daemon." );
+ if ( !iAlarmSender->sendAlarms( iSettings->turnOnAt(), iSettings->turnOffAt() ) )
+ {
+ iSuccess = false;
+ return; //this is critical so returning if no success
+ }
+ }
+
+ // - disable the certain hw keys (only "home"-hw-key at the moment)
+ // - register init script to launch the application when ever the device is launched
+ // - disable the screen "auto-switch-off" and "dimming"
+ // - store info about the new operation mode
+
+ emit changingMode( "Disabling home hardware-key." );
+ sleep( 2 );
+ if( !iConfigurator->toggleHWKeys( false ) )
+ iSuccess = false;
+ if( iSuccess ) {
+ emit changingMode( "Installing the application init start-up script." );
+ sleep( 2 );
+ if ( !iConfigurator->toggleInitScript( true ) )
+ iSuccess = false;
+ }
+ if( iSuccess ) {
+ emit changingMode( "Disabling the screen switching off and dimming." );
+ sleep( 2 );
+ if( !iConfigurator->toggleScreenSwitchOff( false ) )
+ iSuccess = false;
+ }
+ if( iSuccess ) {
+ emit changingMode( "Storing information about the new operation mode." );
+ sleep( 2 );
+ if( !storeOperationMode( DeviceManager::KioskMode, iDataStorage ) ) {
+ emit error( DeviceManager::ModeNotStored );
+ iSuccess = false;
+ }
+ }
+ if( !iSuccess ) {
+ // we have to roll back if something fails
+ // of course rolling back may fail as well but it is impossible to catch
+ emit toggleErrorSending( false );
+ iAlarmSender->removeAlarms();
+ iConfigurator->toggleHWKeys( true );
+ iConfigurator->toggleInitScript( false );
+ iConfigurator->toggleScreenSwitchOff( true );
+ emit toggleErrorSending( true );
+ return;
+ }
+ break;
+
+ case DeviceManager::KioskMode:
+ // change to StandAloneInProgress mode
+
+ // - enable the certain hw keys (only "home"-hw-key at the moment)
+ // - unregister the init script
+ // - enable the screen "auto-switch-off" and "dimming"
+ // - store info about the new operation mode
+ emit changingMode( "Enabling home hardware-key." );
+ sleep( 2 );
+ if( !iConfigurator->toggleHWKeys( true ) )
+ iSuccess = false;
+ if( iSuccess ) {
+ emit changingMode( "Enabling the screen switching off and dimming." );
+ sleep( 2 );
+ if( !iConfigurator->toggleScreenSwitchOff( true ) )
+ iSuccess = false;
+ }
+ if( iSuccess ) {
+ emit changingMode( "Storing information about the new operation mode." );
+ sleep( 2 );
+ if( !storeOperationMode( DeviceManager::StandAloneModeInProgress, iDataStorage ) ) {
+ emit error( DeviceManager::ModeNotStored );
+ iSuccess = false;
+ }
+ }
+ if( iSuccess ) {
+ emit changingMode( "Removing the auto launch alarms from alarm daemon." );
+ sleep( 2 );
+ if( !iAlarmSender->removeStoredAlarms() )
+ iSuccess = false;
+ }
+ if( !iSuccess ) {
+ // we have to roll back if something fails
+ // of course rolling back may fail as well but it is impossible to catch
+ emit toggleErrorSending( false );
+ iConfigurator->toggleHWKeys( false );
+ iConfigurator->toggleInitScript( true );
+ iConfigurator->toggleScreenSwitchOff( false );
+ storeOperationMode( DeviceManager::KioskMode, iDataStorage );
+ emit toggleErrorSending( true );
+ return;
+ }
+ break;
+ default: // StandAloneModeInProgress should never come in question
+ break;
+ }
+}
+
+bool OperationModeToggler::success()
+{
+ return iSuccess;
+}
+
+bool OperationModeToggler::storeOperationMode( DeviceManager::OperationMode aMode, DeviceDataStorage *aDataStorage )
+{
+ qDebug() << "OperationModeToggler::storeOperationMode( const OperationMode & )";
+ QStringList modeStrList;
+ QString str;
+ modeStrList.append( str.append( QString( "%1" ).arg( aMode ) ) );
+ if ( !aDataStorage->storeData( aDataStorage->dataSectionToString( DeviceDataStorage::DeviceMode ), modeStrList ) )
+ return false;
+ return true;
+}
--- /dev/null
+#ifndef OPERATIONMODETOGGLER_H_
+#define OPERATIONMODETOGGLER_H_
+
+#include "DeviceManager.h"
+
+#include <QThread>
+
+class StartupSettings;
+class AlarmSender;
+class DeviceConfigurator;
+class DeviceDataStorage;
+
+class OperationModeToggler : public QThread
+{
+ Q_OBJECT
+
+public:
+ //! Constructor.
+ /*!
+ * Constructor for HWKeyListener class
+ */
+ OperationModeToggler(
+ DeviceManager::OperationMode aMode,
+ StartupSettings *aSettings,
+ AlarmSender *aAlarmSender,
+ DeviceConfigurator *aConfigurator,
+ DeviceDataStorage *aDataStorage
+ );
+
+ //! Destructor.
+ virtual ~OperationModeToggler();
+ //! Run method of the class.
+ /*!
+ * Run method of the class.
+ */
+ void run();
+ bool success();
+ //! Stores the current operation mode.
+ /*!
+ * Stores the current operation mode by asking the DeviceDataStorage to write it to the internal
+ * data storage.
+ * \param aMode The operation mode that user wants to activate.
+ * \return True if operation mode storing succeeds; otherwise, false.
+ */
+ static bool storeOperationMode( DeviceManager::OperationMode aMode, DeviceDataStorage *aDataStorage );
+
+signals:
+ void error( DeviceManager::ErrorCode aCode );
+ void toggleErrorSending( bool aToggle );
+ void changingMode( const QString &aMessage );
+
+private:
+ DeviceManager::OperationMode iMode;
+ StartupSettings *iSettings;
+ AlarmSender *iAlarmSender;
+ DeviceConfigurator *iConfigurator;
+ DeviceDataStorage *iDataStorage;
+ bool iSuccess;
+};
+
+#endif /*OPERATIONMODETOGGLER_H_*/
subLayout->addWidget( buttonCancel );
connect( buttonCancel, SIGNAL( pressed() ), this, SIGNAL( cancel() ) );
}
+ mainLayout->addLayout( subLayout );
setLayout( mainLayout );
}