|
1 /* |
|
2 * Copyright (c) 2007 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: Listen to CenRep and PubSub Keys |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <btserversdkcrkeys.h> |
|
21 #include <btengprivatecrkeys.h> |
|
22 #include <bt_subscribe.h> |
|
23 #include "BTUIKeyWatcher.h" |
|
24 #include "BTUIMainView.h" |
|
25 #include "debug.h" |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // NewL |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CBTUIKeyWatcher* CBTUIKeyWatcher::NewL( TAny* aCaller, TInt aServiceID ) |
|
34 { |
|
35 CBTUIKeyWatcher* self = new( ELeave ) CBTUIKeyWatcher( aCaller ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL( aServiceID ); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // C++ default constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CBTUIKeyWatcher::CBTUIKeyWatcher( TAny* aCaller ) |
|
47 : iCaller( aCaller ) |
|
48 { |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // Symbian 2nd-phase constructor |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 void CBTUIKeyWatcher::ConstructL( TInt aServiceID ) |
|
56 { |
|
57 TRACE_FUNC_ENTRY |
|
58 |
|
59 if( aServiceID & KBTUIPHYCountWatcher ) |
|
60 { |
|
61 TInt err = iPHYCountKey.Attach( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothPHYCount ); |
|
62 if( !err ) |
|
63 { |
|
64 iPHYCountWatcher = CBTUIActive::NewL( this, KBTUIPHYCountWatcher, CActive::EPriorityStandard ); |
|
65 if( iPHYCountWatcher != NULL ) |
|
66 { |
|
67 iPHYCountKey.Subscribe( iPHYCountWatcher->RequestStatus() ); |
|
68 iPHYCountWatcher->GoActive(); |
|
69 } |
|
70 else |
|
71 { |
|
72 TRACE_INFO(_L("new iPHYCountWatcher failed")); |
|
73 } |
|
74 } |
|
75 else |
|
76 { |
|
77 TRACE_INFO((_L("Attach failed %d"), err)) |
|
78 } |
|
79 } |
|
80 |
|
81 TRACE_FUNC_EXIT |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // Destructor |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 CBTUIKeyWatcher::~CBTUIKeyWatcher() |
|
89 { |
|
90 TRACE_FUNC_ENTRY |
|
91 |
|
92 if( iPHYCountKey.Handle() ) |
|
93 { |
|
94 iPHYCountKey.Cancel(); |
|
95 } |
|
96 if( iPHYCountWatcher ) |
|
97 { |
|
98 delete iPHYCountWatcher; |
|
99 iPHYCountWatcher = NULL; |
|
100 } |
|
101 iPHYCountKey.Close(); |
|
102 |
|
103 TRACE_FUNC_EXIT |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // From class MBTEngActiveObserver. |
|
109 // Processes a changed key value. |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CBTUIKeyWatcher::RequestCompletedL( CBTUIActive* aActive, TInt aId, TInt /*aStatus*/ ) |
|
113 { |
|
114 switch( aId ) |
|
115 { |
|
116 case KBTUIPHYCountWatcher: |
|
117 iPHYCountKey.Subscribe( aActive->RequestStatus() ); |
|
118 aActive->GoActive(); |
|
119 static_cast<CBTUIMainView*>(iCaller)->UpdateParentView(); |
|
120 break; |
|
121 default: |
|
122 TRACE_INFO((_L("wrong key notification! id=%d"), aId)) |
|
123 break; |
|
124 } |
|
125 TRACE_FUNC_EXIT |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // From class MBTEngActiveObserver. |
|
130 // Handles a leave in RunL/RequestCompletedL by checking that all |
|
131 // the subscriptions are active. |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 void CBTUIKeyWatcher::HandleError( CBTUIActive* aActive, TInt aId, TInt aError ) |
|
135 { |
|
136 TRACE_INFO((_L("status = %d"), aError)) |
|
137 (void) aError; |
|
138 if( !aActive->IsActive() ) |
|
139 { |
|
140 switch( aId ) |
|
141 { |
|
142 case KBTUIPHYCountWatcher: |
|
143 iPHYCountKey.Subscribe( aActive->RequestStatus() ); |
|
144 aActive->GoActive(); |
|
145 break; |
|
146 default: |
|
147 TRACE_INFO((_L("wrong key notification! id=%d"), aId)) |
|
148 break; |
|
149 } |
|
150 } |
|
151 } |