1 /* |
|
2 * Copyright (c) 2009- 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: Listens for changes in one CommsDat table through CenRep. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <commsdat.h> |
|
19 #include <centralrepository.h> |
|
20 #include <cmcommonconstants.h> |
|
21 |
|
22 #include "cmcommsdatnotifier.h" |
|
23 #include "cmmanagerimpl.h" |
|
24 |
|
25 // Repository for CommsDat |
|
26 const TUid KCDCommsRepositoryId = { 0xCCCCCC00 }; |
|
27 |
|
28 CCmCommsDatNotifier* CCmCommsDatNotifier::NewL( TUint32 aTableId ) |
|
29 { |
|
30 CCmCommsDatNotifier* self = CCmCommsDatNotifier::NewLC( aTableId ); |
|
31 CleanupStack::Pop( self ); |
|
32 return self; |
|
33 } |
|
34 |
|
35 CCmCommsDatNotifier* CCmCommsDatNotifier::NewLC( TUint32 aTableId ) |
|
36 { |
|
37 CCmCommsDatNotifier* self = new( ELeave ) CCmCommsDatNotifier( aTableId ); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 return self; |
|
41 } |
|
42 |
|
43 CCmCommsDatNotifier::~CCmCommsDatNotifier() |
|
44 { |
|
45 // Cancel outstanding request, if exists |
|
46 if( iWatcher ) |
|
47 { |
|
48 Cancel(); |
|
49 } |
|
50 delete iRepository; |
|
51 |
|
52 DeleteCallBackArray(); |
|
53 |
|
54 iWatcher = NULL; |
|
55 } |
|
56 |
|
57 void CCmCommsDatNotifier::DeleteCallBackArray() |
|
58 { |
|
59 TInt count = iCallBackArray->Count(); |
|
60 TInt index( 0 ); |
|
61 while( count > 0 ) |
|
62 { |
|
63 iCallBackArray->Delete( index ); |
|
64 iCallBackArray->Compress(); |
|
65 |
|
66 count = iCallBackArray->Count(); |
|
67 } |
|
68 |
|
69 delete iCallBackArray; |
|
70 iCallBackArray = NULL; |
|
71 } |
|
72 |
|
73 CCmCommsDatNotifier::CCmCommsDatNotifier( TUint32 aTableId ) |
|
74 : |
|
75 CActive( EPriorityStandard ), |
|
76 iTableId( aTableId ), |
|
77 iWatcher( NULL ) |
|
78 { |
|
79 iRepository = NULL; |
|
80 } |
|
81 |
|
82 void CCmCommsDatNotifier::ConstructL() |
|
83 { |
|
84 iCallBackArray = new (ELeave) CCmCallBackArray( KCmArrayBigGranularity ); |
|
85 |
|
86 iRepository = CRepository::NewL( KCDCommsRepositoryId ); |
|
87 CActiveScheduler::Add( this ); |
|
88 } |
|
89 |
|
90 void CCmCommsDatNotifier::WatcherRegisterL( MCmCommsDatWatcher* aWatcher ) |
|
91 { |
|
92 if( !aWatcher ) |
|
93 { |
|
94 return; |
|
95 } |
|
96 |
|
97 if( !iWatcher ) |
|
98 { |
|
99 TInt err( RequestNotifications() ); |
|
100 User::LeaveIfError( err ); |
|
101 } |
|
102 |
|
103 iCallBackArray->AppendL( aWatcher ); |
|
104 |
|
105 iWatcher = aWatcher; |
|
106 } |
|
107 |
|
108 void CCmCommsDatNotifier::WatcherUnRegister( ) |
|
109 { |
|
110 TInt index = iCallBackArray->Count(); |
|
111 index --; |
|
112 |
|
113 if (index >= 0) |
|
114 { |
|
115 iCallBackArray->Delete( index ); |
|
116 iCallBackArray->Compress(); |
|
117 } |
|
118 |
|
119 index = iCallBackArray->Count(); |
|
120 index --; |
|
121 if (index >= 0) |
|
122 { |
|
123 iWatcher = (*iCallBackArray)[index]; |
|
124 } |
|
125 else |
|
126 { |
|
127 iWatcher = NULL; |
|
128 } |
|
129 |
|
130 if( !iWatcher ) |
|
131 { |
|
132 Cancel(); |
|
133 } |
|
134 } |
|
135 |
|
136 TInt CCmCommsDatNotifier::RequestNotifications() |
|
137 { |
|
138 TInt err = iRepository->NotifyRequest( iTableId, KCDMaskShowRecordType, iStatus ); |
|
139 |
|
140 if ( KErrNone == err ) |
|
141 { |
|
142 SetActive(); |
|
143 } |
|
144 |
|
145 return err; |
|
146 } |
|
147 |
|
148 void CCmCommsDatNotifier::DoCancel() |
|
149 { |
|
150 iRepository->NotifyCancel( iTableId, KCDMaskShowRecordType ); |
|
151 } |
|
152 |
|
153 void CCmCommsDatNotifier::RunL() |
|
154 { |
|
155 if ( iStatus.Int() < KErrNone ) |
|
156 { |
|
157 return; |
|
158 } |
|
159 |
|
160 if ( iWatcher ) |
|
161 { |
|
162 iWatcher->CommsDatChangesL(); |
|
163 |
|
164 RequestNotifications(); |
|
165 } |
|
166 } |
|
167 |
|
168 // End-of-file |
|