60
|
1 |
/*
|
|
2 |
*
|
|
3 |
* Copyright (c) <2010> Comarch S.A. and/or its subsidiary(-ies).
|
|
4 |
* All rights reserved.
|
|
5 |
* This component and the accompanying materials are made available
|
|
6 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
7 |
* which accompanies this distribution, and is available
|
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
9 |
*
|
|
10 |
* Original Contributors:
|
|
11 |
* Comarch S.A. - original contribution.
|
|
12 |
*
|
|
13 |
* Contributors:
|
|
14 |
*
|
|
15 |
* Description:
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
#include "hfpconnectionmanagement.h"
|
|
19 |
#include "hfpcommand.h"
|
|
20 |
#include "hfpsettings.h"
|
|
21 |
#include "debug.h"
|
|
22 |
_LIT8(KHsHFPParamValue0,"0");
|
|
23 |
_LIT8(KHsHFPParamValue1,"1");
|
|
24 |
_LIT8(KHsHFPParamValue3,"3");
|
|
25 |
_LIT8(KHsHFPParamValue16,"16");
|
|
26 |
|
|
27 |
CHsHFPConnectionManagement* CHsHFPConnectionManagement::NewL(
|
|
28 |
MHsHFPFeatureProviderObserver* aObserver )
|
|
29 |
{
|
|
30 |
CHsHFPConnectionManagement* self = CHsHFPConnectionManagement::NewLC(
|
|
31 |
aObserver );
|
|
32 |
CleanupStack::Pop( self );
|
|
33 |
return self;
|
|
34 |
}
|
|
35 |
|
|
36 |
CHsHFPConnectionManagement* CHsHFPConnectionManagement::NewLC(
|
|
37 |
MHsHFPFeatureProviderObserver* aObserver )
|
|
38 |
{
|
|
39 |
CHsHFPConnectionManagement* self =
|
|
40 |
new ( ELeave ) CHsHFPConnectionManagement( aObserver );
|
|
41 |
CleanupStack::PushL( self );
|
|
42 |
self->ConstructL();
|
|
43 |
return self;
|
|
44 |
}
|
|
45 |
|
|
46 |
CHsHFPConnectionManagement::~CHsHFPConnectionManagement()
|
|
47 |
{
|
|
48 |
TRACE_FUNC_ENTRY
|
|
49 |
if ( iSettings )
|
|
50 |
{
|
|
51 |
iSettings->Release();
|
|
52 |
}
|
|
53 |
TRACE_FUNC_EXIT
|
|
54 |
}
|
|
55 |
|
|
56 |
TInt CHsHFPConnectionManagement::EstablishServiceLevelConnection(
|
|
57 |
const CHsHFPCommand &aInputCmd, CHsHFPCommand &aOutputCmd )
|
|
58 |
{
|
|
59 |
TRACE_FUNC_ENTRY
|
|
60 |
TInt res = KErrNone;
|
|
61 |
switch ( iEstablishmentState )
|
|
62 |
{
|
|
63 |
case EHFPNotConnected:
|
|
64 |
{
|
|
65 |
if ( aInputCmd.Type() == EHFPCmdUnknown )//initialization
|
|
66 |
{
|
|
67 |
aOutputCmd.SetType( EHFPCmdBRSF );
|
|
68 |
aOutputCmd.SetMode( ECmdModeWrite );
|
|
69 |
RATParamArray params;
|
|
70 |
params.Append( TATParam( KHsHFPParamValue16 ) );
|
|
71 |
aOutputCmd.SetParams( params );
|
|
72 |
iEstablishmentState = EHFPWaitingForBrsfAndOk;
|
|
73 |
}
|
|
74 |
else
|
|
75 |
{
|
|
76 |
res = KErrArgument;
|
|
77 |
}
|
|
78 |
break;
|
|
79 |
}
|
|
80 |
case EHFPWaitingForBrsfAndOk:
|
|
81 |
{
|
|
82 |
if ( aInputCmd.Type() == EHFPCmdBRSF )
|
|
83 |
{
|
|
84 |
iWaitingForOK = ETrue;
|
|
85 |
}
|
|
86 |
else if ( iWaitingForOK && aInputCmd.Type() == EHFPCmdOK )
|
|
87 |
{
|
|
88 |
iWaitingForOK = EFalse;
|
|
89 |
aOutputCmd.SetType( EHFPCmdCIND );
|
|
90 |
aOutputCmd.SetMode( ECmdModeTest );
|
|
91 |
iEstablishmentState = EHFPWaitingForCindTestAndOk;
|
|
92 |
}
|
|
93 |
else
|
|
94 |
{
|
|
95 |
res = KErrArgument;
|
|
96 |
}
|
|
97 |
break;
|
|
98 |
}
|
|
99 |
case EHFPWaitingForCindTestAndOk:
|
|
100 |
{
|
|
101 |
if ( aInputCmd.Type() == EHFPCmdCIND )
|
|
102 |
{
|
|
103 |
TRAP( res, InitializeIndicatorsL( &aInputCmd ) );
|
|
104 |
iWaitingForOK = ETrue;
|
|
105 |
}
|
|
106 |
else if ( iWaitingForOK && aInputCmd.Type() == EHFPCmdOK )
|
|
107 |
{
|
|
108 |
iWaitingForOK = EFalse;
|
|
109 |
aOutputCmd.SetType( EHFPCmdCIND );
|
|
110 |
aOutputCmd.SetMode( ECmdModeRead );
|
|
111 |
iEstablishmentState = EHFPWaitingForCindReadAndOk;
|
|
112 |
}
|
|
113 |
else
|
|
114 |
{
|
|
115 |
res = KErrArgument;
|
|
116 |
}
|
|
117 |
break;
|
|
118 |
}
|
|
119 |
case EHFPWaitingForCindReadAndOk:
|
|
120 |
{
|
|
121 |
if ( aInputCmd.Type() == EHFPCmdCIND )
|
|
122 |
{
|
|
123 |
TRAP( res, SetupIndicatorsL( &aInputCmd ) );
|
|
124 |
iWaitingForOK = ETrue;
|
|
125 |
}
|
|
126 |
else if ( iWaitingForOK && aInputCmd.Type() == EHFPCmdOK )
|
|
127 |
{
|
|
128 |
iWaitingForOK = EFalse;
|
|
129 |
aOutputCmd.SetType( EHFPCmdCMER );
|
|
130 |
aOutputCmd.SetMode( ECmdModeWrite );
|
|
131 |
RATParamArray params;
|
|
132 |
params.Append( TATParam( KHsHFPParamValue3 ) );
|
|
133 |
params.Append( TATParam( KHsHFPParamValue0 ) );
|
|
134 |
params.Append( TATParam( KHsHFPParamValue0 ) );
|
|
135 |
params.Append( TATParam( KHsHFPParamValue1 ) );
|
|
136 |
aOutputCmd.SetParams( params );
|
|
137 |
iEstablishmentState = EHFPWaitingForOk;
|
|
138 |
}
|
|
139 |
else
|
|
140 |
{
|
|
141 |
res = KErrArgument;
|
|
142 |
}
|
|
143 |
break;
|
|
144 |
}
|
|
145 |
case EHFPWaitingForOk:
|
|
146 |
{
|
|
147 |
if ( aInputCmd.Type() == EHFPCmdOK )
|
|
148 |
{
|
|
149 |
iEstablishmentState = EHFPConnected;
|
|
150 |
|
|
151 |
// Initialize volume level synchronization
|
|
152 |
aOutputCmd.SetType( EHFPCmdVGS );
|
|
153 |
aOutputCmd.SetMode( ECmdModeWrite );
|
|
154 |
RATParamArray params;
|
|
155 |
TBuf8 <KHsHFPMaxVolumeLevelParamSize> vgsLevel;
|
|
156 |
vgsLevel.AppendNum( iSettings->iVgsLevel );
|
|
157 |
params.Append( TATParam( vgsLevel ) );
|
|
158 |
aOutputCmd.SetParams( params );
|
|
159 |
|
|
160 |
iObserver->HandleProcedureCompleted( KErrNone );
|
|
161 |
}
|
|
162 |
else
|
|
163 |
{
|
|
164 |
res = KErrArgument;
|
|
165 |
}
|
|
166 |
break;
|
|
167 |
}
|
|
168 |
default:
|
|
169 |
res = KErrArgument;
|
|
170 |
break;
|
|
171 |
}
|
|
172 |
TRACE_FUNC_EXIT
|
|
173 |
return res;
|
|
174 |
}
|
|
175 |
|
|
176 |
void CHsHFPConnectionManagement::HandleServiceLevelConnectionRelease( TInt aErr )
|
|
177 |
{
|
|
178 |
TRACE_FUNC_ENTRY
|
|
179 |
iEstablishmentState = EHFPNotConnected;
|
|
180 |
iObserver->HandleProcedureCompleted( KErrNone );
|
|
181 |
TRACE_FUNC_EXIT
|
|
182 |
}
|
|
183 |
|
|
184 |
CHsHFPConnectionManagement::CHsHFPConnectionManagement(
|
|
185 |
MHsHFPFeatureProviderObserver* aObserver ) :
|
|
186 |
iObserver( aObserver )
|
|
187 |
{
|
|
188 |
}
|
|
189 |
|
|
190 |
void CHsHFPConnectionManagement::ConstructL()
|
|
191 |
{
|
|
192 |
TRACE_FUNC_ENTRY
|
|
193 |
|
|
194 |
iSettings = CHsHFPSettings::InstanceL();
|
|
195 |
TRACE_FUNC_EXIT
|
|
196 |
}
|
|
197 |
|
|
198 |
void CHsHFPConnectionManagement::InitializeIndicatorsL(
|
|
199 |
const CHsHFPCommand* aCommand )
|
|
200 |
{
|
|
201 |
TRACE_FUNC_ENTRY
|
|
202 |
|
|
203 |
TInt params = aCommand->Params().Count();
|
|
204 |
|
|
205 |
TChar end( '\"' );
|
|
206 |
|
|
207 |
const TInt prefixLength = 2;
|
|
208 |
const TInt suffixLength = 2;
|
|
209 |
for ( TInt i = 0; i < params; i++ )
|
|
210 |
{
|
|
211 |
TInt pos = aCommand->Params()[i].Des().LocateReverse( end );
|
|
212 |
|
|
213 |
if ( pos == KErrNotFound )
|
|
214 |
{
|
|
215 |
User::Leave( KErrArgument );
|
|
216 |
}
|
|
217 |
|
|
218 |
RBuf8 buf;
|
|
219 |
buf.CreateL( aCommand->Params()[i].Des() );
|
|
220 |
buf.CleanupClosePushL();
|
|
221 |
|
|
222 |
buf.Delete( 0, prefixLength );
|
|
223 |
|
|
224 |
buf.Delete( pos - suffixLength, buf.Length() - 1 );
|
|
225 |
|
|
226 |
iSettings->iSettingsArr.AppendL( THsHFPIndicatorSetting( buf, 0 ) );
|
|
227 |
CleanupStack::PopAndDestroy( &buf );
|
|
228 |
|
|
229 |
}
|
|
230 |
TRACE_FUNC_EXIT
|
|
231 |
}
|
|
232 |
|
|
233 |
void CHsHFPConnectionManagement::SetupIndicatorsL(
|
|
234 |
const CHsHFPCommand* aCommand )
|
|
235 |
{
|
|
236 |
TRACE_FUNC_ENTRY
|
|
237 |
|
|
238 |
for ( TInt i = 0; i < aCommand->Params().Count(); i++ )
|
|
239 |
{
|
|
240 |
if ( iSettings->iSettingsArr.Count() > ( i + 1 ) )
|
|
241 |
{
|
|
242 |
iSettings->iSettingsArr[i + 1].SetValueL(
|
|
243 |
aCommand->Params()[i].Des() );
|
|
244 |
TRACE_INFO( (_L8("INDICATOR: %S - value: %d "),
|
|
245 |
&iSettings->iSettingsArr[i + 1].Des(),
|
|
246 |
iSettings->iSettingsArr[i + 1].Int() ) );
|
|
247 |
}
|
|
248 |
}
|
|
249 |
|
|
250 |
TRACE_FUNC_EXIT
|
|
251 |
}
|