New thread class (OperationodeToggler) created in DeviceControl module to send sub...
authorJan Lapinkataja <jan.lapinkataja@ixonos.com>
Fri, 22 May 2009 07:58:35 +0000 (10:58 +0300)
committerJan Lapinkataja <jan.lapinkataja@ixonos.com>
Fri, 22 May 2009 07:58:35 +0000 (10:58 +0300)
QtMeetings.pro
resources/xml/errortable.xml
src/IO/DeviceControl/DeviceManager.cpp
src/IO/DeviceControl/DeviceManager.h
src/IO/DeviceControl/OperationModeToggler.cpp [new file with mode: 0644]
src/IO/DeviceControl/OperationModeToggler.h [new file with mode: 0644]
src/UserInterface/Utils/ProgressBar.cpp

index f223557..c57d210 100644 (file)
@@ -13,7 +13,8 @@ INCLUDEPATH += src/Domain/ \
     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 \
@@ -44,7 +45,8 @@ HEADERS += src/UserInterface/Utils/ProgressBar.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 \
@@ -80,7 +82,6 @@ RESOURCES += resources/BusinessLogic.qrc \
     resources/UserInterface.qrc
 CONFIG += link_pkgconfig
 PKGCONFIG += libalarm
-
 //DEFINES += DEBUG_OUTPUT_TO_FILE
 executable.files = qtmeetings
 executable.path = /usr/bin/
index 4afbc58..2c5d424 100644 (file)
@@ -27,5 +27,5 @@
        <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>
index c38647c..c4b6a64 100644 (file)
@@ -4,6 +4,7 @@
 #include "StartupSettings.h"
 #include "DeviceDataStorage.h"
 #include "DeviceConfigurator.h"
+#include "OperationModeToggler.h"
 
 #include <QtDebug>
 #include <QStringList>
@@ -19,6 +20,16 @@ DeviceManager::DeviceManager( StartupSettings *aSettings )
 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()
@@ -68,83 +79,12 @@ void DeviceManager::changeMode( bool aChange )
                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()
@@ -175,25 +115,13 @@ 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;
 }
 
@@ -241,3 +169,22 @@ void DeviceManager::errorSender( DeviceManager::ErrorCode aErrorCode, const QStr
 
        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
index d318482..2d0dac4 100644 (file)
@@ -9,6 +9,7 @@ class HWKeyListener;
 class StartupSettings;
 class DeviceDataStorage;
 class DeviceConfigurator;
+class OperationModeToggler;
 
 static const int ERROR_BASE=200;
 
@@ -123,6 +124,7 @@ private slots:
         * \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.
@@ -133,14 +135,6 @@ private:
         * \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
@@ -155,6 +149,7 @@ private:
         * \param aHandle indicates if the signals should be connected or not.
         */
        void handleKeyPresses( bool aHandle );
+       void toggleErrorSending( bool aToggle );
 
 private:
        AlarmSender *iAlarmSender;
@@ -162,6 +157,7 @@ private:
        StartupSettings *iSettings;
        DeviceDataStorage *iDataStorage;
        DeviceConfigurator *iConfigurator;
+       OperationModeToggler *iModeToggler;
 
        OperationMode iMode;
        bool iSendErrorMessages;
diff --git a/src/IO/DeviceControl/OperationModeToggler.cpp b/src/IO/DeviceControl/OperationModeToggler.cpp
new file mode 100644 (file)
index 0000000..0f44687
--- /dev/null
@@ -0,0 +1,160 @@
+#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;
+}
diff --git a/src/IO/DeviceControl/OperationModeToggler.h b/src/IO/DeviceControl/OperationModeToggler.h
new file mode 100644 (file)
index 0000000..21413f6
--- /dev/null
@@ -0,0 +1,61 @@
+#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_*/
index 30f6056..08ce4b2 100755 (executable)
@@ -31,6 +31,7 @@ ProgressBar::ProgressBar( const QString &aText, bool aCancellable, QWidget *aPar
                subLayout->addWidget( buttonCancel );
                connect( buttonCancel, SIGNAL( pressed() ), this, SIGNAL( cancel() ) );
        }
+       mainLayout->addLayout( subLayout );
        
        setLayout( mainLayout );
 }