|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalTechnology |
|
19 */ |
|
20 |
|
21 #include "cmtpconnectionmgr.h" |
|
22 #include "cmtpserversession.h" |
|
23 #include "rmtpframework.h" |
|
24 #include "cmtpframeworkconfig.h" |
|
25 #include "cmtpdataprovidercontroller.h" |
|
26 #include "cmtpparserrouter.h" |
|
27 #include "e32def.h" |
|
28 __FLOG_STMT(_LIT8(KComponent,"ServerSession");) |
|
29 |
|
30 |
|
31 /** |
|
32 Constructor. |
|
33 */ |
|
34 CMTPServerSession::CMTPServerSession() |
|
35 { |
|
36 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
37 __FLOG(_L8("CMTPServerSession - Entry")); |
|
38 __FLOG(_L8("CMTPServerSession - Exit")); |
|
39 } |
|
40 |
|
41 /** |
|
42 Destructor. |
|
43 */ |
|
44 CMTPServerSession::~CMTPServerSession() |
|
45 { |
|
46 __FLOG(_L8("~CMTPServerSession - Entry")); |
|
47 static_cast<CMTPServer*>(const_cast<CServer2*>(CSession2::Server()))->DropSession(); |
|
48 iSingletons.Close(); |
|
49 __FLOG(_L8("~CMTPServerSession - Exit")); |
|
50 __FLOG_CLOSE; |
|
51 } |
|
52 |
|
53 void CMTPServerSession::CreateL() |
|
54 { |
|
55 __FLOG(_L8("CreateL - Entry")); |
|
56 iSingletons.OpenL(); |
|
57 static_cast<CMTPServer*>(const_cast<CServer2*>(CSession2::Server()))->AddSession(); |
|
58 __FLOG(_L8("CreateL - Exit")); |
|
59 } |
|
60 |
|
61 void CMTPServerSession::ServiceL(const RMessage2& aMessage) |
|
62 { |
|
63 __FLOG(_L8("ServiceL - Entry")); |
|
64 switch (aMessage.Function()) |
|
65 { |
|
66 case EMTPClientStartTransport: |
|
67 __FLOG(_L8("StartTransport message received")); |
|
68 DoStartTransportL(aMessage); |
|
69 break; |
|
70 case EMTPClientStopTransport: |
|
71 __FLOG(_L8("StopTransport message received")); |
|
72 DoStopTransport(aMessage); |
|
73 break; |
|
74 case EMTPClientIsAvailable : |
|
75 __FLOG(_L8("IsAvailable message received")); |
|
76 DoIsAvailableL(aMessage); |
|
77 |
|
78 break; |
|
79 default: |
|
80 __FLOG(_L8("Unrecognised message received")); |
|
81 break; |
|
82 } |
|
83 __FLOG(_L8("ServiceL - Exit")); |
|
84 } |
|
85 TBool CMTPServerSession::CheckIsAvailableL(TUid aNewUID,TUid aCurUID) |
|
86 { |
|
87 |
|
88 TInt SwitchEnabled; |
|
89 iSingletons.FrameworkConfig().GetValueL(CMTPFrameworkConfig::ETransportSwitchEnabled, SwitchEnabled); |
|
90 if(!SwitchEnabled ) |
|
91 { |
|
92 return EFalse; |
|
93 } |
|
94 TBuf<30> value; |
|
95 iSingletons.FrameworkConfig().GetValueL(CMTPFrameworkConfig::ETransportHighPriorityUID,value); |
|
96 TUint HighUID; |
|
97 TLex lex(value); |
|
98 TInt conErr = lex.Val(HighUID,EHex); |
|
99 if(aCurUID.iUid == HighUID) |
|
100 { |
|
101 return EFalse; |
|
102 |
|
103 } |
|
104 else if(aNewUID.iUid ==HighUID) |
|
105 { |
|
106 return ETrue; |
|
107 } |
|
108 return EFalse; |
|
109 } |
|
110 /** |
|
111 Starts up the specified MTP transport protocol. |
|
112 @param aTransport The implementation UID of the transport protocol implemetation. |
|
113 @leave One of the system wide error codes, if a processing error occurs. |
|
114 */ |
|
115 void CMTPServerSession::DoStartTransportL(const RMessage2& aMessage) |
|
116 { |
|
117 __FLOG(_L8("DoStartTransportL - Entry")); |
|
118 TUid newUID = TUid::Uid(aMessage.Int0()); |
|
119 TUid curUID = iSingletons.ConnectionMgr().TransportUid(); |
|
120 if(curUID !=(KNullUid)) // Another Transport is already running |
|
121 { |
|
122 if(!CheckIsAvailableL(newUID,curUID)) |
|
123 { |
|
124 aMessage.Complete(KErrServerBusy); |
|
125 iSingletons.ConnectionMgr().QueueTransportL( newUID, NULL ); |
|
126 return; |
|
127 } |
|
128 iSingletons.ConnectionMgr().StopTransport(curUID); |
|
129 } |
|
130 |
|
131 TUid secureid=aMessage.SecureId(); |
|
132 iSingletons.ConnectionMgr().SetClientSId(secureid); |
|
133 |
|
134 TInt length = aMessage.GetDesLength( 1 ); |
|
135 |
|
136 if((!CheckIsBlueToothTransport(newUID) || (length!=0)) && (iSingletons.DpController().Count()==0)) |
|
137 { |
|
138 iSingletons.DpController().LoadDataProvidersL(); |
|
139 iSingletons.Router().ConfigureL(); |
|
140 } |
|
141 |
|
142 if (length > 0) |
|
143 { |
|
144 HBufC8* paramHbuf = HBufC8::NewLC(length); |
|
145 TPtr8 bufptr = paramHbuf->Des(); |
|
146 aMessage.ReadL( 1, bufptr, 0); |
|
147 TRAPD(err, iSingletons.ConnectionMgr().StartTransportL( newUID, static_cast<TAny*>(paramHbuf) )); |
|
148 if ( KErrArgument == err ) |
|
149 { |
|
150 PanicClient( aMessage, EPanicErrArgument ); |
|
151 } |
|
152 else if ( KErrNone == err ) |
|
153 { |
|
154 aMessage.Complete(KErrNone); |
|
155 } |
|
156 else |
|
157 { |
|
158 User::LeaveIfError( err ); |
|
159 } |
|
160 CleanupStack::PopAndDestroy(paramHbuf); |
|
161 } |
|
162 else |
|
163 { |
|
164 iSingletons.ConnectionMgr().StartTransportL(newUID, NULL); |
|
165 aMessage.Complete(KErrNone); |
|
166 } |
|
167 |
|
168 |
|
169 __FLOG(_L8("DoStartTransportL - Exit")); |
|
170 } |
|
171 |
|
172 |
|
173 /** |
|
174 Shuts down the specified MTP transport protocol. |
|
175 @param aTransport The implementation UID of the transport protocol implemetation. |
|
176 */ |
|
177 void CMTPServerSession::DoStopTransport(const RMessage2& aMessage) |
|
178 { |
|
179 __FLOG(_L8("DoStopTransport - Entry")); |
|
180 iSingletons.ConnectionMgr().StopTransport( TUid::Uid( aMessage.Int0() ), ETrue ); |
|
181 aMessage.Complete(KErrNone); |
|
182 __FLOG(_L8("DoStopTransport - Exit")); |
|
183 } |
|
184 |
|
185 /** |
|
186 Checks whether MTP Framework shall allow the StartTransport Command for given transport. |
|
187 @param aTransport The implementation UID of the transport protocol implementation. |
|
188 @leave One of the system wide error codes, if a processing error occurs. |
|
189 */ |
|
190 void CMTPServerSession::DoIsAvailableL(const RMessage2& aMessage) |
|
191 { |
|
192 __FLOG(_L8("DoStopTransport - Entry")); |
|
193 |
|
194 TUid newUID = TUid::Uid(aMessage.Int0()); |
|
195 TUid curUID = iSingletons.ConnectionMgr().TransportUid(); |
|
196 |
|
197 if(curUID !=(KNullUid)) // Another Transport is already running |
|
198 { |
|
199 if(curUID== newUID) |
|
200 { |
|
201 aMessage.Complete(KErrAlreadyExists); |
|
202 return; |
|
203 } |
|
204 else if(!CheckIsAvailableL(newUID,curUID)) |
|
205 { |
|
206 aMessage.Complete(KErrServerBusy); |
|
207 return; |
|
208 } |
|
209 } |
|
210 |
|
211 aMessage.Complete(KErrNone); |
|
212 __FLOG(_L8("DoStopTransport - Exit")); |
|
213 } |
|
214 |
|
215 TBool CMTPServerSession::CheckIsBlueToothTransport(TUid aNewUid) |
|
216 { |
|
217 TInt32 bluetoothUid = 0x10286FCB; |
|
218 return aNewUid.iUid == bluetoothUid; |
|
219 } |