|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Alert queue and handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <centralrepository.h> |
|
20 #include <DevManInternalCRKeys.h> |
|
21 #include "NSmlAlertQueue.h" |
|
22 #include "nsmldebug.h" |
|
23 // ============================ MEMBER FUNCTIONS =============================== |
|
24 |
|
25 // --------------------------------------------------------- |
|
26 // CNSmlMessageQueue::NewL(MNSmlAlertObserver* aObserver) |
|
27 // Two phase constructor |
|
28 // --------------------------------------------------------- |
|
29 // |
|
30 EXPORT_C CNSmlMessageQueue* CNSmlMessageQueue::NewL( MNSmlAlertObserver* aObserver ) |
|
31 { |
|
32 CNSmlMessageQueue* self = new (ELeave) CNSmlMessageQueue( aObserver ); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(); //self |
|
36 return self; |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------- |
|
40 // CNSmlMessageQueue::~CNSmlMessageQueue() |
|
41 // Destructor |
|
42 // --------------------------------------------------------- |
|
43 EXPORT_C CNSmlMessageQueue::~CNSmlMessageQueue() |
|
44 { |
|
45 DestroyItems(); |
|
46 iAlertQueue.Reset(); |
|
47 iAlertHandler->Cancel(); |
|
48 delete iAlertHandler; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------- |
|
52 // CNSmlMessageQueue::AddMessageL(const TDesC8& aMessage, |
|
53 // TSmlUsageType aType, TSmlProtocolVersion aVersion, TSmlTransportId aBearerType ) |
|
54 // Adds new alert message to alert queue |
|
55 // --------------------------------------------------------- |
|
56 EXPORT_C void CNSmlMessageQueue::AddMessageL( |
|
57 const TDesC8& aMessage, |
|
58 TSmlUsageType aType, |
|
59 TSmlProtocolVersion aVersion, |
|
60 TSmlTransportId aBearerType ) |
|
61 { |
|
62 CNSmlMessageItem* item = CNSmlMessageItem::NewL( aMessage, aType, |
|
63 aVersion, aBearerType ); |
|
64 |
|
65 iAlertQueue.AddLast(*item); |
|
66 |
|
67 if ( iState == ENSmlIdle ) |
|
68 { |
|
69 iAlertHandler->ProcessAlert(); |
|
70 } |
|
71 |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------- |
|
75 // CNSmlMessageQueue::ServerSuspended( TBool aSuspend ) |
|
76 // Sets the suspend state |
|
77 // --------------------------------------------------------- |
|
78 EXPORT_C void CNSmlMessageQueue::ServerSuspended( TBool aSuspend ) |
|
79 { |
|
80 iState = ( aSuspend ) ? ENSmlSuspended : ENSmlIdle; |
|
81 |
|
82 if ( iState == ENSmlSuspended ) |
|
83 { |
|
84 iAlertHandler->Cancel(); |
|
85 } |
|
86 else if ( ! IsEmpty() ) |
|
87 { |
|
88 iAlertHandler->ProcessAlert(); |
|
89 } |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------- |
|
93 // CNSmlMessageQueue::IsEmpty() |
|
94 // |
|
95 // --------------------------------------------------------- |
|
96 EXPORT_C TBool CNSmlMessageQueue::IsEmpty() |
|
97 { |
|
98 return iAlertQueue.IsEmpty(); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------- |
|
102 // CNSmlMessageQueue::CheckMessage( TBool& aMore, TSmlUsageType& aType, |
|
103 // TSmlProtocolVersion& aVersion, TSmlTransportId& aBearerType ) |
|
104 // Checks if there is alert message in queue. Returns also the usage type |
|
105 // and protocol version of the message. |
|
106 // --------------------------------------------------------- |
|
107 void CNSmlMessageQueue::CheckMessage( |
|
108 TBool& aMore, |
|
109 TSmlUsageType& aType, |
|
110 TSmlProtocolVersion& aVersion, |
|
111 TSmlTransportId& aBearerType ) |
|
112 { |
|
113 iState = ENSmlProcessing; |
|
114 |
|
115 iAlertIterator.SetToFirst(); |
|
116 CNSmlMessageItem* item = iAlertIterator; |
|
117 |
|
118 aMore = ( item != NULL ); |
|
119 |
|
120 if ( aMore ) |
|
121 { |
|
122 aType = item->iUsageType; |
|
123 aVersion = item->iProtocol; |
|
124 aBearerType = item->iBearerType; |
|
125 } |
|
126 } |
|
127 |
|
128 |
|
129 // --------------------------------------------------------- |
|
130 // CNSmlMessageQueue::MessageSize() |
|
131 // Returns the size of alert message |
|
132 // --------------------------------------------------------- |
|
133 TInt CNSmlMessageQueue::MessageSize() |
|
134 { |
|
135 iAlertIterator.SetToFirst(); |
|
136 CNSmlMessageItem* item = iAlertIterator; |
|
137 |
|
138 if (item) |
|
139 { |
|
140 return item->Message().Length(); |
|
141 } |
|
142 |
|
143 return 0; |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------- |
|
147 // CNSmlMessageQueue::AlertMessage( TDes8& aMessage ) |
|
148 // Fetches the message from alert queue |
|
149 // --------------------------------------------------------- |
|
150 void CNSmlMessageQueue::AlertMessage( TDes8& aMessage ) |
|
151 { |
|
152 iAlertIterator.SetToFirst(); |
|
153 CNSmlMessageItem* item = iAlertIterator; |
|
154 |
|
155 if (item) |
|
156 { |
|
157 aMessage.Zero(); |
|
158 |
|
159 aMessage.Append( item->Message() ); |
|
160 |
|
161 item->iDlink.Deque(); |
|
162 delete item; |
|
163 item = NULL; |
|
164 } |
|
165 |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------- |
|
169 // CNSmlMessageQueue::CreateJobL( CSmlAlertInfo& aInfo, TBool& aQuit, const TPtrC8& aPackage ) |
|
170 // Creates job from supplied onformation and passes it to observer |
|
171 // --------------------------------------------------------- |
|
172 void CNSmlMessageQueue::CreateJobL( CSmlAlertInfo& aInfo, TBool& aQuit, const TPtrC8& aPackage ) |
|
173 { |
|
174 _DBG_FILE("CNSmlMessageQueue::CreateJobL: begin"); |
|
175 if ( aInfo.JobControl() != CSmlAlertInfo::EDoNotCreateJob ) |
|
176 { |
|
177 CNSmlAlertJobInfo jobInfo; |
|
178 jobInfo.iProfileId = aInfo.Profile(); |
|
179 jobInfo.iType = aInfo.Protocol(); |
|
180 jobInfo.iContentType = new (ELeave) CArrayFixFlat<TNSmlContentTypeInfo>(1); |
|
181 jobInfo.iTransportId = aInfo.Transport(); |
|
182 jobInfo.iPackage.Set( aPackage ); |
|
183 jobInfo.iSessionId = aInfo.SessionId(); |
|
184 TInt SanSupport( KErrNone ); |
|
185 CRepository* centrep = NULL; |
|
186 TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys) ); |
|
187 if( err == KErrNone ) |
|
188 { |
|
189 centrep->Get( KDevManSANUIBitVariation, SanSupport ); |
|
190 } |
|
191 delete centrep; |
|
192 if( SanSupport == 1 ) |
|
193 { |
|
194 jobInfo.iUimode = aInfo.GetUimode(); |
|
195 } |
|
196 DBG_FILE_CODE(jobInfo.iUimode, _S8("CNSmlMessageQueue::CreateJobL() :Uimode result")); |
|
197 |
|
198 TInt count = aInfo.TaskIds().Count(); |
|
199 const RArray<TInt>& tasks = aInfo.TaskIds(); |
|
200 const RArray<TSmlSyncType>& syncTypes = aInfo.TaskSyncTypes(); |
|
201 |
|
202 TNSmlContentTypeInfo info; |
|
203 |
|
204 for (TInt index = 0; index < count; index++) |
|
205 { |
|
206 info.iTaskId = tasks[index]; |
|
207 info.iSyncType = syncTypes[index]; |
|
208 jobInfo.iContentType->AppendL(info); |
|
209 } |
|
210 iAlertObserver->CreateJobL( jobInfo ); |
|
211 } |
|
212 |
|
213 //Check next alert message |
|
214 iAlertIterator.SetToFirst(); |
|
215 CNSmlMessageItem* item = iAlertIterator; |
|
216 |
|
217 aQuit = (item == NULL); |
|
218 |
|
219 if ( iState == ENSmlSuspended ) |
|
220 { |
|
221 aQuit = ETrue; |
|
222 } |
|
223 else |
|
224 { |
|
225 iState = ENSmlIdle; |
|
226 } |
|
227 _DBG_FILE("CNSmlMessageQueue::CreateJobL: end!"); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CNSmlMessageQueue::DoDisconnect() |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void CNSmlMessageQueue::DoDisconnect() |
|
235 { |
|
236 TRAP_IGNORE( iAlertObserver->DoDisconnectL() ); |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CNSmlMessageQueue::DestroyItems() |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CNSmlMessageQueue::DestroyItems() |
|
244 { |
|
245 CNSmlMessageItem* item; |
|
246 |
|
247 iAlertIterator.SetToFirst(); |
|
248 |
|
249 while ( ( item = iAlertIterator++ ) != NULL ) |
|
250 { |
|
251 item->iDlink.Deque(); |
|
252 delete item; |
|
253 item = NULL; |
|
254 }; |
|
255 |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------- |
|
259 // CNSmlMessageQueue::CNSmlMessageQueue( MNSmlAlertObserver* aObserver ) |
|
260 // Constructor |
|
261 // --------------------------------------------------------- |
|
262 EXPORT_C CNSmlMessageQueue::CNSmlMessageQueue( MNSmlAlertObserver* aObserver ) |
|
263 : iAlertQueue( CNSmlMessageItem::iOffset ),iAlertIterator( iAlertQueue ), iAlertObserver( aObserver ) |
|
264 { |
|
265 iState = ENSmlIdle; |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------- |
|
269 // CNSmlMessageQueue::ConstructL() |
|
270 // Second phase constructor |
|
271 // --------------------------------------------------------- |
|
272 void CNSmlMessageQueue::ConstructL() |
|
273 { |
|
274 iAlertHandler = CNSmlAlertHandler::NewL( this ); |
|
275 } |