29
|
1 |
/*
|
|
2 |
* Copyright (c) 2006-2007 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: The session object for DUN server
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32std.h>
|
|
20 |
#include <c32comm.h>
|
|
21 |
#include <f32file.h>
|
|
22 |
#include <e32math.h>
|
|
23 |
#include <locodbearer.h>
|
|
24 |
#include <btfeaturescfg.h>
|
|
25 |
#include "dunserverdef.h"
|
|
26 |
#include "DunSession.h"
|
|
27 |
#include "DunServer.h"
|
|
28 |
#include "DunPlugin.h"
|
|
29 |
#include "DunDebug.h"
|
|
30 |
|
|
31 |
|
|
32 |
// ======== MEMBER FUNCTIONS ========
|
|
33 |
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
// CDunSession::CDunSession
|
|
36 |
// ---------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
CDunSession::CDunSession( CDunServer* aDunServer ) :
|
|
39 |
CSession2(),
|
|
40 |
iDunServer( aDunServer )
|
|
41 |
{
|
|
42 |
FTRACE(FPrint( _L( "CDunSession::CDunSession()") ));
|
|
43 |
iDunServer->IncRefCount();
|
|
44 |
FTRACE(FPrint( _L( "CDunSession::CDunSession() complete") ));
|
|
45 |
}
|
|
46 |
|
|
47 |
// ---------------------------------------------------------------------------
|
|
48 |
// Destructor.
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
CDunSession::~CDunSession()
|
|
52 |
{
|
|
53 |
FTRACE(FPrint(_L("CDunSession::~CDunSession()")));
|
|
54 |
if ( iDunServer )
|
|
55 |
{
|
|
56 |
iDunServer->DecRefCount();
|
|
57 |
iDunServer = NULL;
|
|
58 |
}
|
|
59 |
FTRACE(FPrint(_L("CDunSession::~CDunSession() complete")));
|
|
60 |
}
|
|
61 |
|
|
62 |
// ---------------------------------------------------------------------------
|
|
63 |
// Return the version number
|
|
64 |
// ---------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
TVersion CDunSession::Version(void) const
|
|
67 |
{
|
|
68 |
return (TVersion( KDunServerMajorVersionNumber,
|
|
69 |
KDunServerMinorVersionNumber,
|
|
70 |
KDunServerBuildVersionNumber ));
|
|
71 |
}
|
|
72 |
|
|
73 |
// ---------------------------------------------------------------------------
|
|
74 |
// From class CSession2.
|
|
75 |
// Handles the servicing of client requests passed to the server
|
|
76 |
// ---------------------------------------------------------------------------
|
|
77 |
//
|
|
78 |
void CDunSession::ServiceL( const RMessage2& aMessage )
|
|
79 |
{
|
|
80 |
FTRACE(FPrint(_L("CDunSession::ServiceL()")));
|
|
81 |
TBool hasCapability = aMessage.HasCapability( ECapabilityLocalServices );
|
|
82 |
if ( !hasCapability )
|
|
83 |
{
|
|
84 |
aMessage.Complete( KErrPermissionDenied );
|
|
85 |
FTRACE(FPrint(_L("CDunSession::ServiceL() (no capability) complete")));
|
|
86 |
return;
|
|
87 |
}
|
|
88 |
TInt retVal = KErrNotSupported;
|
|
89 |
switch ( aMessage.Function() )
|
|
90 |
{
|
|
91 |
case EDunFuncManageService:
|
|
92 |
retVal = DoService( aMessage );
|
|
93 |
break;
|
|
94 |
case EDunFuncActiveConnection:
|
|
95 |
retVal = DoTestService( aMessage );
|
|
96 |
break;
|
|
97 |
default:
|
|
98 |
FTRACE(FPrint(_L("CDunSession::ServiceL() (not supported) complete")));
|
|
99 |
break;
|
|
100 |
}
|
|
101 |
aMessage.Complete( retVal );
|
|
102 |
FTRACE(FPrint(_L("CDunSession::ServiceL() complete")));
|
|
103 |
}
|
|
104 |
|
|
105 |
// ---------------------------------------------------------------------------
|
|
106 |
// From class CSession2.
|
|
107 |
// Return a reference to DUN server
|
|
108 |
// ---------------------------------------------------------------------------
|
|
109 |
//
|
|
110 |
CDunServer& CDunSession::Server() const
|
|
111 |
{
|
|
112 |
return *iDunServer;
|
|
113 |
}
|
|
114 |
|
|
115 |
// ---------------------------------------------------------------------------
|
|
116 |
// Handles incoming service messages
|
|
117 |
// ---------------------------------------------------------------------------
|
|
118 |
//
|
|
119 |
TInt CDunSession::DoService( const RMessage2& aMessage )
|
|
120 |
{
|
|
121 |
FTRACE(FPrint(_L("CDunSession::DoService()")));
|
|
122 |
if ( !iDunServer )
|
|
123 |
{
|
|
124 |
FTRACE(FPrint(_L("CDunSession::DoService() (iDunServer) not initialized!")));
|
|
125 |
return KErrGeneral;
|
|
126 |
}
|
|
127 |
|
|
128 |
TLocodBearer bearer = static_cast<TLocodBearer>( aMessage.Int0() );
|
|
129 |
TBool bearerStatus = static_cast<TBool>( aMessage.Int1() );
|
|
130 |
|
|
131 |
TUid pluginUid;
|
|
132 |
switch ( bearer )
|
|
133 |
{
|
|
134 |
case ELocodBearerBT:
|
|
135 |
{
|
|
136 |
pluginUid = KDunBtPluginUid;
|
|
137 |
FTRACE(FPrint(_L("CDunSession::DoService() Managing service for BT, bearer status %d"), bearerStatus));
|
|
138 |
|
|
139 |
BluetoothFeatures::TEnterpriseEnablementMode mode = BluetoothFeatures::EDisabled;
|
|
140 |
TRAPD(err, mode = BluetoothFeatures::EnterpriseEnablementL());
|
|
141 |
if ( err )
|
|
142 |
{
|
|
143 |
FTRACE(FPrint(_L("CDunSession::DoService() complete: failed to get BluetoothFeatures::EnterpriseEnablementL")));
|
|
144 |
return err;
|
|
145 |
}
|
|
146 |
if ( mode != BluetoothFeatures::EEnabled )
|
|
147 |
{
|
|
148 |
FTRACE(FPrint(_L("CDunSession::DoService() complete: !BluetoothFeatures::EEnabled")));
|
|
149 |
return KErrNotSupported;
|
|
150 |
}
|
|
151 |
}
|
|
152 |
break;
|
|
153 |
case ELocodBearerIR:
|
|
154 |
pluginUid = KDunIrPluginUid;
|
|
155 |
FTRACE(FPrint(_L("CDunSession::DoService() Managing service for IR, bearer status %d"), bearerStatus));
|
|
156 |
break;
|
|
157 |
case ELocodBearerUSB:
|
|
158 |
pluginUid = KDunUsbPluginUid;
|
|
159 |
FTRACE(FPrint(_L("CDunSession::DoService() Managing service for USB, bearer status %d"), bearerStatus));
|
|
160 |
break;
|
|
161 |
default:
|
|
162 |
FTRACE(FPrint(_L("CDunSession::DoService() Unknown service %d, bearer status %d!"), bearer, bearerStatus));
|
|
163 |
return KErrNotSupported;
|
|
164 |
}
|
|
165 |
TInt retVal = KErrNone;
|
|
166 |
if ( bearerStatus ) // ON
|
|
167 |
{
|
|
168 |
retVal = iDunServer->NotifyMediaOpenRequest( pluginUid );
|
|
169 |
}
|
|
170 |
else // OFF
|
|
171 |
{
|
|
172 |
retVal = iDunServer->NotifyMediaCloseRequest( pluginUid );
|
|
173 |
}
|
|
174 |
FTRACE(FPrint(_L("CDunSession::DoService() complete")));
|
|
175 |
return retVal;
|
|
176 |
}
|
|
177 |
|
|
178 |
// ---------------------------------------------------------------------------
|
|
179 |
// Handles incoming test service messages
|
|
180 |
// ---------------------------------------------------------------------------
|
|
181 |
//
|
|
182 |
TInt CDunSession::DoTestService( const RMessage2& aMessage )
|
|
183 |
{
|
|
184 |
FTRACE(FPrint(_L("CDunSession::DoTestService()")));
|
|
185 |
if ( !iDunServer )
|
|
186 |
{
|
|
187 |
FTRACE(FPrint(_L("CDunSession::DoTestService() (iDunServer) not initialized!")));
|
|
188 |
return KErrGeneral;
|
|
189 |
}
|
|
190 |
TConnId connId = iDunServer->ActiveConnection();
|
|
191 |
TPckgBuf<TConnId> connIdPckg( connId );
|
|
192 |
aMessage.Write( 0, connIdPckg ); // First argument in EDunFuncActiveConnection
|
|
193 |
FTRACE(FPrint(_L("CDunSession::DoTestService() complete")));
|
|
194 |
return KErrNone;
|
|
195 |
}
|