5
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 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 the License "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: class implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <activitymanager.h>
|
|
19 |
|
|
20 |
#include "sysinfoservice.h"
|
|
21 |
#include "sysuseractivity.h"
|
|
22 |
#include "entitykeys.h"
|
|
23 |
#include "sysrequest.h"
|
|
24 |
|
|
25 |
using namespace SysInfo;
|
|
26 |
// --------------------------------------------------------------------
|
|
27 |
// CUserActivity::CUserActivity()
|
|
28 |
// C++ default constructor.
|
|
29 |
// --------------------------------------------------------------------
|
|
30 |
//
|
|
31 |
CUserActivity::CUserActivity( TSysRequest::TRequestType aReqType,
|
|
32 |
TInt32 aTransID,ISystemObserver* aObsrvr )
|
|
33 |
:CActiveRequest(aReqType,aTransID,aObsrvr)
|
|
34 |
{
|
|
35 |
|
|
36 |
}
|
|
37 |
|
|
38 |
// --------------------------------------------------------------------
|
|
39 |
// CUserActivity::~CUserActivity()
|
|
40 |
// Destructor.
|
|
41 |
// --------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
CUserActivity::~CUserActivity()
|
|
44 |
{
|
|
45 |
delete iActivityManager;
|
|
46 |
}
|
|
47 |
|
|
48 |
// --------------------------------------------------------------------
|
|
49 |
// CUserActivity::NewL()
|
|
50 |
// Two-phased constructor, returns instance of this class.
|
|
51 |
// --------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
CUserActivity* CUserActivity::NewL(const TSysRequest& aRequest)
|
|
54 |
{
|
|
55 |
CUserActivity* self;
|
|
56 |
self = new (ELeave) CUserActivity(aRequest.RequestType(),
|
|
57 |
aRequest.TransactionID(),aRequest.Observer());
|
|
58 |
|
|
59 |
CleanupStack::PushL(self);
|
|
60 |
self->ConstructL (aRequest);
|
|
61 |
CleanupStack::Pop(self);
|
|
62 |
|
|
63 |
return self;
|
|
64 |
}
|
|
65 |
|
|
66 |
// --------------------------------------------------------------------
|
|
67 |
// CUserActivity::ConstructL()
|
|
68 |
// 2nd Phase constructor to allocate required resources for this obj.
|
|
69 |
// --------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
void CUserActivity::ConstructL(const TSysRequest& aRequest)
|
|
72 |
{
|
|
73 |
//supportes only notifications.
|
|
74 |
if(TSysRequest::ENotification != RequestType())
|
|
75 |
User::Leave(KErrNotSupported);
|
|
76 |
|
|
77 |
//Validate input data. this is mandatatory input.
|
|
78 |
const CSysData* Input = aRequest.SystemData();
|
|
79 |
if(Input)
|
|
80 |
{
|
|
81 |
if( CSysData::EStatus == Input->DataType() )
|
|
82 |
iTimeout = ((CStatus*)Input)->Status();
|
|
83 |
else
|
|
84 |
User::Leave(KErrArgument);
|
|
85 |
}
|
|
86 |
else
|
|
87 |
User::Leave(KErrArgument);
|
|
88 |
|
|
89 |
iActivityManager = CUserActivityManager::NewL( CActive::EPriorityStandard );
|
|
90 |
}
|
|
91 |
|
|
92 |
// --------------------------------------------------------------------
|
|
93 |
// CUserActivity::Request()
|
|
94 |
// Issues user activity notification request.
|
|
95 |
// --------------------------------------------------------------------
|
|
96 |
//
|
|
97 |
TInt CUserActivity::Request()
|
|
98 |
{
|
|
99 |
if(iTimeout <= 0)
|
|
100 |
return KErrArgument;
|
|
101 |
else
|
|
102 |
{
|
|
103 |
if( !iActivityManager->IsActive() )
|
|
104 |
iActivityManager->Start(iTimeout,
|
|
105 |
TCallBack(HandleInactiveEventL,this ),
|
|
106 |
TCallBack(HandleActiveEventL, this ) );
|
|
107 |
|
|
108 |
return KErrNone;
|
|
109 |
}
|
|
110 |
}
|
|
111 |
|
|
112 |
// --------------------------------------------------------------------
|
|
113 |
// CUserActivity::RunL()
|
|
114 |
// never been called. This is not an active object implementation.
|
|
115 |
// --------------------------------------------------------------------
|
|
116 |
//
|
|
117 |
void CUserActivity::RunL()
|
|
118 |
{
|
|
119 |
User::Leave(KErrGeneral);
|
|
120 |
}
|
|
121 |
|
|
122 |
// --------------------------------------------------------------------
|
|
123 |
// CUserActivity::DoCancel()
|
|
124 |
// never been called. This is not an active object implementation.
|
|
125 |
// --------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
void CUserActivity::DoCancel()
|
|
128 |
{
|
|
129 |
}
|
|
130 |
|
|
131 |
// --------------------------------------------------------------------
|
|
132 |
// CUserActivity::HandleInactiveEventL()
|
|
133 |
// call back handle to handle In activity event.
|
|
134 |
// --------------------------------------------------------------------
|
|
135 |
//
|
|
136 |
TInt CUserActivity::HandleInactiveEventL(TAny* aPtr)
|
|
137 |
{
|
|
138 |
((CUserActivity*)aPtr)->HandleReqResponseL(EUSERINACTIVITY);
|
|
139 |
return KErrNone;
|
|
140 |
}
|
|
141 |
|
|
142 |
// --------------------------------------------------------------------
|
|
143 |
// CUserActivity::HandleActiveEventL()
|
|
144 |
// call back handle to handle user activity event.
|
|
145 |
// --------------------------------------------------------------------
|
|
146 |
//
|
|
147 |
TInt CUserActivity::HandleActiveEventL(TAny* aPtr)
|
|
148 |
{
|
|
149 |
((CUserActivity*)aPtr)->HandleReqResponseL(EUSERACTIVITY);
|
|
150 |
return KErrNone;
|
|
151 |
}
|
|
152 |
|
|
153 |
// --------------------------------------------------------------------
|
|
154 |
// CUserActivity::HandleReqResponseL()
|
|
155 |
// gets called whenever an user activity/inactivity event triggered.
|
|
156 |
// --------------------------------------------------------------------
|
|
157 |
//
|
|
158 |
void CUserActivity::HandleReqResponseL(TEvent aEvent)
|
|
159 |
{
|
|
160 |
CStatus* status = CStatus::NewL(aEvent);
|
|
161 |
CleanupStack::PushL(status);
|
|
162 |
|
|
163 |
TRAP_IGNORE(SystemObserver()->HandleResponseL(KDisplay, KUserInactivity,
|
|
164 |
status, TransactionID(), RequestType()));
|
|
165 |
|
|
166 |
CleanupStack::Pop(status);
|
|
167 |
}
|
|
168 |
|
|
169 |
// End of file.
|