116
|
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 "tsrunningappsession.h"
|
|
18 |
#include "tstaskmonitorglobals.h"
|
|
19 |
|
|
20 |
#include "tsdataobservertask.h"
|
|
21 |
#include "tsdataprovidertask.h"
|
|
22 |
#include "tsdatatask.h"
|
|
23 |
|
|
24 |
_LIT(KErrObserverExists, "Observer already exists");
|
|
25 |
// -----------------------------------------------------------------------------
|
|
26 |
/**
|
|
27 |
* Constructor for performing 1st stage construction
|
|
28 |
*/
|
|
29 |
CTsRunningAppSession::CTsRunningAppSession(
|
|
30 |
const MTsDataProvider& aDataProvider )
|
|
31 |
:
|
|
32 |
iDataProvider(aDataProvider)
|
|
33 |
{
|
|
34 |
// No implementation required
|
|
35 |
}
|
|
36 |
|
|
37 |
// -----------------------------------------------------------------------------
|
|
38 |
/**
|
|
39 |
* Destructor.
|
|
40 |
*/
|
|
41 |
CTsRunningAppSession::~CTsRunningAppSession()
|
|
42 |
{
|
|
43 |
iDataStorages.Close();
|
|
44 |
iObservers.ResetAndDestroy();
|
|
45 |
}
|
|
46 |
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
/**
|
|
49 |
* Two-phased constructor.
|
|
50 |
* @param aObserverStorage - observers storage
|
|
51 |
* @param aDataProvider - serialized data provider
|
|
52 |
* @param aDataStorages - data storages
|
|
53 |
*/
|
|
54 |
CTsRunningAppSession* CTsRunningAppSession::NewL(
|
|
55 |
const MTsDataProvider& aDataProvider,
|
|
56 |
const TArray<MTsDataStorage*> &aDataStorages )
|
|
57 |
{
|
|
58 |
CTsRunningAppSession* self =
|
|
59 |
new (ELeave) CTsRunningAppSession( aDataProvider );
|
|
60 |
CleanupStack::PushL( self );
|
|
61 |
self->ConstructL( aDataStorages );
|
|
62 |
CleanupStack::Pop( self );
|
|
63 |
return self;
|
|
64 |
}
|
|
65 |
|
|
66 |
// -----------------------------------------------------------------------------
|
|
67 |
/**
|
|
68 |
* EPOC default constructor for performing 2nd stage construction
|
|
69 |
*/
|
|
70 |
void CTsRunningAppSession::ConstructL(
|
|
71 |
const TArray<MTsDataStorage*> &aDataStorages )
|
|
72 |
{
|
|
73 |
for( TInt iter(0); iter < aDataStorages.Count(); ++iter )
|
|
74 |
{
|
|
75 |
iDataStorages.AppendL( aDataStorages[iter] );
|
|
76 |
}
|
|
77 |
}
|
|
78 |
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
/**
|
|
81 |
* Implements interface
|
|
82 |
* @see void CSession2::ServiceL(const RMessage2&)
|
|
83 |
*/
|
|
84 |
void CTsRunningAppSession::ServiceL(const RMessage2& aMessage)
|
|
85 |
{
|
|
86 |
switch ( aMessage.Function() )
|
|
87 |
{
|
|
88 |
case SubscribeRunningAppChanges:
|
|
89 |
CTsDataObserverTask::ExecuteLD( *this, aMessage );
|
|
90 |
break;
|
|
91 |
|
|
92 |
case CancelSubscribeRunningAppChanges:
|
|
93 |
iObservers.ResetAndDestroy();
|
|
94 |
aMessage.Complete(KErrNone);
|
|
95 |
break;
|
|
96 |
|
|
97 |
case GetRunningAppInfo:
|
|
98 |
case FlushData:
|
|
99 |
TsDataProviderTask::ExecuteL( iDataProvider, aMessage );
|
|
100 |
break;
|
|
101 |
|
|
102 |
case RegisterScreenshotMessage:
|
|
103 |
case UnregisterScreenshotMessage:
|
|
104 |
case VisibilityChange:
|
|
105 |
case OpenTaskMessage:
|
|
106 |
case CloseTaskMessage:
|
|
107 |
TsDataTask::ExecuteL( iDataStorages.Array(), aMessage );
|
|
108 |
break;
|
|
109 |
|
|
110 |
default:
|
|
111 |
aMessage.Complete(CServer2::EBadMessageNumber);
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
|
115 |
// -----------------------------------------------------------------------------
|
|
116 |
/**
|
|
117 |
* Implements interface
|
|
118 |
* @see void MTsDataObserver::DataChanged()
|
|
119 |
*/
|
|
120 |
void CTsRunningAppSession::DataChanged()
|
|
121 |
{
|
|
122 |
TInt iter(iObservers.Count()-1);
|
|
123 |
iMissedDataUpdate = ( iter < 0 );
|
|
124 |
for( ; iter >= 0; --iter )
|
|
125 |
{
|
|
126 |
iObservers[iter]->DataChanged();
|
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
// -----------------------------------------------------------------------------
|
|
131 |
/**
|
|
132 |
* Implements interface
|
|
133 |
* @see void MTsDataObserverStorage::PushL(CTsDataObserver*)
|
|
134 |
*/
|
|
135 |
void CTsRunningAppSession::PushL(CTsDataObserver* aObserver)
|
|
136 |
{
|
|
137 |
( 0 <= iObservers.Find( aObserver ) ) ?
|
|
138 |
User::Panic( KErrObserverExists, KErrAlreadyExists ) :
|
|
139 |
iObservers.AppendL( aObserver );
|
|
140 |
if( iMissedDataUpdate )
|
|
141 |
{
|
|
142 |
aObserver->DataChanged();
|
|
143 |
iMissedDataUpdate = EFalse;
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
// -----------------------------------------------------------------------------
|
|
148 |
/**
|
|
149 |
* Implements interface
|
|
150 |
* @see void MTsDataObserverStorage::Pop(CTsDataObserver*)
|
|
151 |
*/
|
|
152 |
void CTsRunningAppSession::Pop(CTsDataObserver* aObserver)
|
|
153 |
{
|
|
154 |
const TInt offset( iObservers.Find( aObserver ) );
|
|
155 |
if( 0 <= offset )
|
|
156 |
{
|
|
157 |
iObservers.Remove(offset);
|
|
158 |
}
|
|
159 |
}
|