|
1 // btserialserver.cpp |
|
2 // |
|
3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include "btserialserver.h" |
|
14 #include "btserialsession.h" |
|
15 #include <fshell/btincomingserial.h> |
|
16 |
|
17 static void RunServerL(RServer2* aServerPtr) |
|
18 // |
|
19 // Perform all server initialisation, in particular creation of the |
|
20 // scheduler and server and then run the scheduler |
|
21 // |
|
22 { |
|
23 // naming the server thread after the server helps to debug panics |
|
24 User::LeaveIfError(RThread::RenameMe(KBtSerialServerThreadName)); |
|
25 // |
|
26 // create and install the active scheduler we need |
|
27 CActiveScheduler* s=new(ELeave) CActiveScheduler; |
|
28 CleanupStack::PushL(s); |
|
29 CActiveScheduler::Install(s); |
|
30 // |
|
31 // create the server (leave it on the cleanup stack) |
|
32 CServer2* server = CBtSerialServer::NewLC(); |
|
33 *aServerPtr = server->Server(); |
|
34 // |
|
35 // Initialisation complete, now signal the client |
|
36 RThread::Rendezvous(KErrNone); |
|
37 // |
|
38 // Ready to run |
|
39 CActiveScheduler::Start(); |
|
40 // |
|
41 // Cleanup the server and scheduler |
|
42 CleanupStack::PopAndDestroy(2); |
|
43 } |
|
44 |
|
45 TInt ServerThread(TAny* aRServerPtr) |
|
46 // |
|
47 // Server process entry-point |
|
48 // |
|
49 { |
|
50 __UHEAP_MARK; |
|
51 // |
|
52 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
53 TInt r=KErrNoMemory; |
|
54 if (cleanup) |
|
55 { |
|
56 RServer2* serverPtr = static_cast<RServer2*>(aRServerPtr); |
|
57 |
|
58 TRAP(r,RunServerL(serverPtr)); |
|
59 delete cleanup; |
|
60 } |
|
61 // |
|
62 __UHEAP_MARKEND; |
|
63 return r; |
|
64 } |
|
65 |
|
66 //______________________________________________________________________________ |
|
67 // CBtSerialServer |
|
68 CServer2* CBtSerialServer::NewLC() |
|
69 { |
|
70 CBtSerialServer* self=new(ELeave) CBtSerialServer; |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 inline CBtSerialServer::CBtSerialServer() |
|
77 :CServer2(0,EUnsharableSessions) |
|
78 { |
|
79 } |
|
80 |
|
81 |
|
82 |
|
83 void CBtSerialServer::ConstructL() |
|
84 { |
|
85 StartL(KNullDesC); |
|
86 } |
|
87 |
|
88 |
|
89 CSession2* CBtSerialServer::NewSessionL(const TVersion&,const RMessage2&) const |
|
90 { |
|
91 if (iSession) |
|
92 { |
|
93 User::Leave(KErrAlreadyExists); |
|
94 } |
|
95 const_cast<CBtSerialServer*>(this)->iSession = new(ELeave) CBtSerialSession(); |
|
96 return iSession; |
|
97 } |
|
98 |
|
99 void CBtSerialServer::DropSession() |
|
100 { |
|
101 iSession = NULL; |
|
102 CActiveScheduler::Stop(); |
|
103 } |
|
104 |