29
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 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: The implementation of LCD service
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <locodserviceplugin.h>
|
|
20 |
|
|
21 |
#include "locodservice.h"
|
|
22 |
#include "debug.h"
|
|
23 |
|
|
24 |
// ======== MEMBER FUNCTIONS ========
|
|
25 |
|
|
26 |
// ---------------------------------------------------------------------------
|
|
27 |
// Creates a service object based on the service plug in objects
|
|
28 |
// ---------------------------------------------------------------------------
|
|
29 |
//
|
|
30 |
CLocodService* CLocodService::NewL(CLocodServicePlugin& aPlugin)
|
|
31 |
{
|
|
32 |
CLocodService* self = new (ELeave) CLocodService(aPlugin);
|
|
33 |
CleanupStack::PushL(self);
|
|
34 |
self->ConstructL();
|
|
35 |
CleanupStack::Pop(self);
|
|
36 |
return self;
|
|
37 |
}
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
// C++ destructor
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
CLocodService::~CLocodService()
|
|
44 |
{
|
|
45 |
delete iPlugin;
|
|
46 |
iRequests.Close();
|
|
47 |
TRACE_FUNC
|
|
48 |
}
|
|
49 |
|
|
50 |
// ---------------------------------------------------------------------------
|
|
51 |
// return the plugin instance
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
CLocodServicePlugin& CLocodService::Plugin()
|
|
55 |
{
|
|
56 |
return *iPlugin;
|
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
// ---------------------------------------------------------------------------
|
|
61 |
// A request is sent to service plug in to manage their services
|
|
62 |
// ---------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
TInt CLocodService::ManageService(TLocodBearer aBearer, TBool aStatus)
|
|
65 |
{
|
|
66 |
TRACE_INFO((_L("[Srvc %d] [SrvcState 0x%04x]"), iPlugin->ImplementationUid().iUid, iServiceStatus))
|
|
67 |
|
|
68 |
// if there is an outstanding request which has the same bearer,
|
|
69 |
// remove all later enqueued request, and
|
|
70 |
// enqueue this request if the bearer status is different from the ongoing one.
|
|
71 |
TInt count = iRequests.Count();
|
|
72 |
for (TInt i = 0; i < count; i++)
|
|
73 |
{
|
|
74 |
if (iRequests[i].iBearer == aBearer && iRequests[i].iRequesting)
|
|
75 |
{
|
|
76 |
for (TInt j = count - 1; j > i; j--)
|
|
77 |
{
|
|
78 |
if (iRequests[j].iBearer == aBearer)
|
|
79 |
{
|
|
80 |
TRACE_INFO((_L("[Srvc %d] [ManSrvc] Remove buffered request(Bearer 0x%04x status %d)"),
|
|
81 |
iPlugin->ImplementationUid().iUid, aBearer, iRequests[j].iStatus))
|
|
82 |
iRequests.Remove(j);
|
|
83 |
}
|
|
84 |
}
|
|
85 |
if ((!iRequests[i].iStatus && aStatus) || (iRequests[i].iStatus && !aStatus))
|
|
86 |
{
|
|
87 |
TRACE_INFO((_L("[Srvc %d] [ManSrvc] Buffer request(Bearer 0x%04x status %d)"),
|
|
88 |
iPlugin->ImplementationUid().iUid, aBearer, aStatus))
|
|
89 |
return iRequests.Append(TLocodServiceRequest(aBearer, aStatus));
|
|
90 |
}
|
|
91 |
else
|
|
92 |
{
|
|
93 |
TRACE_INFO((_L("[Srvc %d] [ManSrvc] Request(Bearer 0x%04x status %d) discarded"),
|
|
94 |
iPlugin->ImplementationUid().iUid, aBearer, aStatus))
|
|
95 |
return KErrNone;
|
|
96 |
}
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
// else if the latest bearer status in this service plugin is different,
|
|
101 |
// Start ManageService()
|
|
102 |
if ( aStatus && !(iServiceStatus & aBearer) ||
|
|
103 |
!aStatus && (iServiceStatus & aBearer))
|
|
104 |
{
|
|
105 |
TLocodServiceRequest request(aBearer, aStatus);
|
|
106 |
request.iRequesting = ETrue;
|
|
107 |
TInt err = iRequests.Append(request);
|
|
108 |
TRACE_INFO((_L("[Srvc %d] [ManSrvc] Issue request(Bearer 0x%04x status %d)"),
|
|
109 |
iPlugin->ImplementationUid().iUid, aBearer, aStatus))
|
|
110 |
if (!err)
|
|
111 |
{
|
|
112 |
iPlugin->ManageService(aBearer, aStatus);
|
|
113 |
}
|
|
114 |
return err;
|
|
115 |
}
|
|
116 |
|
|
117 |
// else the latest bearer status in this service plugin is the same,
|
|
118 |
// do nothing
|
|
119 |
TRACE_INFO((_L("[Srvc %d] [ManSrvc] Request(Bearer 0x%04x status %d) discarded"),
|
|
120 |
iPlugin->ImplementationUid().iUid, aBearer, aStatus))
|
|
121 |
return KErrNone;
|
|
122 |
}
|
|
123 |
|
|
124 |
// ---------------------------------------------------------------------------
|
|
125 |
// Based on the status of bearer either the request is removed or a new manage
|
|
126 |
// service is issued
|
|
127 |
// ---------------------------------------------------------------------------
|
|
128 |
//
|
|
129 |
void CLocodService::ManageServiceCompleted(TLocodBearer aBearer,
|
|
130 |
TBool aStatus, TInt err)
|
|
131 |
{
|
|
132 |
TRACE_INFO((_L("[Srvc %d] [ManSrvc complete] (Bearer 0x%04x status %d) return %d"),
|
|
133 |
iPlugin->ImplementationUid().iUid, aBearer, aStatus, err))
|
|
134 |
// Save the latest status of this bearer
|
|
135 |
if (!err)
|
|
136 |
{
|
|
137 |
if (aStatus)
|
|
138 |
{
|
|
139 |
iServiceStatus |= aBearer;
|
|
140 |
}
|
|
141 |
else
|
|
142 |
{
|
|
143 |
iServiceStatus &= (~aBearer);
|
|
144 |
}
|
|
145 |
TRACE_INFO((_L("[Srvc %d] [SrvcState 0x%04x]"), iPlugin->ImplementationUid().iUid, iServiceStatus))
|
|
146 |
}
|
|
147 |
|
|
148 |
// Find the completed request and remove it from the request list.
|
|
149 |
TInt count = iRequests.Count();
|
|
150 |
for (TInt i = 0; i < count; i++)
|
|
151 |
{
|
|
152 |
if (iRequests[i].iBearer == aBearer && iRequests[i].iRequesting)
|
|
153 |
{
|
|
154 |
TRACE_INFO((_L("[Srvc %d] [ManSrvc completed] Remove completed request(Bearer 0x%04x status %d)"),
|
|
155 |
iPlugin->ImplementationUid().iUid, aBearer, iRequests[i].iStatus))
|
|
156 |
iRequests.Remove(i);
|
|
157 |
break;
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
// Find the next request and start ManageService if the status is changed.
|
|
162 |
count = iRequests.Count();
|
|
163 |
for (TInt i = 0; i < count; i++)
|
|
164 |
{
|
|
165 |
if (iRequests[i].iBearer == aBearer)
|
|
166 |
{
|
|
167 |
if ( (iRequests[i].iStatus && !(iServiceStatus & aBearer)) ||
|
|
168 |
(!iRequests[i].iStatus && (iServiceStatus & aBearer)))
|
|
169 |
{
|
|
170 |
iRequests[i].iRequesting = ETrue;
|
|
171 |
TRACE_INFO((_L("[Srvc %d] [ManSrvc completed] Issue buffered request(Bearer 0x%04x status %d)"),
|
|
172 |
iPlugin->ImplementationUid().iUid, aBearer, iRequests[i].iStatus))
|
|
173 |
iPlugin->ManageService(iRequests[i].iBearer, iRequests[i].iStatus);
|
|
174 |
}
|
|
175 |
else
|
|
176 |
{
|
|
177 |
TRACE_INFO((_L("[Srvc %d] [ManSrvc completed] Remove buffered request(Bearer 0x%04x status %d)"),
|
|
178 |
iPlugin->ImplementationUid().iUid, aBearer, iRequests[i].iStatus))
|
|
179 |
iRequests.Remove(i);
|
|
180 |
}
|
|
181 |
break;
|
|
182 |
}
|
|
183 |
}
|
|
184 |
}
|
|
185 |
|
|
186 |
// ---------------------------------------------------------------------------
|
|
187 |
// return if there are request pending
|
|
188 |
// ---------------------------------------------------------------------------
|
|
189 |
//
|
|
190 |
TBool CLocodService::HasServiceToManage() const
|
|
191 |
{
|
|
192 |
return iRequests.Count();
|
|
193 |
}
|
|
194 |
|
|
195 |
// ---------------------------------------------------------------------------
|
|
196 |
// C++ default constructor
|
|
197 |
// ---------------------------------------------------------------------------
|
|
198 |
//
|
|
199 |
CLocodService::CLocodService(CLocodServicePlugin& aPlugin) : iPlugin(&aPlugin)
|
|
200 |
{
|
|
201 |
TRACE_FUNC_THIS
|
|
202 |
}
|
|
203 |
|
|
204 |
// ---------------------------------------------------------------------------
|
|
205 |
// C++ 2nd phase construction
|
|
206 |
// ---------------------------------------------------------------------------
|
|
207 |
//
|
|
208 |
void CLocodService::ConstructL()
|
|
209 |
{
|
|
210 |
}
|
|
211 |
|
|
212 |
// ---------------------------------------------------------------------------
|
|
213 |
// C++ default constructor
|
|
214 |
// ---------------------------------------------------------------------------
|
|
215 |
//
|
|
216 |
TLocodServiceRequest::TLocodServiceRequest(TLocodBearer aBearer, TBool aStatus)
|
|
217 |
: iBearer(aBearer), iStatus(aStatus), iRequesting(EFalse)
|
|
218 |
{
|
|
219 |
}
|
|
220 |
|