|
1 |
|
2 // Copyright (c) 2005-2009 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 // |
|
16 |
|
17 #include <e32base.h> |
|
18 #include <d32locd.h> |
|
19 #include "DummyServer.h" |
|
20 |
|
21 // The dummy server.. |
|
22 CDummyServer* CDummyServer::NewLC() |
|
23 { |
|
24 CDummyServer* self = new (ELeave) CDummyServer(); |
|
25 CleanupStack::PushL(self); |
|
26 self->ConstructL(); |
|
27 return self; |
|
28 } |
|
29 |
|
30 |
|
31 // Second-stage constructor. |
|
32 void CDummyServer::ConstructL() |
|
33 { |
|
34 StartL(KDummyServerName); |
|
35 } |
|
36 |
|
37 CDummyServer::CDummyServer() |
|
38 : CServer2(CActive::EPriorityStandard) |
|
39 { |
|
40 } |
|
41 |
|
42 CDummyServer::~CDummyServer() |
|
43 { |
|
44 |
|
45 } |
|
46 |
|
47 void CDummyServer::StopServer() |
|
48 { |
|
49 CActiveScheduler::Stop(); |
|
50 } |
|
51 |
|
52 CSession2* CDummyServer::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/) const |
|
53 { |
|
54 TVersion ver(KCountServMajorVersionNumber,KCountServMinorVersionNumber,KCountServBuildVersionNumber); |
|
55 |
|
56 if (!User::QueryVersionSupported(ver,aVersion)) |
|
57 { |
|
58 User::Leave(KErrNotSupported); |
|
59 } |
|
60 return new (ELeave) CDummyServerSession; |
|
61 } |
|
62 |
|
63 CDummyServerSession::CDummyServerSession() |
|
64 { |
|
65 } |
|
66 CDummyServerSession::~CDummyServerSession() |
|
67 { |
|
68 const CDummyServer* observer = static_cast<const CDummyServer*>(Server()); |
|
69 //Lets take out constness of this pointer |
|
70 CDummyServer* observer1 = const_cast<CDummyServer*>(observer); |
|
71 //Call the non-const member function |
|
72 observer1->StopServer(); |
|
73 } |
|
74 |
|
75 |
|
76 void CDummyServerSession::ServiceL(const RMessage2& aMessage) |
|
77 { |
|
78 |
|
79 TRAPD(err,DispatchMessageL(aMessage)); |
|
80 aMessage.Complete(err); |
|
81 } |
|
82 |
|
83 |
|
84 void CDummyServerSession::DispatchMessageL(const RMessage2& aMessage) |
|
85 { |
|
86 if(aMessage.Function() == EServGetTMsvEntry) |
|
87 { |
|
88 GetTMsvEntryL(aMessage); |
|
89 return; |
|
90 } |
|
91 } |
|
92 |
|
93 |
|
94 // Get the TMsvEntry of the message whose TMsvId is passed from the client.. |
|
95 void CDummyServerSession::GetTMsvEntryL(const RMessage2& aMessage) |
|
96 { |
|
97 CDummyObserver* ob = new(ELeave) CDummyObserver; |
|
98 CleanupStack::PushL(ob); |
|
99 |
|
100 TPckgBuf<TMsvId> idBuf; |
|
101 idBuf = aMessage.Int0(); |
|
102 |
|
103 CMsvSession* session = CMsvSession::OpenSyncL(*ob); |
|
104 CleanupStack::PushL(session); |
|
105 |
|
106 TMsvId entryId = idBuf(); |
|
107 CMsvEntry* cEntry = session->GetEntryL(entryId); |
|
108 CleanupStack::PushL(cEntry); |
|
109 |
|
110 TPckgBuf<TMsvEntry> pckg = cEntry->Entry(); |
|
111 aMessage.WriteL(1,pckg); |
|
112 |
|
113 CleanupStack::PopAndDestroy(3,ob);//cEntry,session,ob |
|
114 } |
|
115 |
|
116 |
|
117 void StartDummyServerL() |
|
118 { |
|
119 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); |
|
120 CleanupStack::PushL(scheduler); |
|
121 CActiveScheduler::Install(scheduler); |
|
122 |
|
123 // create the server (leave it on the cleanup stack) |
|
124 CDummyServer::NewLC(); |
|
125 |
|
126 // naming the server thread after the server helps to debug panics |
|
127 User::LeaveIfError(User::RenameProcess(KDummyServerName)); |
|
128 |
|
129 // initialisation complete, now signal the client. |
|
130 RProcess::Rendezvous(KErrNone); |
|
131 |
|
132 CActiveScheduler::Start(); |
|
133 CleanupStack::PopAndDestroy(2, scheduler); // server, scheduler |
|
134 } |
|
135 |
|
136 TInt E32Main() |
|
137 { |
|
138 __UHEAP_MARK; |
|
139 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
140 TInt err = KErrNoMemory; |
|
141 if (cleanup) |
|
142 { |
|
143 TRAP(err, StartDummyServerL()); |
|
144 delete cleanup; |
|
145 } |
|
146 |
|
147 __UHEAP_MARKEND; |
|
148 return err; |
|
149 } |
|
150 |