|
1 /* |
|
2 * Copyright (c) 2004 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: Publish & Subscribe property change observer implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "MIMPSSystemNotifierObserver.h" |
|
22 #include "CIMPSSystemNotifierPubSub.h" |
|
23 #include "CIMPSPropertyObserver.h" |
|
24 #include "IMPSSystemNotifyDefs.h" |
|
25 |
|
26 #include <sacls.h> |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CIMPSSystemNotifierPubSub::CIMPSSystemNotifierPubSub |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CIMPSSystemNotifierPubSub::CIMPSSystemNotifierPubSub( |
|
37 MIMPSSystemNotifierObserver& aObserver, |
|
38 const TUid aKey |
|
39 ) |
|
40 : iObserver( aObserver ), |
|
41 iKey( aKey ) |
|
42 { |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CIMPSSystemNotifierPubSub::ConstructL |
|
47 // Symbian 2nd phase constructor can leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CIMPSSystemNotifierPubSub::ConstructL() |
|
51 { |
|
52 iPropertyObserver = CIMPSPropertyObserver::NewL( *this ); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CIMPSSystemNotifierPubSub::NewL |
|
57 // Two-phased constructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CIMPSSystemNotifierPubSub* CIMPSSystemNotifierPubSub::NewL( |
|
61 MIMPSSystemNotifierObserver& aObserver, |
|
62 TUid aKey ) |
|
63 { |
|
64 CIMPSSystemNotifierPubSub* self = |
|
65 new( ELeave ) CIMPSSystemNotifierPubSub( aObserver, aKey ); |
|
66 |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 CleanupStack::Pop(); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // Destructor |
|
76 CIMPSSystemNotifierPubSub::~CIMPSSystemNotifierPubSub() |
|
77 { |
|
78 delete iPropertyObserver; |
|
79 } |
|
80 |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CIMPSSystemNotifierPubSub::Subscribe |
|
84 // (other items were commented in a header). |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 TInt CIMPSSystemNotifierPubSub::Subscribe() |
|
88 { |
|
89 TInt err( KErrNone ); |
|
90 TRAP( err, |
|
91 iPropertyObserver->ObservePropertyChangeL( KUidSystemCategory, iKey.iUid ) ); |
|
92 return err; |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CIMPSSystemNotifierPubSub::UnSubscribe |
|
97 // (other items were commented in a header). |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void CIMPSSystemNotifierPubSub::UnSubscribe() |
|
101 { |
|
102 iPropertyObserver->CancelObserve(); |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CIMPSSystemNotifierPubSub::GetIntKey |
|
107 // (other items were commented in a header). |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 TInt CIMPSSystemNotifierPubSub::GetIntKey( TInt& aValue ) |
|
111 { |
|
112 TInt err = RProperty::Get( KUidSystemCategory, iKey.iUid, aValue ); |
|
113 return err; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CIMPSSystemNotifierPubSub::HandlePropertyNotificationEventL( TUid /*aCategory*/, TUint /*aKey*/ ) |
|
118 // |
|
119 // (other items were commented in a header). |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void CIMPSSystemNotifierPubSub::HandlePropertyNotificationEventL( TUid /*aCategory*/, TUint /*aKey*/ ) |
|
123 { |
|
124 TInt value( KErrNone ); |
|
125 User::LeaveIfError( RProperty::Get( KUidSystemCategory, iKey.iUid, value ) ); |
|
126 iObserver.HandleSystemNotifierEventL( iKey, value ); |
|
127 } |
|
128 |