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 #include "ncmcoexistbearerwatcher.h" |
|
19 #include "OstTraceDefinitions.h" |
|
20 #ifdef OST_TRACE_COMPILER_IN_USE |
|
21 #include "ncmcoexistbearerwatcherTraces.h" |
|
22 #endif |
|
23 |
|
24 |
|
25 #ifdef _DEBUG |
|
26 _LIT(KCoBearerPanic, "CoexistBearerPanic"); |
|
27 #endif |
|
28 |
|
29 CNcmCoexistBearerWatcher* CNcmCoexistBearerWatcher::NewL() |
|
30 { |
|
31 CNcmCoexistBearerWatcher* self = new(ELeave) CNcmCoexistBearerWatcher(); |
|
32 CleanupStack::PushL(self); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop(self); |
|
35 return self; |
|
36 } |
|
37 |
|
38 CNcmCoexistBearerWatcher::CNcmCoexistBearerWatcher() : CActive(CActive::EPriorityStandard) |
|
39 { |
|
40 CActiveScheduler::Add(this); |
|
41 } |
|
42 |
|
43 |
|
44 CNcmCoexistBearerWatcher::~CNcmCoexistBearerWatcher() |
|
45 { |
|
46 Cancel(); |
|
47 iProperty.Close(); |
|
48 } |
|
49 |
|
50 |
|
51 void CNcmCoexistBearerWatcher::ConstructL() |
|
52 { |
|
53 OstTraceFunctionEntry0(CNCMCOEXISTBEARERWATCHER_CONSTRUCTL); |
|
54 |
|
55 const TUint KIPBearerCoexistenceProperty = 0x10286a95; |
|
56 |
|
57 TInt err = iProperty.Define(KIPBearerCoexistenceProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy); |
|
58 if ( (err != KErrNone) && (err != KErrAlreadyExists) ) |
|
59 { |
|
60 OstTrace1( TRACE_ERROR, CNCMCOEXISTBEARERWATCHER_CONSTRUCTL_DUP02, "Failed to define the property;err=%d", err ); |
|
61 User::Leave(err); |
|
62 } |
|
63 |
|
64 TSecureId thisSID = RProcess().SecureId(); |
|
65 User::LeaveIfError(iProperty.Attach(thisSID, KIPBearerCoexistenceProperty)); |
|
66 User::LeaveIfError(iProperty.Get(reinterpret_cast<TInt&>(iBearerState))); |
|
67 |
|
68 OstTraceFunctionExit0(CNCMCOEXISTBEARERWATCHER_CONSTRUCTL_DUP01); |
|
69 } |
|
70 |
|
71 |
|
72 TInt CNcmCoexistBearerWatcher::SetIpOverUsbActive(TRequestStatus& aStatus) |
|
73 { |
|
74 OstTraceFunctionEntry0(CNCMCOEXISTBEARERWATCHER_SETIPOVERUSBACTIVE); |
|
75 |
|
76 TInt ret = DoActive(); |
|
77 OstTrace1(TRACE_NORMAL, CNCMCOEXISTBEARERWATCHER_SETIPOVERUSBACTIVE_DUP01, "DoActive()=%d.", ret); |
|
78 |
|
79 if (KErrNone == ret) |
|
80 { |
|
81 OstTraceFunctionExitExt(CNCMCOEXISTBEARERWATCHER_SETIPOVERUSBACTIVE_DUP02, this, KErrCompletion); |
|
82 return KErrCompletion; |
|
83 } |
|
84 else if (KErrInUse == ret) |
|
85 { |
|
86 iReportStatus = &aStatus; |
|
87 *iReportStatus = KRequestPending; |
|
88 |
|
89 iProperty.Subscribe(iStatus); |
|
90 SetActive(); |
|
91 return KErrNone; |
|
92 } |
|
93 |
|
94 OstTraceFunctionExitExt(CNCMCOEXISTBEARERWATCHER_SETIPOVERUSBACTIVE_DUP03, this, ret); |
|
95 return ret; |
|
96 } |
|
97 /** |
|
98 * do Set IP Over USB Actived. |
|
99 */ |
|
100 TInt CNcmCoexistBearerWatcher::DoActive() |
|
101 { |
|
102 __ASSERT_DEBUG(iBearerState != EIPBearerIPOverUSB, User::Panic(KCoBearerPanic, __LINE__)); |
|
103 |
|
104 _LIT(KIPBearerCoexistenceMutex, "IPBearerCoexistenceMutex"); |
|
105 RMutex gMutex; |
|
106 TInt error = gMutex.CreateGlobal(KIPBearerCoexistenceMutex); |
|
107 if ( error != KErrNone ) |
|
108 { |
|
109 if( error == KErrAlreadyExists ) |
|
110 { |
|
111 error = gMutex.OpenGlobal(KIPBearerCoexistenceMutex); |
|
112 if(error != KErrNone) |
|
113 { |
|
114 OstTrace1(TRACE_ERROR, CNCMCOEXISTBEARERWATCHER_DOACTIVE, "Failed to open global mutex, error=%d", error); |
|
115 return KErrNotReady; |
|
116 } |
|
117 } |
|
118 else |
|
119 { |
|
120 OstTrace1(TRACE_ERROR, CNCMCOEXISTBEARERWATCHER_DOACTIVE_DUP01, "Failed to create a global mutex, error=%d", error); |
|
121 return KErrNotReady; |
|
122 } |
|
123 } |
|
124 |
|
125 gMutex.Wait(); |
|
126 error = iProperty.Get(reinterpret_cast<TInt&>(iBearerState)); |
|
127 if (error != KErrNone) |
|
128 { |
|
129 OstTrace1(TRACE_ERROR, CNCMCOEXISTBEARERWATCHER_DOACTIVE_DUP02, "Failed to get property value, error=%d", error); |
|
130 } |
|
131 else |
|
132 { |
|
133 if (iBearerState == EIPBearerNoneActive) |
|
134 { |
|
135 error = iProperty.Set(EIPBearerIPOverUSB); |
|
136 if (error != KErrNone) |
|
137 { |
|
138 OstTrace1(TRACE_ERROR, CNCMCOEXISTBEARERWATCHER_DOACTIVE_DUP03, "Failed to set property value, error=%d", error); |
|
139 } |
|
140 else |
|
141 { |
|
142 iBearerState = EIPBearerIPOverUSB; |
|
143 } |
|
144 } |
|
145 else |
|
146 { |
|
147 error = KErrInUse; |
|
148 __ASSERT_DEBUG(iBearerState != EIPBearerIPOverUSB, User::Panic(KCoBearerPanic, __LINE__)); |
|
149 OstTrace1(TRACE_WARNING, CNCMCOEXISTBEARERWATCHER_DOACTIVE_DUP04, "Failed to set CoexistIPBearer to IPOverUsb since iBearerState=%d", iBearerState); |
|
150 } |
|
151 } |
|
152 |
|
153 gMutex.Signal(); |
|
154 gMutex.Close(); |
|
155 |
|
156 return error; |
|
157 } |
|
158 |
|
159 TInt CNcmCoexistBearerWatcher::SetIpOverUsbDeactive() |
|
160 { |
|
161 __ASSERT_DEBUG(iBearerState==EIPBearerIPOverUSB, User::Panic(KCoBearerPanic, __LINE__)); |
|
162 |
|
163 TInt err = iProperty.Set(EIPBearerNoneActive); |
|
164 OstTrace1(TRACE_NORMAL, CNCMCOEXISTBEARERWATCHER_SETIPOVERUSBDEACTIVE, "Stop using Coexistence Bearer, result=%d", err); |
|
165 iBearerState = EIPBearerNoneActive; |
|
166 |
|
167 return err; |
|
168 } |
|
169 |
|
170 void CNcmCoexistBearerWatcher::RunL() |
|
171 { |
|
172 OstTrace1(TRACE_NORMAL, CNCMCOEXISTBEARERWATCHER_RUNL, "iStatus.Int()=%d", iStatus.Int()); |
|
173 |
|
174 if (KErrNone == iStatus.Int()) |
|
175 { |
|
176 TInt ret = DoActive(); |
|
177 OstTrace1(TRACE_NORMAL, CNCMCOEXISTBEARERWATCHER_RUNL_DUP01, "DoActive()=%d", ret); |
|
178 if (KErrNone == ret) |
|
179 { |
|
180 User::RequestComplete(iReportStatus, KErrNone); |
|
181 } |
|
182 else if (KErrInUse == ret) |
|
183 { |
|
184 iProperty.Subscribe(iStatus); |
|
185 SetActive(); |
|
186 } |
|
187 else |
|
188 { |
|
189 User::RequestComplete(iReportStatus, ret); |
|
190 } |
|
191 } |
|
192 else if (KErrCancel != iStatus.Int()) |
|
193 { |
|
194 User::RequestComplete(iReportStatus, iStatus.Int()); |
|
195 } |
|
196 } |
|
197 |
|
198 void CNcmCoexistBearerWatcher::DoCancel() |
|
199 { |
|
200 OstTraceFunctionEntry0(CNCMCOEXISTBEARERWATCHER_DOCANCEL); |
|
201 iProperty.Cancel(); |
|
202 User::RequestComplete(iReportStatus, KErrCancel); |
|
203 } |
|