|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <e32debug.h> |
|
20 #include <AknCapServerDefs.h> |
|
21 #include <apgtask.h> |
|
22 #include "AutolockGripStatusObserver.h" |
|
23 |
|
24 |
|
25 EXPORT_C CAutolockGripStatusObserver* CAutolockGripStatusObserver::NewL( MAutolockGripStatusObserver* aObserver, RWsSession& aSession ) |
|
26 { |
|
27 CAutolockGripStatusObserver* self = new (ELeave) CAutolockGripStatusObserver( aSession ); |
|
28 CleanupStack::PushL( self ); |
|
29 self->ConstructL( aObserver ); |
|
30 CleanupStack::Pop( self ); |
|
31 return self; |
|
32 } |
|
33 |
|
34 void CAutolockGripStatusObserver::ConstructL( MAutolockGripStatusObserver* aObserver ) |
|
35 { |
|
36 #if defined(_DEBUG) |
|
37 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::ConstructL") ); |
|
38 #endif |
|
39 TInt err = iGripStatus.Attach( KPSUidHWRM, KHWRMGripStatus ); |
|
40 if ( err ) |
|
41 { |
|
42 #if defined(_DEBUG) |
|
43 RDebug::Print(_L("(AUTOLOCK)ERROR: Attach failed, err %d"), err ); |
|
44 #endif |
|
45 } |
|
46 iObserver = aObserver; |
|
47 CActiveScheduler::Add( this ); |
|
48 iGripStatus.Subscribe( iStatus ); |
|
49 SetActive(); |
|
50 } |
|
51 |
|
52 CAutolockGripStatusObserver::CAutolockGripStatusObserver( RWsSession& aSession ) : CActive( EPriorityIdle ), iSession( aSession ) |
|
53 { |
|
54 } |
|
55 |
|
56 CAutolockGripStatusObserver::~CAutolockGripStatusObserver() |
|
57 { |
|
58 #if defined(_DEBUG) |
|
59 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::~CAutolockGripStatusObserver") ); |
|
60 #endif |
|
61 Cancel(); |
|
62 iGripStatus.Close(); |
|
63 } |
|
64 |
|
65 void CAutolockGripStatusObserver::DoCancel() |
|
66 { |
|
67 #if defined(_DEBUG) |
|
68 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::DoCancel") ); |
|
69 #endif |
|
70 iGripStatus.Cancel(); |
|
71 } |
|
72 |
|
73 void CAutolockGripStatusObserver::RunL() |
|
74 { |
|
75 #if defined(_DEBUG) |
|
76 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::RunL") ); |
|
77 #endif |
|
78 iGripStatus.Subscribe( iStatus ); |
|
79 SetActive(); |
|
80 |
|
81 TInt gripStatus; |
|
82 TInt err = iGripStatus.Get( gripStatus ); |
|
83 if( !err ) |
|
84 { |
|
85 GripStatusChangedL( gripStatus ); |
|
86 } |
|
87 } |
|
88 |
|
89 void CAutolockGripStatusObserver::GripStatusChangedL( TInt aGripStatus ) |
|
90 { |
|
91 #if defined(_DEBUG) |
|
92 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL")); |
|
93 #endif |
|
94 if( aGripStatus == EPSHWRMGripOpen ) |
|
95 { |
|
96 #if defined(_DEBUG) |
|
97 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL => Grip opened")); |
|
98 #endif |
|
99 if( !iObserver->DeviceLockQueryStatus() && iObserver->DeviceLockStatus() ) |
|
100 { |
|
101 #if defined(_DEBUG) |
|
102 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL => send command")); |
|
103 #endif |
|
104 //Grip opened |
|
105 TApaTaskList tasklist( iSession ); |
|
106 TApaTask capserver = tasklist.FindApp( KAknCapServerUid ); |
|
107 if( capserver.Exists() ) |
|
108 { |
|
109 TKeyEvent key; |
|
110 key.iCode = EKeyDevice0; |
|
111 key.iModifiers = 0; |
|
112 key.iRepeats = 0; |
|
113 key.iScanCode = EStdKeyDevice0; |
|
114 capserver.SendKey( key ); |
|
115 } |
|
116 |
|
117 } |
|
118 } |
|
119 else |
|
120 { |
|
121 #if defined(_DEBUG) |
|
122 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL => Grip closed")); |
|
123 #endif |
|
124 //Grip closed |
|
125 if( iObserver->DeviceLockQueryStatus() ) |
|
126 { |
|
127 #if defined(_DEBUG) |
|
128 RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL => send key event")); |
|
129 #endif |
|
130 //the device lock query is on top |
|
131 //generate cancel key event |
|
132 TRawEvent rawEvent; |
|
133 rawEvent.Set( TRawEvent::EKeyDown, KCancelKeyCode ); |
|
134 iSession.SimulateRawEvent( rawEvent ); |
|
135 } |
|
136 } |
|
137 } |
|
138 |
|
139 // End of File |