24
|
1 |
// Copyright (c) 2007-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 "cmocksysession.h"
|
|
17 |
#include "rmocksy.h"
|
|
18 |
#include "cmocksyengine.h"
|
|
19 |
|
|
20 |
|
|
21 |
/**
|
|
22 |
Panic the client.
|
|
23 |
*/
|
|
24 |
void PanicClient(const RMessagePtr2& aMessage, TMockSYPanic aPanic)
|
|
25 |
{
|
|
26 |
_LIT(KPanic,"MockSY");
|
|
27 |
aMessage.Panic(KPanic,aPanic);
|
|
28 |
}
|
|
29 |
|
|
30 |
/**
|
|
31 |
Factory function.
|
|
32 |
*/
|
|
33 |
CSession2* CMockSYSession::NewL(CMockSYEngine& aEngine)
|
|
34 |
{
|
|
35 |
CMockSYSession* self=new(ELeave) CMockSYSession(aEngine);
|
|
36 |
CleanupStack::PushL(self);
|
|
37 |
self->ConstructL();
|
|
38 |
CleanupStack::Pop(self);
|
|
39 |
return self;
|
|
40 |
}
|
|
41 |
|
|
42 |
/**
|
|
43 |
Constructor
|
|
44 |
*/
|
|
45 |
CMockSYSession::CMockSYSession(CMockSYEngine& aEngine)
|
|
46 |
:iEngine(aEngine)
|
|
47 |
{
|
|
48 |
}
|
|
49 |
|
|
50 |
/**
|
|
51 |
2nd phase construction
|
|
52 |
*/
|
|
53 |
void CMockSYSession::ConstructL()
|
|
54 |
{
|
|
55 |
iEngine.AddListenerL(*this);
|
|
56 |
}
|
|
57 |
|
|
58 |
/**
|
|
59 |
Destructor
|
|
60 |
*/
|
|
61 |
CMockSYSession::~CMockSYSession()
|
|
62 |
{
|
|
63 |
iEngine.RemoveListener(*this);
|
|
64 |
iEngine.SessionClosed();
|
|
65 |
if (!iNotifyDoneMsg.IsNull())
|
|
66 |
{
|
|
67 |
iNotifyDoneMsg.Complete(KErrCancel);
|
|
68 |
}
|
|
69 |
}
|
|
70 |
|
|
71 |
/**
|
|
72 |
Engine listener
|
|
73 |
*/
|
|
74 |
void CMockSYSession::Notify(TNotificationType aNotification)
|
|
75 |
{
|
|
76 |
switch (aNotification)
|
|
77 |
{
|
|
78 |
case EHandlingTerminated:
|
|
79 |
case EFailure:
|
|
80 |
{
|
|
81 |
if (!iNotifyDoneMsg.IsNull())
|
|
82 |
{
|
|
83 |
iNotifyDoneMsg.Complete(aNotification==EHandlingTerminated?KErrNone:KErrCorrupt);
|
|
84 |
}
|
|
85 |
}
|
|
86 |
break;
|
|
87 |
default:
|
|
88 |
; // don't care about other notifications
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
Handles the servicing of a client request that has been passed
|
|
94 |
to the server.
|
|
95 |
*/
|
|
96 |
void CMockSYSession::ServiceL(const RMessage2& aMessage)
|
|
97 |
{
|
|
98 |
switch(aMessage.Function())
|
|
99 |
{
|
|
100 |
case RMockSY::KExpect:
|
|
101 |
{
|
|
102 |
HBufC8* data = HBufC8::NewLC(aMessage.GetDesLengthL(3));
|
|
103 |
TPtr8 dataPtr = data->Des();
|
|
104 |
aMessage.ReadL(3,dataPtr);
|
|
105 |
CleanupStack::Pop(data);
|
|
106 |
iEngine.QueueEpectedCallL(aMessage.Int0(),aMessage.Int1(),aMessage.Int2(),data);
|
|
107 |
aMessage.Complete(KErrNone);
|
|
108 |
}
|
|
109 |
break;
|
|
110 |
|
|
111 |
case RMockSY::KComplete:
|
|
112 |
{
|
|
113 |
HBufC8* data = HBufC8::NewLC(aMessage.GetDesLengthL(3));
|
|
114 |
TPtr8 dataPtr = data->Des();
|
|
115 |
aMessage.ReadL(3,dataPtr);
|
|
116 |
CleanupStack::Pop(data);
|
|
117 |
iEngine.QueueReturnCallL(aMessage.Int0(),aMessage.Int1(), aMessage.Int2(),data);
|
|
118 |
aMessage.Complete(KErrNone);
|
|
119 |
}
|
|
120 |
break;
|
|
121 |
|
|
122 |
case RMockSY::KNotifyTerminated:
|
|
123 |
{
|
|
124 |
if (!iNotifyDoneMsg.IsNull())
|
|
125 |
{
|
|
126 |
PanicClient(aMessage,EPanicAlreadyReceiving);
|
|
127 |
}
|
|
128 |
else
|
|
129 |
{
|
|
130 |
iNotifyDoneMsg = aMessage;
|
|
131 |
}
|
|
132 |
}
|
|
133 |
break;
|
|
134 |
|
|
135 |
case RMockSY::KGetNextLogLine:
|
|
136 |
{
|
|
137 |
HBufC* line = iEngine.GetNextLogLine();
|
|
138 |
TInt ret;
|
|
139 |
if (line!=NULL)
|
|
140 |
{
|
|
141 |
ret=aMessage.Write(0,line->Des());
|
|
142 |
delete line;
|
|
143 |
}
|
|
144 |
else
|
|
145 |
{
|
|
146 |
ret=aMessage.Write(0,KNullDesC);
|
|
147 |
}
|
|
148 |
aMessage.Complete(ret);
|
|
149 |
}
|
|
150 |
break;
|
|
151 |
|
|
152 |
case RMockSY::KGetStatus:
|
|
153 |
{
|
|
154 |
TBool retVal;
|
|
155 |
TPckg<TBool> retValPckg(retVal);
|
|
156 |
retVal = iEngine.HasWaitingEvents();
|
|
157 |
aMessage.Write(0,retValPckg);
|
|
158 |
retVal = iEngine.HasPendingEvents();
|
|
159 |
aMessage.Write(1,retValPckg);
|
|
160 |
retVal = iEngine.HasFailure();
|
|
161 |
aMessage.Write(2,retValPckg);
|
|
162 |
aMessage.Complete(KErrNone);
|
|
163 |
}
|
|
164 |
break;
|
|
165 |
case RMockSY::KPause:
|
|
166 |
{
|
|
167 |
aMessage.Complete(iEngine.PauseCompletion());
|
|
168 |
break;
|
|
169 |
}
|
|
170 |
case RMockSY::KResume:
|
|
171 |
{
|
|
172 |
aMessage.Complete(iEngine.ResumeCompletion());
|
|
173 |
break;
|
|
174 |
}
|
|
175 |
|
|
176 |
default:
|
|
177 |
PanicClient(aMessage,EPanicIllegalFunction);
|
|
178 |
}
|
|
179 |
}
|