|
1 /* |
|
2 * Copyright (c) 2005 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 * Server class is responsible for creating sessions and then handle |
|
16 * messages from the session class. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32property.h> |
|
23 #include <btengprivatepskeys.h> |
|
24 |
|
25 #include "BTAccServer.h" |
|
26 #include "BTAccClientSrv.h" // server name, panic code |
|
27 #include "BTAccSecurityPolicy.h" |
|
28 #include "BTAccSession.h" // create server's session |
|
29 #include "debug.h" |
|
30 #include "btmanclient.h" // TBTDevAddrPckgBug |
|
31 #include "basrvaccman.h" |
|
32 #include "BTAccInfo.h" |
|
33 |
|
34 /** PubSub key read and write policies */ |
|
35 _LIT_SECURITY_POLICY_C1( KBTEngPSKeyReadPolicy, |
|
36 ECapabilityLocalServices); |
|
37 _LIT_SECURITY_POLICY_C1( KBTEngPSKeyWritePolicy, |
|
38 ECapabilityLocalServices); |
|
39 |
|
40 // CONSTANTS |
|
41 const TInt KShutdownDelay = 5000000; |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CBTAccServer::CBTAccServer |
|
47 // C++ default constructor can NOT contain any code that |
|
48 // might leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CBTAccServer::CBTAccServer(TInt aPriority) : CPolicyServer(aPriority, KBTAccSrvPolicy) |
|
52 { |
|
53 } |
|
54 |
|
55 // Destructor |
|
56 CBTAccServer::~CBTAccServer() |
|
57 { |
|
58 delete iAccMan; |
|
59 delete iTimer; |
|
60 iSessions.Close(); |
|
61 |
|
62 RProperty::Delete( KPSUidBluetoothEnginePrivateCategory, KBTATCodec ); |
|
63 |
|
64 TRACE_FUNC |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // NewL |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 CBTAccServer* CBTAccServer::NewLC() |
|
72 { |
|
73 CBTAccServer* self=new(ELeave) CBTAccServer(EPriorityStandard); |
|
74 CleanupStack::PushL(self); |
|
75 self->ConstructL(); |
|
76 self->StartL(KBTAudioManName); |
|
77 RThread().SetPriority(EPriorityRealTime); |
|
78 return self; |
|
79 } |
|
80 |
|
81 void CBTAccServer::StartShutdownTimerIfNoSessions() |
|
82 { |
|
83 if (iSessions.Count() == 0 && (!iTimer || !iTimer->IsActive())) |
|
84 { |
|
85 if (!iTimer) |
|
86 { |
|
87 TRAP_IGNORE(iTimer = CPeriodic::NewL(CActive::EPriorityStandard)); |
|
88 } |
|
89 |
|
90 if (iTimer) |
|
91 { |
|
92 iTimer->Start(KShutdownDelay, 0, TCallBack(CBTAccServer::TimerFired, this)); |
|
93 } |
|
94 |
|
95 TRACE_FUNC |
|
96 } |
|
97 } |
|
98 |
|
99 void CBTAccServer::ClientOpened(CBTAccSession& aSession) |
|
100 { |
|
101 TRACE_FUNC |
|
102 |
|
103 //cancel the timer to prevent the server from shutting down |
|
104 CancelShutdownTimer(); |
|
105 |
|
106 //add the session to the array of sessions |
|
107 (void)iSessions.Append(&aSession); |
|
108 } |
|
109 |
|
110 void CBTAccServer::ClientClosed(CBTAccSession& aSession) |
|
111 { |
|
112 TRACE_FUNC_ENTRY |
|
113 |
|
114 //find and remove the given session from the array |
|
115 for (TUint i = 0; i < iSessions.Count(); ++i) |
|
116 { |
|
117 if (iSessions[i] == &aSession) |
|
118 { |
|
119 iSessions.Remove(i); |
|
120 break; |
|
121 } |
|
122 } |
|
123 |
|
124 StartShutdownTimerIfNoSessions(); |
|
125 TRACE_FUNC_EXIT |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // NewSessionL |
|
130 // Create session(s) to client(s) |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 CSession2* CBTAccServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const |
|
134 { |
|
135 // check we're the right version |
|
136 TVersion srvVersion(KBTAccServerMajorVersionNumber, |
|
137 KBTAccServerMinorVersionNumber, |
|
138 KBTAccServerBuildVersionNumber); |
|
139 |
|
140 if (!User::QueryVersionSupported(srvVersion, aVersion)) |
|
141 { |
|
142 User::Leave(KErrNotSupported); |
|
143 } |
|
144 |
|
145 CBTAccSession* session = CBTAccSession::NewL(*iAccMan); |
|
146 return session; |
|
147 } |
|
148 |
|
149 void CBTAccServer::ConstructL() |
|
150 { |
|
151 iAccMan = CBasrvAccMan::NewL(); |
|
152 iAccMan->LoadServicesL(); |
|
153 |
|
154 User::LeaveIfError(RProperty::Define(KPSUidBluetoothEnginePrivateCategory, |
|
155 KBTATCodec, RProperty::EByteArray, |
|
156 KBTEngPSKeyReadPolicy, |
|
157 KBTEngPSKeyWritePolicy)); |
|
158 } |
|
159 |
|
160 void CBTAccServer::CancelShutdownTimer() |
|
161 { |
|
162 delete iTimer; |
|
163 iTimer = NULL; |
|
164 } |
|
165 |
|
166 TInt CBTAccServer::TimerFired(TAny* /*aThis*/) |
|
167 { |
|
168 CActiveScheduler::Stop(); |
|
169 return KErrNone; |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------- |
|
173 // PanicClient |
|
174 // RMessage::Panic() also completes the message. |
|
175 // --------------------------------------------------------- |
|
176 void PanicClient(const RMessage2& aMessage,TInt aPanic) |
|
177 { |
|
178 TRACE_ERROR((_L("[BTAccServer]\t PanicClient: Reason: %d"), aPanic)) |
|
179 aMessage.Panic(KBTAudioManPanic,aPanic); |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------- |
|
183 // PanicServer |
|
184 // Panic our own thread |
|
185 // --------------------------------------------------------- |
|
186 void PanicServer(TInt aPanic) |
|
187 { |
|
188 TRACE_ERROR((_L("[BTAccServer]\t PanicServer: Reason: %d"), aPanic)) |
|
189 User::Panic(KBTAudioManPanic, aPanic); |
|
190 } |
|
191 |
|
192 // End of file |