|
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 #include <s32mem.h> |
|
17 #include <e32svr.h> |
|
18 |
|
19 #include "pbapsession.h" |
|
20 #include "clientserver.h" |
|
21 #include "pbapserver.h" |
|
22 |
|
23 #include "btaccesshostlog.h" |
|
24 |
|
25 |
|
26 |
|
27 CPbapSession::CPbapSession() |
|
28 { |
|
29 LOG_FUNC |
|
30 } |
|
31 |
|
32 /** |
|
33 Second phase constructor for sessions. Called by the CServer2 framework |
|
34 when a session is created (e.g. a connection is made to the server). |
|
35 */ |
|
36 void CPbapSession::CreateL() |
|
37 { |
|
38 LOG_FUNC |
|
39 Server().AddSession(); |
|
40 } |
|
41 |
|
42 /** |
|
43 Destructor for session classes. When this is called it indicates that |
|
44 a session is closing its connection with the server. |
|
45 */ |
|
46 CPbapSession::~CPbapSession() |
|
47 { |
|
48 LOG_FUNC |
|
49 Server().DropSession(); |
|
50 } |
|
51 |
|
52 |
|
53 CPbapServer& CPbapSession::Server() |
|
54 { |
|
55 LOG_FUNC |
|
56 return *static_cast<CPbapServer*>(const_cast<CServer2*>(CSession2::Server())); |
|
57 } |
|
58 |
|
59 /** |
|
60 Handle message requests for this session. Leaving is handled by |
|
61 CPbapSession::ServiceError() which reports the error code to the client. |
|
62 */ |
|
63 void CPbapSession::ServiceL(const RMessage2 &aMessage) |
|
64 { |
|
65 LOG_FUNC |
|
66 switch (aMessage.Function()) |
|
67 { |
|
68 case EPbapStartListening: |
|
69 { |
|
70 Server().StartObexL(); |
|
71 CompleteRequest(aMessage, KErrNone); |
|
72 } |
|
73 break; |
|
74 case EPbapStopListening: |
|
75 { |
|
76 Server().ReleaseObex(); |
|
77 CompleteRequest(aMessage, KErrNone); |
|
78 } |
|
79 break; |
|
80 case EPbapSetPassword: |
|
81 { |
|
82 HBufC* password = HBufC::NewLC(aMessage.GetDesLengthL(0)); |
|
83 TPtr passwordPtr(password->Des()); |
|
84 aMessage.ReadL(0, passwordPtr); |
|
85 Server().SetPasswordL(password); // ownership passed |
|
86 CleanupStack::Pop(password); |
|
87 CompleteRequest(aMessage, KErrNone); |
|
88 } |
|
89 break; |
|
90 case EPbapDbgMarkHeap: |
|
91 { |
|
92 #ifdef _DEBUG |
|
93 __UHEAP_MARK; |
|
94 #endif |
|
95 CompleteRequest(aMessage, KErrNone); |
|
96 } |
|
97 break; |
|
98 case EPbapDbgCheckHeap: |
|
99 { |
|
100 #ifdef _DEBUG |
|
101 __UHEAP_CHECK(aMessage.Int0()); |
|
102 #endif |
|
103 CompleteRequest(aMessage, KErrNone); |
|
104 } |
|
105 break; |
|
106 case EPbapDbgMarkEnd: |
|
107 { |
|
108 #ifdef _DEBUG |
|
109 __UHEAP_MARKENDC(aMessage.Int0()); |
|
110 #endif |
|
111 CompleteRequest(aMessage, KErrNone); |
|
112 } |
|
113 break; |
|
114 case EPbapDbgFailNext: |
|
115 { |
|
116 #ifdef _DEBUG |
|
117 if (aMessage.Int0() == 0) |
|
118 { |
|
119 __UHEAP_RESET; |
|
120 } |
|
121 else |
|
122 { |
|
123 __UHEAP_FAILNEXT(aMessage.Int0()); |
|
124 } |
|
125 #endif |
|
126 CompleteRequest(aMessage, KErrNone); |
|
127 } |
|
128 break; |
|
129 default: |
|
130 // panic the client |
|
131 aMessage.Panic(KPbapServerPanic, EPbapServerPanicIllegalFunction); |
|
132 break; |
|
133 } |
|
134 } |
|
135 |
|
136 /** |
|
137 Completes a client request. This function provides a single point of |
|
138 message completion which benefits debugging and maintenance. |
|
139 */ |
|
140 void CPbapSession::CompleteRequest(const RMessage2& aMessage, TInt aResult) |
|
141 { |
|
142 LOG_FUNC |
|
143 |
|
144 if (aMessage.IsNull() == EFalse) |
|
145 { |
|
146 aMessage.Complete(aResult); |
|
147 } |
|
148 } |
|
149 |
|
150 |
|
151 /** |
|
152 Handle an error from CPbapSession::ServiceL() |
|
153 bad descriptor error implies a badly programmed client, so panic it |
|
154 otherwise use the default handling (report the error to the client) |
|
155 */ |
|
156 void CPbapSession::ServiceError(const RMessage2& aMessage, TInt aError) |
|
157 { |
|
158 LOG_FUNC |
|
159 if (aError==KErrBadDescriptor) |
|
160 { |
|
161 // panic the client |
|
162 aMessage.Panic(KPbapServerPanic, EPbapServerPanicBadDescriptor); |
|
163 } |
|
164 CSession2::ServiceError(aMessage, aError); |
|
165 } |