|
1 /* |
|
2 * Copyright (c) 2004 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: Implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <s32file.h> |
|
19 #include "TTcSettings.h" |
|
20 #include "TestClientConstants.h" |
|
21 |
|
22 // Increment this value if changes are made to the settings file contents |
|
23 const TInt KTcSettingsVersion( 7 ); |
|
24 |
|
25 TTcSettings::TTcSettings() |
|
26 : iBearerType( 1 ), |
|
27 iAutoConnect( EFalse ), |
|
28 iTCPPort( KTcDefaultPort ), |
|
29 iIAPId( KTcDefaultIAPId ), |
|
30 iIsFirstRun( ETrue ), |
|
31 iCSYName( 0 ), |
|
32 iCommPort( 0 ), |
|
33 iBaudrate( KTcDefaultBaudrate ), |
|
34 iTCPRemoteAddr() |
|
35 { |
|
36 iTCPRemoteAddr.SetAddress( INET_ADDR( 0, 0, 0, 0 ) ); |
|
37 } |
|
38 |
|
39 TTcSettings::~TTcSettings() |
|
40 { |
|
41 } |
|
42 |
|
43 void TTcSettings::Load() |
|
44 { |
|
45 // Connect to file server |
|
46 RFs fs; |
|
47 if( fs.Connect() ) |
|
48 { |
|
49 return; |
|
50 } |
|
51 |
|
52 // Open the settings file for reading, it might not exist yet |
|
53 RFileReadStream in; |
|
54 if( !in.Open( fs, KTcSettingsFile, EFileRead ) ) |
|
55 { |
|
56 // Load actual data, ignore errors (the file might be of a previous |
|
57 // version and/or some items might be missing). |
|
58 TRAP_IGNORE( doLoadL( in ) ) |
|
59 } |
|
60 |
|
61 in.Close(); |
|
62 fs.Close(); |
|
63 } |
|
64 |
|
65 void TTcSettings::Store() |
|
66 { |
|
67 // Connect to file server |
|
68 RFs fs; |
|
69 if( fs.Connect() ) |
|
70 { |
|
71 return; |
|
72 } |
|
73 |
|
74 // Open the settings file for writing, replace any existing data |
|
75 RFileWriteStream out; |
|
76 if( !out.Replace( fs, KTcSettingsFile, EFileWrite ) ) |
|
77 { |
|
78 // Write actual data, ignore errors |
|
79 TRAP_IGNORE( doStoreL( out ) ) |
|
80 } |
|
81 |
|
82 out.Close(); |
|
83 fs.Close(); |
|
84 } |
|
85 |
|
86 void TTcSettings::doLoadL( RReadStream& aStream ) |
|
87 { |
|
88 // Check that the file is of correct version |
|
89 TInt version = aStream.ReadInt16L(); |
|
90 if( version == KTcSettingsVersion ) |
|
91 { |
|
92 // Read bearer selection |
|
93 iBearerType = aStream.ReadInt32L() ; |
|
94 // Read autoconnect selection |
|
95 iAutoConnect = aStream.ReadInt16L(); |
|
96 // Read TCP port selection |
|
97 iTCPPort = aStream.ReadInt16L(); |
|
98 // Read IAP Id |
|
99 iIAPId = aStream.ReadInt16L(); |
|
100 // Read CSY name |
|
101 iCSYName = aStream.ReadInt32L(); |
|
102 // Read comms port name |
|
103 iCommPort = aStream.ReadInt32L(); |
|
104 // Read baudrate of comms |
|
105 iBaudrate = aStream.ReadInt32L(); |
|
106 // Read first run flag |
|
107 iIsFirstRun = aStream.ReadInt16L(); |
|
108 |
|
109 // Read remote TCP address as string |
|
110 |
|
111 // Read length first |
|
112 TUint16 length = aStream.ReadInt16L(); |
|
113 |
|
114 TBuf<40> buf; |
|
115 aStream.ReadL( buf, length); |
|
116 iTCPRemoteAddr.Input(buf); |
|
117 |
|
118 } |
|
119 } |
|
120 |
|
121 void TTcSettings::doStoreL( RWriteStream& aStream ) |
|
122 { |
|
123 aStream.WriteInt16L( KTcSettingsVersion ); |
|
124 // Write bearer selection |
|
125 aStream.WriteInt32L( iBearerType ); |
|
126 // Write autoconnect selection |
|
127 aStream.WriteInt16L( iAutoConnect ); |
|
128 // Write TCP port selection |
|
129 aStream.WriteInt16L( iTCPPort ); |
|
130 // Write IAP iD |
|
131 aStream.WriteInt16L( iIAPId ); |
|
132 // Write CSY name |
|
133 aStream.WriteInt32L( iCSYName ); |
|
134 // Write comms port name |
|
135 aStream.WriteInt32L( iCommPort ); |
|
136 // Write baudrate of comms |
|
137 aStream.WriteInt32L( iBaudrate ); |
|
138 // Write first run flag |
|
139 aStream.WriteInt16L( iIsFirstRun ); |
|
140 |
|
141 // Write remote tcp address as string |
|
142 TBuf<40> buf; |
|
143 iTCPRemoteAddr.Output(buf); |
|
144 |
|
145 //write length first |
|
146 aStream.WriteInt16L( buf.Length() ); |
|
147 aStream.WriteL(buf); |
|
148 |
|
149 } |