|
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 // HCI server session. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include "hcisession.h" |
|
24 #include "hciserver.h" |
|
25 #include "corehciutil.h" |
|
26 #include "hciserverrequestmgr.h" |
|
27 |
|
28 #include <bluetooth/hci/hciipc.h> |
|
29 #include <bluetooth/logger.h> |
|
30 |
|
31 #ifdef __FLOG_ACTIVE |
|
32 _LIT8(KLogComponent, LOG_COMPONENT_HCISERVER); |
|
33 #endif |
|
34 |
|
35 CHCISession* CHCISession::NewL(CHCIServer& aServer) |
|
36 { |
|
37 LOG_STATIC_FUNC |
|
38 |
|
39 CHCISession* self = new(ELeave) CHCISession(aServer); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 CHCISession::CHCISession(CHCIServer& aServer) |
|
47 : iServer(aServer) |
|
48 { |
|
49 LOG_FUNC |
|
50 |
|
51 iServer.OpenClientReference(); |
|
52 } |
|
53 |
|
54 void CHCISession::ConstructL() |
|
55 { |
|
56 LOG_FUNC |
|
57 } |
|
58 |
|
59 CHCISession::~CHCISession() |
|
60 { |
|
61 LOG_FUNC |
|
62 |
|
63 if(iService) |
|
64 { |
|
65 // only release the service if we acquired it. |
|
66 iServer.ReleaseService(iService); |
|
67 } |
|
68 |
|
69 iServer.CloseClientReference(); |
|
70 } |
|
71 |
|
72 void CHCISession::ServiceL(const RMessage2& aMessage) |
|
73 { |
|
74 LOG_FUNC; |
|
75 LOG1(_L8("\taMessage.Function() = %d"), aMessage.Function()); |
|
76 |
|
77 // This ServiceL only handles the connect to service function, any other |
|
78 // service functions are delegated to the actual services. |
|
79 if(aMessage.Function() == EConnectToService) |
|
80 { |
|
81 if(!iService) |
|
82 { |
|
83 TRAPD(err, iService = iServer.ConnectToServiceL(aMessage.Int0())); |
|
84 if(err == KErrNone) |
|
85 { |
|
86 // We have successfully connected to the service |
|
87 __ASSERT_DEBUG(iService, PANIC(KHciServerPanicCat, ENoServiceProvidedOnConnect)); |
|
88 aMessage.Complete(KErrNone); |
|
89 } |
|
90 else if(err == KErrInUse) |
|
91 { |
|
92 // Service is in use so error the request. |
|
93 aMessage.Complete(KErrInUse); |
|
94 } |
|
95 else |
|
96 { |
|
97 // Some other error meaning the client has made a bad request |
|
98 // so punish them |
|
99 PanicClient(aMessage, EBadServiceConnectRequest); |
|
100 } |
|
101 } |
|
102 else |
|
103 { |
|
104 // We are already open and have a service, so the client is |
|
105 // misbehaving - punish them |
|
106 PanicClient(aMessage, EServiceAlreadyConnected); |
|
107 } |
|
108 } |
|
109 else |
|
110 { |
|
111 // Actually use the service. |
|
112 if(iService) |
|
113 { |
|
114 iService->ServiceL(*this, aMessage); |
|
115 } |
|
116 else |
|
117 { |
|
118 // We need to have been connected to a service, if we haven't |
|
119 // then the client is misbehaving. |
|
120 PanicClient(aMessage, EServiceNotConnectedYet); |
|
121 } |
|
122 } |
|
123 } |