|
1 /* |
|
2 * Copyright (c) 2007 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: Handles defualt connection logic |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <metadatabase.h> |
|
19 #include <datamobilitycommsdattypes.h> |
|
20 #include <cmdefconnvalues.h> |
|
21 #include "mpmdefaultconnection.h" |
|
22 #include "mpmserversession.h" //KShift8 |
|
23 #include "mpmserver.h" |
|
24 #include "mpmlogger.h" |
|
25 #include "mpmcommsdataccess.h" |
|
26 |
|
27 using namespace CommsDat; |
|
28 // --------------------------------------------------------------------------- |
|
29 // CMPMDefaultConnection::NewL |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CMPMDefaultConnection* CMPMDefaultConnection::NewL( const CMPMServer* aServer) |
|
33 { |
|
34 CMPMDefaultConnection * self = new (ELeave) |
|
35 CMPMDefaultConnection( aServer ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CMPMDefaultConnection::~CMPMDefaultConnection() |
|
48 { |
|
49 } |
|
50 // --------------------------------------------------------------------------- |
|
51 // CMPMDefaultConnection::SetDefaultIAP |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 TInt CMPMDefaultConnection::SetDefaultIAP( TInt aIapId ) |
|
55 { |
|
56 TInt err( KErrNone ); |
|
57 //check validity |
|
58 if( ( aIapId ) > 0 && ( aIapId <= KCDMaxRecords ) ) |
|
59 { |
|
60 iDefaultIapId = aIapId; |
|
61 MPMLOGSTRING2( |
|
62 "CMPMDefaultConnection::SetDefaultIAP Set default connection iap: %d", |
|
63 aIapId) |
|
64 } |
|
65 else |
|
66 { |
|
67 err = KErrArgument; |
|
68 MPMLOGSTRING2( |
|
69 "CMPMDefaultConnection::SetDefaultIAP Invalid iap: %d", |
|
70 aIapId) |
|
71 } |
|
72 return err; |
|
73 } |
|
74 // --------------------------------------------------------------------------- |
|
75 // CMPMDefaultConnection::ClearDefaultIAP |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 void CMPMDefaultConnection::ClearDefaultIAP() |
|
79 { |
|
80 iDefaultIapId = 0; |
|
81 MPMLOGSTRING( "CMPMDefaultConnection::ClearDefaultIAP:\ |
|
82 cleared default iap" ) |
|
83 } |
|
84 // --------------------------------------------------------------------------- |
|
85 // CMPMDefaultConnection::GetDefaultConnectionL |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void CMPMDefaultConnection::GetDefaultConnectionL( TCmDefConnType& aMode, |
|
89 TUint32& aConnection ) |
|
90 { |
|
91 // first option is registered default iap |
|
92 if( iDefaultIapId ) |
|
93 { |
|
94 MPMLOGSTRING2( "CMPMDefaultConnection::GetDefaultConnectionL:\ |
|
95 default iap set as id %d", iDefaultIapId ) |
|
96 aMode = ECmDefConnConnectionMethod; |
|
97 aConnection = iDefaultIapId; |
|
98 } |
|
99 else |
|
100 { |
|
101 MPMLOGSTRING( "CMPMDefaultConnection::GetDefaultConnectionL:\ |
|
102 getting value from commsdat" ) |
|
103 |
|
104 // read global commsdat setting |
|
105 // |
|
106 TRAPD( err, ReadDefConnSettingL( aMode, aConnection ) ) |
|
107 |
|
108 if( err != KErrNone ) |
|
109 { |
|
110 //use default values |
|
111 // |
|
112 aMode = KDefaultMode; |
|
113 aConnection = KDefaultConnectionId; |
|
114 } |
|
115 |
|
116 MPMLOGSTRING3( "CMPMDefaultConnection::GetDefaultConnectionL: \ |
|
117 found type %d, id %d", aMode, aConnection ) |
|
118 |
|
119 } |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // Constructor |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 CMPMDefaultConnection::CMPMDefaultConnection( const CMPMServer* aServer ) : |
|
127 iServer( aServer ) |
|
128 { |
|
129 |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CMPMDefaultConnection::ConstructL |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CMPMDefaultConnection::ConstructL() |
|
137 { |
|
138 |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // CMPMDefaultConnection::IntToCmDefConnType |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 TCmDefConnType CMPMDefaultConnection::IntToCmDefConnTypeL( const TUint& aInt ) |
|
146 { |
|
147 TCmDefConnType type( TCmDefConnType ( 0 ) ); |
|
148 |
|
149 if( aInt == ECmDefConnDestination ) |
|
150 { |
|
151 type = ECmDefConnDestination; |
|
152 } |
|
153 else if( aInt == ECmDefConnConnectionMethod ) |
|
154 { |
|
155 type = ECmDefConnConnectionMethod; |
|
156 } |
|
157 else |
|
158 { |
|
159 MPMLOGSTRING2( "CMPMDefaultConnection::IntToCmDefConnType:\ |
|
160 incorrect value %d", aInt ) |
|
161 User::Leave( KErrArgument ); |
|
162 } |
|
163 |
|
164 return type; |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CMPMDefaultConnection::ReadDefConnSetting |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CMPMDefaultConnection::ReadDefConnSettingL( TCmDefConnType& aType, |
|
172 TUint32& aId ) |
|
173 { |
|
174 MPMLOGSTRING( "CMPMDefaultConnection::ReadDefConnSettingL " ) |
|
175 CMDBSession* db = CMDBSession::NewLC( CMDBSession::LatestVersion() ); |
|
176 TMDBElementId tableId = CCDDefConnRecord::TableIdL( *db ); |
|
177 |
|
178 // fetch value from commsdat using record set to be able |
|
179 // to load any and all records in the table. |
|
180 // we don't want to make assumptions on id |
|
181 // |
|
182 CMDBRecordSet<CMDBGenericRecord> * recordSet = new ( ELeave ) |
|
183 CMDBRecordSet<CMDBGenericRecord>( tableId ); |
|
184 CleanupStack::PushL( recordSet ); |
|
185 recordSet->LoadL( *db ); |
|
186 |
|
187 CCDDefConnRecord* dconn = new (ELeave) CCDDefConnRecord( tableId ); |
|
188 CleanupStack::PushL( dconn ); |
|
189 if( recordSet->iRecords.Count() ) |
|
190 { |
|
191 // load the first entry found |
|
192 dconn->SetElementId( CMPMCommsDatAccess::GetRealElementId( recordSet->iRecords[0] ) ); |
|
193 dconn->LoadL( *db ); |
|
194 aType = IntToCmDefConnTypeL( dconn->iDefConnType ); |
|
195 aId = dconn->iDefConnUid; |
|
196 } |
|
197 else |
|
198 { |
|
199 // nothing found, use default value |
|
200 // |
|
201 MPMLOGSTRING( "CMPMDefaultConnection::ReadDefConnSettingL \ |
|
202 no entry found" ) |
|
203 aType = KDefaultMode; |
|
204 aId = KDefaultConnectionId; |
|
205 } |
|
206 db->Close(); |
|
207 CleanupStack::PopAndDestroy( dconn ); |
|
208 CleanupStack::PopAndDestroy( recordSet ); |
|
209 CleanupStack::PopAndDestroy( db ); |
|
210 } |