javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/swtflipwatch.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - initial implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 #include <org_eclipse_swt_internal_qt_OS.h>
       
    13 #include <hwrmdomainpskeys.h>
       
    14 
       
    15 #include "swtflipwatch.h"
       
    16 #include "swtapplication.h"
       
    17 #include "swts60.h"
       
    18 
       
    19 namespace Java { namespace eSWT {
       
    20 
       
    21 // Priority of the flip watch CActive. If for some reason the flip watch
       
    22 // CActive gets blocked, the watch timer should wait also. Therefore the
       
    23 // priority of the watch timer should be lower than this.
       
    24 const TInt KSwtFlipWatchPriority = 0;
       
    25 
       
    26 // Using a short delay on the flip watch will avoid ui unresponsiveness when
       
    27 // fast swaping the flip back and forth.
       
    28 const TInt KSwtFlipWatchTimeout = 250000;
       
    29 
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CSwtFlipWatch::NewL
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CSwtFlipWatch* CSwtFlipWatch::NewL()
       
    39 {
       
    40     CSwtFlipWatch* self = new(ELeave) CSwtFlipWatch();
       
    41     CleanupStack::PushL(self);
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop(self);
       
    44     return self;
       
    45 }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CSwtFlipWatch::~CSwtFlipWatch
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CSwtFlipWatch::~CSwtFlipWatch()
       
    52 {
       
    53     Cancel();
       
    54     iProperty.Close();
       
    55 
       
    56     if (iTimer)
       
    57     {
       
    58         iTimer->Cancel();
       
    59         delete iTimer;
       
    60     }
       
    61 }
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CSwtFlipWatch::CSwtFlipWatch
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CSwtFlipWatch::CSwtFlipWatch()
       
    69         : CActive(KSwtFlipWatchPriority)
       
    70 {
       
    71   
       
    72 }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CSwtFlipWatch::ConstructL
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CSwtFlipWatch::ConstructL()
       
    79 {
       
    80     isInitializationState = ETrue;
       
    81     User::LeaveIfError(iProperty.Attach(KPSUidHWRM, KHWRMFlipStatus));
       
    82     iTimer = CSwtFlipWatchTimer::NewL(this);
       
    83     CActiveScheduler::Add(this);
       
    84     RunL();
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CSwtFlipWatch::DoCancel
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CSwtFlipWatch::DoCancel()
       
    92 {
       
    93     iProperty.Cancel();
       
    94 }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CSwtFlipWatch::RunL
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CSwtFlipWatch::RunL()
       
   101 {
       
   102     iTimer->Cancel();
       
   103     iProperty.Subscribe(iStatus);
       
   104     // For performance reasons while in fast sequence of swaps the observers
       
   105     // will get screen deactivated event only once.
       
   106     if (!iFlipChanging)
       
   107         {
       
   108         SymbianUtils::eventFilter( swtApp, -1, org_eclipse_swt_internal_qt_OS_QSWTEVENT_SCREENDEACTIVATED);
       
   109         }
       
   110     iFlipChanging = ETrue;
       
   111     iTimer->SetTimer(KSwtFlipWatchTimeout);
       
   112     SetActive();
       
   113 }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CSwtFlipWatch::HandleTimeoutL
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CSwtFlipWatch::HandleTimeoutL()
       
   120 {
       
   121     TInt flipStatus = 0;
       
   122     TInt err = iProperty.Get(flipStatus);
       
   123     if ( !isInitializationState && err == KErrNone)
       
   124         {
       
   125         iFlipChanging = EFalse;
       
   126         // Report flip change
       
   127         if (flipStatus ==  EPSHWRMFlipClosed)
       
   128             {
       
   129             SymbianUtils::eventFilter( swtApp, -1, org_eclipse_swt_internal_qt_OS_QSWTEVENT_MOBILEDEVICECLOSED);
       
   130             } else{
       
   131             SymbianUtils::eventFilter( swtApp, -1, org_eclipse_swt_internal_qt_OS_QSWTEVENT_MOBILEDEVICEOPENED);
       
   132             }
       
   133         // For performance reasons while in fast sequence of swaps the observers
       
   134         // will get screen deactivated event only once.
       
   135         // ASSUMPTION: The screen changes if the flip changes.
       
   136         SymbianUtils::eventFilter( swtApp, -1, org_eclipse_swt_internal_qt_OS_QSWTEVENT_SCREENACTIVATED);
       
   137         }
       
   138     isInitializationState = EFalse;
       
   139 }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CSwtFlipWatchTimer::NewL
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 CSwtFlipWatchTimer* CSwtFlipWatchTimer::NewL(MSwtFlipWatchTimerHandler* aHandler)
       
   146 {
       
   147     CSwtFlipWatchTimer* self = new(ELeave) CSwtFlipWatchTimer(aHandler);
       
   148     CleanupStack::PushL(self);
       
   149     self->ConstructL();
       
   150     CleanupStack::Pop(self);
       
   151     return self;
       
   152 }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CSwtFlipWatchTimer::CSwtFlipWatchTimer
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 CSwtFlipWatchTimer::CSwtFlipWatchTimer(MSwtFlipWatchTimerHandler* aHandler)
       
   159         : CActive(KSwtFlipWatchPriority - 1)
       
   160         , iHandler(aHandler)
       
   161 {
       
   162     ASSERT(iHandler);
       
   163 }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CSwtFlipWatchTimer::ConstructL
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void CSwtFlipWatchTimer::ConstructL()
       
   170 {
       
   171     TInt err = iTimer.CreateLocal();
       
   172     User::LeaveIfError(err);
       
   173     CActiveScheduler::Add(this);
       
   174 }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CSwtFlipWatchTimer::~CSwtFlipWatchTimer
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 CSwtFlipWatchTimer::~CSwtFlipWatchTimer()
       
   181 {
       
   182     Cancel();
       
   183     iTimer.Close();
       
   184 }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CSwtFlipWatchTimer::RunL
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CSwtFlipWatchTimer::RunL()
       
   191 {
       
   192     iHandler->HandleTimeoutL();
       
   193 }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CSwtFlipWatchTimer::DoCancel
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CSwtFlipWatchTimer::DoCancel()
       
   200 {
       
   201     iTimer.Cancel();
       
   202 }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CSwtFlipWatchTimer::SetTimer
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CSwtFlipWatchTimer::SetTimer(TTimeIntervalMicroSeconds32 aDelay)
       
   209 {
       
   210     Cancel();
       
   211     iTimer.After(iStatus, aDelay);
       
   212     SetActive();
       
   213 }
       
   214 
       
   215 }}