|
1 // rconn.cpp |
|
2 // |
|
3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #undef SYMBIAN_ENABLE_SPLIT_HEADERS // Stopgap to handle TConnectionInfoV2 being moved in latest TB92 |
|
14 |
|
15 #include <fshell/ioutils.h> |
|
16 #include <es_sock.h> |
|
17 #include <es_enum.h> |
|
18 #include <nifvar.h> |
|
19 #include <commdbconnpref.h> |
|
20 |
|
21 using namespace IoUtils; |
|
22 |
|
23 class CCmdRconn : public CCommandBase |
|
24 { |
|
25 public: |
|
26 static CCommandBase* NewLC(); |
|
27 ~CCmdRconn(); |
|
28 private: |
|
29 CCmdRconn(); |
|
30 void ListConnectionsL(); |
|
31 void StartConnectionL(); |
|
32 void StopConnectionL(); |
|
33 private: // From CCommandBase. |
|
34 virtual const TDesC& Name() const; |
|
35 virtual void DoRunL(); |
|
36 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
37 virtual void OptionsL(RCommandOptionList& aOptions); |
|
38 private: |
|
39 RSocketServ iSocketSession; |
|
40 RConnection iConnection; |
|
41 enum |
|
42 { |
|
43 EList, EStart, EStop |
|
44 } iOperation; |
|
45 TUint iIapId; |
|
46 TUint iNetworkId; |
|
47 }; |
|
48 |
|
49 |
|
50 CCommandBase* CCmdRconn::NewLC() |
|
51 { |
|
52 CCmdRconn* self = new(ELeave) CCmdRconn(); |
|
53 CleanupStack::PushL(self); |
|
54 self->BaseConstructL(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 CCmdRconn::~CCmdRconn() |
|
59 { |
|
60 iConnection.Close(); |
|
61 iSocketSession.Close(); |
|
62 } |
|
63 |
|
64 CCmdRconn::CCmdRconn() |
|
65 { |
|
66 } |
|
67 |
|
68 const TDesC& CCmdRconn::Name() const |
|
69 { |
|
70 _LIT(KName, "rconn"); |
|
71 return KName; |
|
72 } |
|
73 |
|
74 #define CASE_RETURN_LIT(XXX) case XXX: { _LIT(_KLit, #XXX); return &_KLit; } |
|
75 #define DEFAULT_RETURN_LIT(XXX) default: { _LIT(_KLit, XXX); return &_KLit; } |
|
76 |
|
77 const TDesC* StringifyConnectionType(TConnectionType aConnectionType) |
|
78 { |
|
79 enum TConnectionType_NotPresentInTB92 |
|
80 { |
|
81 EConnectionCDMA = 2500, |
|
82 EConnectionCDMA20001xRTT, |
|
83 EConnectionCDMA20001xRTTDO, |
|
84 EConnectionCDMA20001xRTTDV, |
|
85 EConnectionCDMA20003xRTT, |
|
86 }; |
|
87 |
|
88 switch (aConnectionType) |
|
89 { |
|
90 CASE_RETURN_LIT(EConnectionGeneric); |
|
91 CASE_RETURN_LIT(EConnectionCSD); |
|
92 CASE_RETURN_LIT(EConnectionGPRS); |
|
93 CASE_RETURN_LIT(EConnectionGPRSR97); |
|
94 CASE_RETURN_LIT(EConnectionGPRSR99); |
|
95 CASE_RETURN_LIT(EConnectionGPRSRel4); |
|
96 CASE_RETURN_LIT(EConnectionGPRSRel5); |
|
97 CASE_RETURN_LIT(EConnectionCDMA); |
|
98 CASE_RETURN_LIT(EConnectionCDMA20001xRTT); |
|
99 CASE_RETURN_LIT(EConnectionCDMA20001xRTTDO); |
|
100 CASE_RETURN_LIT(EConnectionCDMA20001xRTTDV); |
|
101 CASE_RETURN_LIT(EConnectionCDMA20003xRTT); |
|
102 CASE_RETURN_LIT(EConnectionEthernet); |
|
103 CASE_RETURN_LIT(EConnectionWLAN); |
|
104 CASE_RETURN_LIT(EConnectionBTPAN); |
|
105 DEFAULT_RETURN_LIT("Unknown"); |
|
106 } |
|
107 } |
|
108 |
|
109 void CCmdRconn::DoRunL() |
|
110 { |
|
111 LeaveIfErr(iSocketSession.Connect(), _L("Couldn't open socket server session")); |
|
112 LeaveIfErr(iConnection.Open(iSocketSession), _L("Couldn't open connection handle")); |
|
113 |
|
114 if (!iArguments.IsPresent(0)) iOperation = EList; |
|
115 switch (iOperation) |
|
116 { |
|
117 case EList: |
|
118 ListConnectionsL(); |
|
119 break; |
|
120 case EStart: |
|
121 StartConnectionL(); |
|
122 break; |
|
123 case EStop: |
|
124 StopConnectionL(); |
|
125 break; |
|
126 } |
|
127 } |
|
128 |
|
129 void CCmdRconn::ListConnectionsL() |
|
130 { |
|
131 TUint numConnections; |
|
132 LeaveIfErr(iConnection.EnumerateConnections(numConnections), _L("Couldn't enumerate connections")); |
|
133 |
|
134 if (numConnections <= 0) |
|
135 { |
|
136 Write(_L("No connections currently up.\r\n")); |
|
137 } |
|
138 else |
|
139 { |
|
140 IoUtils::CTextFormatter* formatter = CTextFormatter::NewLC(Stdout()); |
|
141 IoUtils::CTextBuffer* buf = IoUtils::CTextBuffer::NewLC(0x100); |
|
142 buf->AppendFormatL(_L("IAP\tNetwork\tType\r\n")); |
|
143 for (TInt i = 1; i <= numConnections; ++i) |
|
144 { |
|
145 TConnectionInfoV2Buf connectionInfoBuf; |
|
146 LeaveIfErr(iConnection.GetConnectionInfo(i, connectionInfoBuf), _L("Couldn't get connection info (%d of %d)"), i, numConnections); |
|
147 TConnectionInfoV2& info = connectionInfoBuf(); |
|
148 buf->AppendFormatL(_L("%d\t%d\t%S\r\n"), info.iIapId, info.iNetId, StringifyConnectionType(info.ConnectionType())); |
|
149 } |
|
150 formatter->TabulateL(0, 2, buf->Descriptor()); |
|
151 Write(formatter->Descriptor()); |
|
152 CleanupStack::PopAndDestroy(2, formatter); |
|
153 } |
|
154 } |
|
155 |
|
156 void CCmdRconn::StartConnectionL() |
|
157 { |
|
158 TCommDbConnPref prefs; |
|
159 if (iIapId > 0) |
|
160 { |
|
161 prefs.SetIapId(iIapId); |
|
162 prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
163 } |
|
164 if (iNetworkId > 0) |
|
165 { |
|
166 prefs.SetNetId(iNetworkId); |
|
167 } |
|
168 LeaveIfErr(iConnection.Start(prefs), _L("Failed to start connection")); |
|
169 } |
|
170 |
|
171 void CCmdRconn::StopConnectionL() |
|
172 { |
|
173 TConnectionInfo connectionInfo; |
|
174 if (iIapId > 0) |
|
175 { |
|
176 connectionInfo.iIapId = iIapId; |
|
177 } |
|
178 if (iNetworkId > 0) |
|
179 { |
|
180 connectionInfo.iNetId = iNetworkId; |
|
181 } |
|
182 TPckgC<TConnectionInfo> connectionInfoPckg(connectionInfo); |
|
183 LeaveIfErr(iConnection.Attach(connectionInfoPckg, RConnection::EAttachTypeNormal), _L("Unable to attach to connection")); |
|
184 LeaveIfErr(iConnection.Stop(), _L("Unable to stop connection")); |
|
185 } |
|
186 |
|
187 void CCmdRconn::OptionsL(RCommandOptionList& aOptions) |
|
188 { |
|
189 _LIT(KOptIapId, "iap"); |
|
190 aOptions.AppendUintL(iIapId, KOptIapId); |
|
191 |
|
192 _LIT(KOptNetworkId, "network"); |
|
193 aOptions.AppendUintL(iNetworkId, KOptNetworkId); |
|
194 } |
|
195 |
|
196 void CCmdRconn::ArgumentsL(RCommandArgumentList& aArguments) |
|
197 { |
|
198 _LIT(KArgOperation, "operation"); |
|
199 aArguments.AppendEnumL((TInt&)iOperation, KArgOperation); |
|
200 } |
|
201 |
|
202 EXE_BOILER_PLATE(CCmdRconn) |
|
203 |