1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 @publishedPartner |
|
22 */ |
|
23 |
|
24 #ifndef USBNCM_H |
|
25 #define USBNCM_H |
|
26 |
|
27 //INCLUDES |
|
28 #include <e32std.h> |
|
29 |
|
30 /** Defines the exported P&S key and data structure of the value. */ |
|
31 namespace UsbNcm |
|
32 { |
|
33 /** The property's category UID. |
|
34 * This property is to notify the NCM connection state. |
|
35 */ |
|
36 static const TUid KCatNcmSvrUid = {0x101F7989}; |
|
37 |
|
38 /** The property's sub-key.*/ |
|
39 static const TUint KKeyNcmConnectionEvent = 0x2002C33F; |
|
40 |
|
41 |
|
42 /** NCM connection state.*/ |
|
43 enum TNcmConnectionState |
|
44 { |
|
45 ENcmStateDisconnected = 0, |
|
46 ENcmStateConnected, |
|
47 ENcmStateMax |
|
48 }; |
|
49 |
|
50 /** |
|
51 * Defines the NCM connection event, which contains the IapId, NCM connection state and corresponding error code. |
|
52 * The NCM connection is a special one which can not only be used by RConnection, but also needed to monitor the P&S to fetch its state changing. |
|
53 * Once the P&S published the ENcmStateConnected, the iIapId is also available for starting this connection. |
|
54 * Otherwise, if the P&S published the ENcmStateDisconnected, the iErrCode should be checked to notify the failure reason: |
|
55 * KErrNone, normally disconnected probably because of USB cable unpluged. |
|
56 * KErrInUse, means the other component(currently, BtPan or RNDIS) hold the other P&S key so that the DHCP Provision can't be done by NCM. |
|
57 * system-wide error code, please check Developer Library. |
|
58 * It is also possible that this P&S key is deleted when fetching its value because of the NCM connection closed by its driver. |
|
59 * |
|
60 * @see below sample code. |
|
61 */ |
|
62 struct TNcmConnectionEvent |
|
63 { |
|
64 TUint32 iIapId; |
|
65 TNcmConnectionState iState; |
|
66 TInt iErrCode; |
|
67 TUint8 reserved[20]; |
|
68 }; |
|
69 } // namespace UsbNcm |
|
70 |
|
71 /** |
|
72 Example Usage: |
|
73 @code |
|
74 //header file. |
|
75 #include <usb/usbncm.h> |
|
76 using namespace UsbNcm; |
|
77 |
|
78 CMySampleClass: public CActive |
|
79 { |
|
80 private: |
|
81 RProperty iProperty; |
|
82 RConnection iConnection; |
|
83 TPckgBuf<TNcmConnectionEvent> iNcmEvent; |
|
84 RSocket iSocket; |
|
85 } |
|
86 @endcode |
|
87 |
|
88 @code |
|
89 #include "mysampleclass.h" |
|
90 |
|
91 void CMySampleClass::ContructL() |
|
92 { |
|
93 User::LeaveIfError(iProperty.Attach(KCatNcmSvrUid, KKeyNcmConnectionEvent, EOwnerThread)); |
|
94 |
|
95 iProperty.Get(iNcmEvent); |
|
96 if (ENcmStateConnected == iNcmEvent.iState) |
|
97 { |
|
98 TRequestStatus* pStatus = &iStatus; |
|
99 iStatus = KRequestPending; |
|
100 User::RequestComplete(pStatus, KErrNone); |
|
101 } |
|
102 else |
|
103 { |
|
104 iProperty.Subscribe(iStatus); |
|
105 SetActive(); |
|
106 } |
|
107 } |
|
108 |
|
109 void CMySampleClass::RunL() |
|
110 { |
|
111 if (KErrNone == iStatus.Int()) |
|
112 { |
|
113 iProperty.Get(iNcmEvent); |
|
114 |
|
115 switch(iNcmEvent.iState) |
|
116 { |
|
117 case ENcmStateConnected: |
|
118 StartConnection(); |
|
119 break; |
|
120 |
|
121 case ENcmStateDisconnected: |
|
122 if (KErrInUse == iNcmEvent.u.iErrCode) |
|
123 { |
|
124 //Show error UI with msg like "BtPan or Rndis is active, pls deactive it then re-try....", etc. |
|
125 } |
|
126 else |
|
127 { |
|
128 //Show error UI with other msg as you like. |
|
129 //StopConnection(); |
|
130 } |
|
131 break; |
|
132 } |
|
133 } |
|
134 } |
|
135 |
|
136 //Sample code, not all string in this panic show on. |
|
137 LIT(KNotFoundNcm, "NotFoundPanic - The NCM connection was not found!"); |
|
138 |
|
139 TInt CMySampleClass::StartConnection() |
|
140 { |
|
141 //the number of connections. |
|
142 TInt cnt = 0; |
|
143 iConnection.EnumerateConnections(cnt); |
|
144 |
|
145 TInt index = 1; |
|
146 for (index = 1; index <= cnt; index++) |
|
147 { |
|
148 TPckgBuf<TConnectionInfo> info; |
|
149 iConnection.GetConnectionInfo(index, info); |
|
150 if (info().iIapId == iNcmEvent.iIapId) |
|
151 { |
|
152 iConnection.Attach(info, RConnection::EAttachTypeNormal); |
|
153 break; |
|
154 } |
|
155 } |
|
156 __ASSERT_ALWAYS(index <= cnt, User::Panic(KErrNotFound, KNotFoundNcm)); |
|
157 |
|
158 TInt ret = iSocket.Open(...., iConnection); |
|
159 //..... |
|
160 return ret; |
|
161 } |
|
162 @endcode |
|
163 */ |
|
164 #endif // USBNCM_H |
|