|
1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "mediaclientwseventobserver.h" |
|
17 #include "mediaclientvideotrace.h" |
|
18 |
|
19 CMediaClientWsEventObserver* CMediaClientWsEventObserver::NewL(MMediaClientWsEventObserverCallback& aCallback) |
|
20 { |
|
21 DEBUG_PRINTF("CMediaClientWsEventObserver::NewL +++"); |
|
22 CMediaClientWsEventObserver* self = new (ELeave) CMediaClientWsEventObserver(aCallback); |
|
23 CleanupStack::PushL(self); |
|
24 self->ConstructL(); |
|
25 CleanupStack::Pop(self); |
|
26 DEBUG_PRINTF("CMediaClientWsEventObserver::NewL ---"); |
|
27 return self; |
|
28 } |
|
29 |
|
30 CMediaClientWsEventObserver::CMediaClientWsEventObserver(MMediaClientWsEventObserverCallback& aCallback) : |
|
31 CActive(EPriorityStandard), |
|
32 iCallback(aCallback) |
|
33 { |
|
34 DEBUG_PRINTF("CMediaClientWsEventObserver::CMediaClientWsEventObserver +++"); |
|
35 DEBUG_PRINTF("CMediaClientWsEventObserver::CMediaClientWsEventObserver ---"); |
|
36 } |
|
37 |
|
38 void CMediaClientWsEventObserver::ConstructL() |
|
39 { |
|
40 DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL +++"); |
|
41 |
|
42 DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL RWsSession Connect"); |
|
43 TInt err = iWs.Connect(); |
|
44 if (err != KErrNone) |
|
45 { |
|
46 DEBUG_PRINTF2("CMediaClientWsEventObserver::ConstructL Windows Server unavailable, err %d", err); |
|
47 User::Leave(err); |
|
48 } |
|
49 |
|
50 DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL RWindowGroup Create"); |
|
51 iWindowGroup = RWindowGroup(iWs); |
|
52 User::LeaveIfError(iWindowGroup.Construct((TUint32)this, EFalse)); |
|
53 |
|
54 // Send created window to the background and hide it from the |
|
55 // application switcher |
|
56 iWindowGroup.SetOrdinalPosition( -1, -1000 ); // -1000 = ECoeWinPriorityNeverAtFront |
|
57 |
|
58 DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL RWindowGroup EnableFocusChangeEvents"); |
|
59 User::LeaveIfError(iWindowGroup.EnableFocusChangeEvents()); |
|
60 |
|
61 UpdateFocusWindowGroupId(ETrue); |
|
62 DEBUG_PRINTF3("CMediaClientWsEventObserver::ConstructL Initial WgId %d Error %d", iWgId, iWgIdError); |
|
63 |
|
64 CActiveScheduler::Add(this); |
|
65 |
|
66 // register with window server to receive focus change notifications |
|
67 DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL iWs.EventReady()"); |
|
68 iWs.EventReady(&iStatus); |
|
69 |
|
70 DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL SetActive()"); |
|
71 SetActive(); |
|
72 |
|
73 DEBUG_PRINTF("CMediaClientWsEventObserver::ConstructL ---"); |
|
74 } |
|
75 |
|
76 CMediaClientWsEventObserver::~CMediaClientWsEventObserver() |
|
77 { |
|
78 DEBUG_PRINTF("CMediaClientWsEventObserver::~CMediaClientWsEventObserver +++"); |
|
79 |
|
80 Cancel(); |
|
81 |
|
82 iWindowGroup.Close(); |
|
83 |
|
84 iWs.Close(); |
|
85 |
|
86 DEBUG_PRINTF("CMediaClientWsEventObserver::~CMediaClientWsEventObserver ---"); |
|
87 } |
|
88 |
|
89 TInt CMediaClientWsEventObserver::FocusWindowGroupId(TInt& aFocusGroupId) |
|
90 { |
|
91 DEBUG_PRINTF("CMediaClientWsEventObserver::FocusWindowGroupId +++"); |
|
92 aFocusGroupId = iWgId; |
|
93 DEBUG_PRINTF3("CMediaClientWsEventObserver::FocusWindowGroupId --- WgId %d, Error %d", iWgId, iWgIdError); |
|
94 return iWgIdError; |
|
95 } |
|
96 |
|
97 void CMediaClientWsEventObserver::UpdateFocusWindowGroupId(TBool aConstruction) |
|
98 { |
|
99 DEBUG_PRINTF2("CMediaClientWsEventObserver::UpdateFocusWindowGroupId +++, construction %d", aConstruction); |
|
100 |
|
101 TInt wgId = iWs.GetFocusWindowGroup(); |
|
102 DEBUG_PRINTF2("CMediaClientWsEventObserver::UpdateFocusWindowGroupId id %d ", wgId); |
|
103 |
|
104 // get the thread that owns windowgroup id |
|
105 TThreadId threadId; |
|
106 iWgIdError = iWs.GetWindowGroupClientThreadId(wgId, threadId); |
|
107 if(iWgIdError != KErrNone) |
|
108 { |
|
109 DEBUG_PRINTF2("CMediaClientWsEventObserver::UpdateFocusWindowGroupId --- Get Thread Id error %d", iWgIdError); |
|
110 return; |
|
111 } |
|
112 |
|
113 RThread thread; |
|
114 iWgIdError = thread.Open(threadId); |
|
115 if(iWgIdError != KErrNone) |
|
116 { |
|
117 DEBUG_PRINTF2("CMediaClientWsEventObserver::UpdateFocusWindowGroupId --- Open thread error %d", iWgIdError); |
|
118 return; |
|
119 } |
|
120 |
|
121 TSecureId fgThreadId = thread.SecureId(); |
|
122 thread.Close(); |
|
123 |
|
124 if(iCallback.MmcweoIgnoreProcess(fgThreadId)) |
|
125 { |
|
126 // If ignore returns ETrue during construction the previous value of iWgId does not contain a valid id. It is 0. |
|
127 // This is an error case so set error flag accordingly. |
|
128 if(aConstruction) |
|
129 { |
|
130 iWgIdError = KErrNotSupported; |
|
131 } |
|
132 } |
|
133 else |
|
134 { |
|
135 iWgId = wgId; |
|
136 } |
|
137 |
|
138 DEBUG_PRINTF("CMediaClientWsEventObserver::UpdateFocusWindowGroupId --- "); |
|
139 } |
|
140 |
|
141 void CMediaClientWsEventObserver::RunL() |
|
142 { |
|
143 DEBUG_PRINTF("CMediaClientWsEventObserver::RunL +++"); |
|
144 |
|
145 iWs.GetEvent(iEvent); |
|
146 |
|
147 DEBUG_PRINTF("CMediaClientWsEventObserver::RunL EventReady()"); |
|
148 iWs.EventReady(&iStatus); |
|
149 DEBUG_PRINTF("CMediaClientWsEventObserver::RunL SetActive()"); |
|
150 SetActive(); |
|
151 |
|
152 DEBUG_PRINTF2("CMediaClientWsEventObserver::RunL() Ws event.Type %d", iEvent.Type()); |
|
153 if(iEvent.Type() == EEventFocusGroupChanged) |
|
154 { |
|
155 DEBUG_PRINTF("CMediaClientWsEventObserver::RunL Received EEventFocusGroupChanged"); |
|
156 |
|
157 TInt prevWgId = iWgId; |
|
158 UpdateFocusWindowGroupId(EFalse); |
|
159 if((iWgIdError != KErrNone) || (iWgId != prevWgId)) |
|
160 { |
|
161 iCallback.MmcweoFocusWindowGroupChanged(); |
|
162 } |
|
163 } |
|
164 else |
|
165 { |
|
166 DEBUG_PRINTF("CMediaClientWsEventObserver::RunL Event Ignored"); |
|
167 } |
|
168 |
|
169 DEBUG_PRINTF("CMediaClientWsEventObserver::RunL ---"); |
|
170 } |
|
171 |
|
172 void CMediaClientWsEventObserver::DoCancel() |
|
173 { |
|
174 DEBUG_PRINTF("CMediaClientWsEventObserver::DoCancel +++"); |
|
175 iWs.EventReadyCancel(); |
|
176 DEBUG_PRINTF("CMediaClientWsEventObserver::DoCancel ---"); |
|
177 } |