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: snsruseractivityservice_p.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "snsruseractivityservice.h" |
|
19 #include "snsruseractivityservice_p.h" |
|
20 |
|
21 #include <activitymanager.h> |
|
22 |
|
23 const int lDefaultInactivityPeriod(5); |
|
24 |
|
25 // ======== LOCAL FUNCTIONS ======== |
|
26 |
|
27 /*! |
|
28 Called as callback to activity event. |
|
29 \param pointer to activity callback object. |
|
30 \retval error code. |
|
31 */ |
|
32 TInt activityCallback(TAny *ptr) |
|
33 { |
|
34 static_cast<SnsrUserActivityServicePrivate *>(ptr)->emitActive(); |
|
35 // activity manager doesn't care about the return value, |
|
36 // we return a value indicating 'true' to be elegant (see CIdle) |
|
37 return 1; |
|
38 } |
|
39 |
|
40 /*! |
|
41 Called as callback to inactivity event. |
|
42 \param pointer to inactivity callback object. |
|
43 \retval error code. |
|
44 */ |
|
45 TInt inactivityCallback(TAny *ptr) |
|
46 { |
|
47 static_cast<SnsrUserActivityServicePrivate *>(ptr)->emitNotActive(); |
|
48 // activity manager doesn't care about the return value, |
|
49 // we return a value indicating 'true' to be elegant (see CIdle) |
|
50 return 1; |
|
51 } |
|
52 |
|
53 // ======== MEMBER FUNCTIONS ======== |
|
54 |
|
55 /*! |
|
56 Constructor. |
|
57 \param servicePublic public implementation. |
|
58 */ |
|
59 SnsrUserActivityServicePrivate::SnsrUserActivityServicePrivate(SnsrUserActivityService *servicePublic) : |
|
60 m_q(servicePublic), mActivityManager(0), mInactivityPeriod(lDefaultInactivityPeriod) |
|
61 { |
|
62 mActivityManager = CUserActivityManager::NewL(CActive::EPriorityStandard); |
|
63 } |
|
64 |
|
65 /*! |
|
66 Destructor. |
|
67 */ |
|
68 SnsrUserActivityServicePrivate::~SnsrUserActivityServicePrivate() |
|
69 { |
|
70 delete mActivityManager; |
|
71 } |
|
72 |
|
73 /*! |
|
74 Sets the inactivity period after which to emit signal of inactivity. |
|
75 \param seconds after which inactivity is detected. |
|
76 */ |
|
77 void SnsrUserActivityServicePrivate::setInactivityPeriod(int seconds) |
|
78 { |
|
79 mInactivityPeriod = seconds; |
|
80 // activity manager panics if timeout set before start |
|
81 if (isWatching()) |
|
82 { |
|
83 mActivityManager->SetInactivityTimeout(TTimeIntervalSeconds(mInactivityPeriod)); |
|
84 } |
|
85 } |
|
86 |
|
87 /*! |
|
88 Retrives the current inactivity period setting. |
|
89 \retval inactivity period set. |
|
90 */ |
|
91 int SnsrUserActivityServicePrivate::inactivityPeriod() const |
|
92 { |
|
93 return mInactivityPeriod; |
|
94 } |
|
95 |
|
96 /*! |
|
97 Starts or stops activity manager user activity watching. |
|
98 \param shouldWatch determines if we shoul start watching or stop watching. |
|
99 */ |
|
100 void SnsrUserActivityServicePrivate::watch(bool shouldWatch) |
|
101 { |
|
102 if (shouldWatch && !isWatching()) { |
|
103 mActivityManager->Start( |
|
104 TTimeIntervalSeconds(mInactivityPeriod), |
|
105 TCallBack(inactivityCallback, this), |
|
106 TCallBack(activityCallback, this)); |
|
107 } else if (!shouldWatch && isWatching()) { |
|
108 mActivityManager->Cancel(); |
|
109 } |
|
110 } |
|
111 |
|
112 /*! |
|
113 Checks if activity service is currently watching for user activity. |
|
114 \retval true if user acitivity service is active. |
|
115 */ |
|
116 bool SnsrUserActivityServicePrivate::isWatching() const |
|
117 { |
|
118 return mActivityManager && mActivityManager->IsActive(); |
|
119 } |
|
120 |
|
121 /*! |
|
122 Emits signal that user is active. |
|
123 */ |
|
124 void SnsrUserActivityServicePrivate::emitActive() const |
|
125 { |
|
126 emit m_q->active(); |
|
127 } |
|
128 |
|
129 /*! |
|
130 Emits signal that user is not active. |
|
131 */ |
|
132 void SnsrUserActivityServicePrivate::emitNotActive() const |
|
133 { |
|
134 emit m_q->notActive(); |
|
135 } |
|