1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/src/Client/Video/mediaclientwseventobserver.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,177 @@
1.4 +// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "mediaclientwseventobserver.h"
1.20 +#include "mediaclientvideotrace.h"
1.21 +
1.22 +CMediaClientWsEventObserver* CMediaClientWsEventObserver::NewL(MMediaClientWsEventObserverCallback& aCallback)
1.23 + {
1.24 + DEBUG_PRINTF("CMediaClientWsEventObserver::NewL +++");
1.25 + CMediaClientWsEventObserver* self = new (ELeave) CMediaClientWsEventObserver(aCallback);
1.26 + CleanupStack::PushL(self);
1.27 + self->ConstructL();
1.28 + CleanupStack::Pop(self);
1.29 + DEBUG_PRINTF("CMediaClientWsEventObserver::NewL ---");
1.30 + return self;
1.31 + }
1.32 +
1.33 +CMediaClientWsEventObserver::CMediaClientWsEventObserver(MMediaClientWsEventObserverCallback& aCallback) :
1.34 +CActive(EPriorityStandard),
1.35 +iCallback(aCallback)
1.36 + {
1.37 + DEBUG_PRINTF("CMediaClientWsEventObserver::CMediaClientWsEventObserver +++");
1.38 + DEBUG_PRINTF("CMediaClientWsEventObserver::CMediaClientWsEventObserver ---");
1.39 + }
1.40 +
1.41 +void CMediaClientWsEventObserver::ConstructL()
1.42 + {
1.43 + DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL +++");
1.44 +
1.45 + DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL RWsSession Connect");
1.46 + TInt err = iWs.Connect();
1.47 + if (err != KErrNone)
1.48 + {
1.49 + DEBUG_PRINTF2("CMediaClientWsEventObserver::ConstructL Windows Server unavailable, err %d", err);
1.50 + User::Leave(err);
1.51 + }
1.52 +
1.53 + DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL RWindowGroup Create");
1.54 + iWindowGroup = RWindowGroup(iWs);
1.55 + User::LeaveIfError(iWindowGroup.Construct((TUint32)this, EFalse));
1.56 +
1.57 + // Send created window to the background and hide it from the
1.58 + // application switcher
1.59 + iWindowGroup.SetOrdinalPosition( -1, -1000 ); // -1000 = ECoeWinPriorityNeverAtFront
1.60 +
1.61 + DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL RWindowGroup EnableFocusChangeEvents");
1.62 + User::LeaveIfError(iWindowGroup.EnableFocusChangeEvents());
1.63 +
1.64 + UpdateFocusWindowGroupId(ETrue);
1.65 + DEBUG_PRINTF3("CMediaClientWsEventObserver::ConstructL Initial WgId %d Error %d", iWgId, iWgIdError);
1.66 +
1.67 + CActiveScheduler::Add(this);
1.68 +
1.69 + // register with window server to receive focus change notifications
1.70 + DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL iWs.EventReady()");
1.71 + iWs.EventReady(&iStatus);
1.72 +
1.73 + DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL SetActive()");
1.74 + SetActive();
1.75 +
1.76 + DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL ---");
1.77 + }
1.78 +
1.79 +CMediaClientWsEventObserver::~CMediaClientWsEventObserver()
1.80 + {
1.81 + DEBUG_PRINTF("CMediaClientWsEventObserver::~CMediaClientWsEventObserver +++");
1.82 +
1.83 + Cancel();
1.84 +
1.85 + iWindowGroup.Close();
1.86 +
1.87 + iWs.Close();
1.88 +
1.89 + DEBUG_PRINTF("CMediaClientWsEventObserver::~CMediaClientWsEventObserver ---");
1.90 + }
1.91 +
1.92 +TInt CMediaClientWsEventObserver::FocusWindowGroupId(TInt& aFocusGroupId)
1.93 + {
1.94 + DEBUG_PRINTF("CMediaClientWsEventObserver::FocusWindowGroupId +++");
1.95 + aFocusGroupId = iWgId;
1.96 + DEBUG_PRINTF3("CMediaClientWsEventObserver::FocusWindowGroupId --- WgId %d, Error %d", iWgId, iWgIdError);
1.97 + return iWgIdError;
1.98 + }
1.99 +
1.100 +void CMediaClientWsEventObserver::UpdateFocusWindowGroupId(TBool aConstruction)
1.101 + {
1.102 + DEBUG_PRINTF2("CMediaClientWsEventObserver::UpdateFocusWindowGroupId +++, construction %d", aConstruction);
1.103 +
1.104 + TInt wgId = iWs.GetFocusWindowGroup();
1.105 + DEBUG_PRINTF2("CMediaClientWsEventObserver::UpdateFocusWindowGroupId id %d ", wgId);
1.106 +
1.107 + // get the thread that owns windowgroup id
1.108 + TThreadId threadId;
1.109 + iWgIdError = iWs.GetWindowGroupClientThreadId(wgId, threadId);
1.110 + if(iWgIdError != KErrNone)
1.111 + {
1.112 + DEBUG_PRINTF2("CMediaClientWsEventObserver::UpdateFocusWindowGroupId --- Get Thread Id error %d", iWgIdError);
1.113 + return;
1.114 + }
1.115 +
1.116 + RThread thread;
1.117 + iWgIdError = thread.Open(threadId);
1.118 + if(iWgIdError != KErrNone)
1.119 + {
1.120 + DEBUG_PRINTF2("CMediaClientWsEventObserver::UpdateFocusWindowGroupId --- Open thread error %d", iWgIdError);
1.121 + return;
1.122 + }
1.123 +
1.124 + TSecureId fgThreadId = thread.SecureId();
1.125 + thread.Close();
1.126 +
1.127 + if(iCallback.MmcweoIgnoreProcess(fgThreadId))
1.128 + {
1.129 + // If ignore returns ETrue during construction the previous value of iWgId does not contain a valid id. It is 0.
1.130 + // This is an error case so set error flag accordingly.
1.131 + if(aConstruction)
1.132 + {
1.133 + iWgIdError = KErrNotSupported;
1.134 + }
1.135 + }
1.136 + else
1.137 + {
1.138 + iWgId = wgId;
1.139 + }
1.140 +
1.141 + DEBUG_PRINTF("CMediaClientWsEventObserver::UpdateFocusWindowGroupId --- ");
1.142 + }
1.143 +
1.144 +void CMediaClientWsEventObserver::RunL()
1.145 + {
1.146 + DEBUG_PRINTF("CMediaClientWsEventObserver::RunL +++");
1.147 +
1.148 + iWs.GetEvent(iEvent);
1.149 +
1.150 + DEBUG_PRINTF("CMediaClientWsEventObserver::RunL EventReady()");
1.151 + iWs.EventReady(&iStatus);
1.152 + DEBUG_PRINTF("CMediaClientWsEventObserver::RunL SetActive()");
1.153 + SetActive();
1.154 +
1.155 + DEBUG_PRINTF2("CMediaClientWsEventObserver::RunL() Ws event.Type %d", iEvent.Type());
1.156 + if(iEvent.Type() == EEventFocusGroupChanged)
1.157 + {
1.158 + DEBUG_PRINTF("CMediaClientWsEventObserver::RunL Received EEventFocusGroupChanged");
1.159 +
1.160 + TInt prevWgId = iWgId;
1.161 + UpdateFocusWindowGroupId(EFalse);
1.162 + if((iWgIdError != KErrNone) || (iWgId != prevWgId))
1.163 + {
1.164 + iCallback.MmcweoFocusWindowGroupChanged();
1.165 + }
1.166 + }
1.167 + else
1.168 + {
1.169 + DEBUG_PRINTF("CMediaClientWsEventObserver::RunL Event Ignored");
1.170 + }
1.171 +
1.172 + DEBUG_PRINTF("CMediaClientWsEventObserver::RunL ---");
1.173 + }
1.174 +
1.175 +void CMediaClientWsEventObserver::DoCancel()
1.176 + {
1.177 + DEBUG_PRINTF("CMediaClientWsEventObserver::DoCancel +++");
1.178 + iWs.EventReadyCancel();
1.179 + DEBUG_PRINTF("CMediaClientWsEventObserver::DoCancel ---");
1.180 + }