99
|
1 |
/*
|
|
2 |
* Copyright (c) 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 "afobservertask.h"
|
|
18 |
#include "afcmd.h"
|
|
19 |
#include "afentry.h"
|
|
20 |
// -----------------------------------------------------------------------------
|
|
21 |
/**
|
|
22 |
* Constructor for performing 1st stage construction
|
|
23 |
* @param globalStorage - global observers storage
|
|
24 |
* @param localStorage - local observers storage
|
|
25 |
* @param msg - request message
|
|
26 |
*/
|
|
27 |
CAfObserverTask::CAfObserverTask(MAfTaskStorage& globalStorage,
|
|
28 |
MAfTaskStorage& localStorage,
|
|
29 |
const RMessage2& msg)
|
|
30 |
:
|
|
31 |
mGlobalStorage(globalStorage),
|
|
32 |
mLocalStorage(localStorage),
|
|
33 |
mMsg(msg)
|
|
34 |
{
|
|
35 |
// No implementation required
|
|
36 |
}
|
|
37 |
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
/**
|
|
40 |
* Destructor.
|
|
41 |
*/
|
|
42 |
CAfObserverTask::~CAfObserverTask()
|
|
43 |
{
|
|
44 |
mData.Close();
|
|
45 |
}
|
|
46 |
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
/**
|
|
49 |
* Handle observer request.
|
|
50 |
* @param globalStorage - global observers storage
|
|
51 |
* @param localStorage - local observers storage
|
|
52 |
* @param msg - request message
|
|
53 |
*/
|
|
54 |
|
|
55 |
void CAfObserverTask::ExecuteLD(MAfTaskStorage& globalStorage,
|
|
56 |
MAfTaskStorage& localStorage,
|
|
57 |
const RMessage2& msg)
|
|
58 |
{
|
|
59 |
CAfObserverTask *self = new(ELeave)CAfObserverTask(globalStorage,
|
|
60 |
localStorage,
|
|
61 |
msg);
|
|
62 |
CleanupStack::PushL(self);
|
|
63 |
globalStorage.PushL(self);
|
|
64 |
CleanupStack::Pop(self);
|
|
65 |
}
|
|
66 |
|
|
67 |
// -----------------------------------------------------------------------------
|
|
68 |
/**
|
|
69 |
* Interface implementation
|
|
70 |
* @see CActivityTask::Data()
|
|
71 |
*/
|
|
72 |
const TDesC8& CAfObserverTask::Data() const
|
|
73 |
{
|
|
74 |
return mData;
|
|
75 |
}
|
|
76 |
|
|
77 |
// -----------------------------------------------------------------------------
|
|
78 |
/**
|
|
79 |
* Interface implementation
|
|
80 |
* @see CActivityTask::BroadcastReceivedL(const RMessage2&)
|
|
81 |
*/
|
|
82 |
void CAfObserverTask::BroadcastReceivedL(const RMessage2& msg)
|
|
83 |
{
|
|
84 |
if(EFalse != mMsg.IsNull()) {
|
|
85 |
mGlobalStorage.Pop(this);//
|
|
86 |
mLocalStorage.Pop(this);
|
|
87 |
delete this;
|
|
88 |
} else if (WaitActivity == mMsg.Function() &&
|
|
89 |
LaunchActivity == msg.Function()) {
|
|
90 |
|
|
91 |
CAfEntry* entry = CAfEntry::NewLC(msg);
|
|
92 |
TPckgBuf<TInt> observerdId;
|
|
93 |
mMsg.ReadL(KRequestAppIdOffset, observerdId);
|
|
94 |
if (observerdId() == entry->ApplicationId()) {
|
|
95 |
CAfEntry::ReallocL(mData, entry->ActivityId().Length());
|
|
96 |
mData.Copy(entry->ActivityId());
|
|
97 |
WriteResponseL();
|
|
98 |
mLocalStorage.PushL(this);
|
|
99 |
mGlobalStorage.Pop(this);
|
|
100 |
mMsg.Complete(KErrNone);
|
|
101 |
}
|
|
102 |
CleanupStack::PopAndDestroy(entry);
|
|
103 |
|
|
104 |
} else if (WaitActivity == mMsg.Function() &&
|
|
105 |
CancelWait == msg.Function() &&
|
|
106 |
mMsg.Session() == msg.Session()) {
|
|
107 |
mGlobalStorage.Pop(this);
|
|
108 |
mMsg.Complete(KErrCancel);
|
|
109 |
delete this;
|
|
110 |
} else if (NotifyChange == mMsg.Function() &&
|
|
111 |
CancelNotify == msg.Function() &&
|
|
112 |
mMsg.Session() == msg.Session()) {
|
|
113 |
mGlobalStorage.Pop(this);
|
|
114 |
mMsg.Complete(KErrCancel);
|
|
115 |
delete this;
|
|
116 |
} else if(NotifyChange == mMsg.Function() &&
|
|
117 |
(AddActivity == msg.Function() ||
|
|
118 |
UpdateActivity == msg.Function() ||
|
|
119 |
RemoveActivity == msg.Function() ||
|
|
120 |
RemoveApplicationActivities == msg.Function())){
|
|
121 |
mMsg.Complete(KErrNone);
|
|
122 |
mGlobalStorage.Pop(this);
|
|
123 |
delete this;
|
|
124 |
}
|
|
125 |
}
|
|
126 |
|
|
127 |
// -----------------------------------------------------------------------------
|
|
128 |
/**
|
|
129 |
* Write response data to requested message
|
|
130 |
*/
|
|
131 |
void CAfObserverTask::WriteResponseL()
|
|
132 |
{
|
|
133 |
mMsg.WriteL(KResponseDataSizeOffset, TPckgBuf<TInt>(mData.Length()));//write data size
|
|
134 |
mMsg.WriteL(KResponseIdOffset, TPckgBuf<CBase*>(this));//task identyfier
|
|
135 |
}
|
|
136 |
|
|
137 |
// -----------------------------------------------------------------------------
|
|
138 |
/**
|
|
139 |
* Returns ETrue if task is related with session argument
|
|
140 |
*/
|
|
141 |
TBool CAfObserverTask::IsSessionTask(const CSession2* session)
|
|
142 |
{
|
|
143 |
return mMsg.Session() == session ? ETrue : EFalse;
|
|
144 |
}
|