sl@0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "openwfcthreadmanager.h"
|
sl@0
|
17 |
#include "openwfcjobmanager.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
COpenWfcMonitorThread::COpenWfcMonitorThread(COpenWfcJobManger& aManager):
|
sl@0
|
21 |
iEndThread(EFalse),
|
sl@0
|
22 |
iManager(aManager)
|
sl@0
|
23 |
{
|
sl@0
|
24 |
|
sl@0
|
25 |
}
|
sl@0
|
26 |
|
sl@0
|
27 |
COpenWfcMonitorThread::~COpenWfcMonitorThread()
|
sl@0
|
28 |
{
|
sl@0
|
29 |
EndThread();
|
sl@0
|
30 |
TRequestStatus threadDies = KErrNone;
|
sl@0
|
31 |
iThread.Resume();
|
sl@0
|
32 |
iThread.Logon(threadDies);
|
sl@0
|
33 |
if (iThread.ExitType() == EExitPending ||
|
sl@0
|
34 |
threadDies != KRequestPending)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
User::WaitForRequest(threadDies);
|
sl@0
|
37 |
}
|
sl@0
|
38 |
iThread.Close();
|
sl@0
|
39 |
iSemaphore.Close();
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
void COpenWfcMonitorThread::ConstructL(TInt aScreenNumber)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
TBuf <255> threadManagerName;
|
sl@0
|
45 |
/*
|
sl@0
|
46 |
* At a given instant in time, one screen can have at most one monitor
|
sl@0
|
47 |
* thread. Test code will, for a given screen, destroy and re-create
|
sl@0
|
48 |
* the monitor thread.
|
sl@0
|
49 |
*
|
sl@0
|
50 |
* At appears that the thread, once killed off, still lingers in
|
sl@0
|
51 |
* the OS for a short time. The newly created thread fails to create
|
sl@0
|
52 |
* if it shares the same name as the one that was killed but still is
|
sl@0
|
53 |
* lingering around.
|
sl@0
|
54 |
*
|
sl@0
|
55 |
* A unique name is needed. This is guaranteed by using a thread name
|
sl@0
|
56 |
* which includes a microsecond counter. This counter wraps every hour,
|
sl@0
|
57 |
* roughly. This is comfortably outside the race condition above.
|
sl@0
|
58 |
*
|
sl@0
|
59 |
* To make debugging easier, we also include the screen number in
|
sl@0
|
60 |
* the thread name.
|
sl@0
|
61 |
*
|
sl@0
|
62 |
* Thus, the thread name is:
|
sl@0
|
63 |
* WFCMonitorThread_<ScreenNumber>_<MicrosecondCounter>
|
sl@0
|
64 |
*/
|
sl@0
|
65 |
_LIT(KThreadName, "WFCMonitorThread_%d_%d");
|
sl@0
|
66 |
TTime now;
|
sl@0
|
67 |
now.UniversalTime();
|
sl@0
|
68 |
TInt microseconds = I64LOW(now.Int64());
|
sl@0
|
69 |
threadManagerName.Format(KThreadName, aScreenNumber, microseconds);
|
sl@0
|
70 |
|
sl@0
|
71 |
User::LeaveIfError(iThread.Create(threadManagerName,
|
sl@0
|
72 |
static_cast<TThreadFunction>(&COpenWfcMonitorThread::Main),
|
sl@0
|
73 |
KDefaultStackSize,
|
sl@0
|
74 |
NULL,
|
sl@0
|
75 |
this,
|
sl@0
|
76 |
EOwnerProcess));
|
sl@0
|
77 |
iThread.SetPriority(EPriorityNormal);
|
sl@0
|
78 |
User::LeaveIfError(iSemaphore.CreateLocal(0));
|
sl@0
|
79 |
Start();
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
COpenWfcMonitorThread* COpenWfcMonitorThread::NewLC(TInt aNumber, COpenWfcJobManger& aManager)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
COpenWfcMonitorThread* self = new(ELeave) COpenWfcMonitorThread(aManager);
|
sl@0
|
85 |
CleanupStack::PushL(self);
|
sl@0
|
86 |
self->ConstructL(aNumber);
|
sl@0
|
87 |
return(self);
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
COpenWfcMonitorThread* COpenWfcMonitorThread::NewL(TInt aNumber, COpenWfcJobManger& aManager)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
COpenWfcMonitorThread* self = COpenWfcMonitorThread::NewLC(aNumber, aManager);
|
sl@0
|
93 |
CleanupStack::Pop(self);
|
sl@0
|
94 |
return self;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
TInt COpenWfcMonitorThread::Main(TAny *aSelf)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
COpenWfcMonitorThread* self = static_cast<COpenWfcMonitorThread*>(aSelf);
|
sl@0
|
100 |
return self->Run();
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
void COpenWfcMonitorThread::Start()
|
sl@0
|
104 |
{
|
sl@0
|
105 |
iThread.Rendezvous(iThreadStatus);
|
sl@0
|
106 |
iThread.Resume();
|
sl@0
|
107 |
User::WaitForRequest(iThreadStatus);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
void COpenWfcMonitorThread::Resume()
|
sl@0
|
111 |
{
|
sl@0
|
112 |
iThread.Resume();
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
void COpenWfcMonitorThread::EndThread()
|
sl@0
|
116 |
{
|
sl@0
|
117 |
iSemaphore.Signal();
|
sl@0
|
118 |
iEndThread = ETrue;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
void COpenWfcMonitorThread::Suspend()
|
sl@0
|
122 |
{
|
sl@0
|
123 |
iThread.Suspend();
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
void COpenWfcMonitorThread::Signal()
|
sl@0
|
127 |
{
|
sl@0
|
128 |
iSemaphore.Signal();
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
TInt COpenWfcMonitorThread::Run()
|
sl@0
|
132 |
{
|
sl@0
|
133 |
RThread::Rendezvous(KErrNone);
|
sl@0
|
134 |
JQLOG(("** START * COpenWfcMonitorThread::Run()"));
|
sl@0
|
135 |
while(!iEndThread)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
JQLOG(("** WAIT FOR SIGNAL * CCOpenwfcMonitorThread::Run()"));
|
sl@0
|
138 |
iSemaphore.Wait();
|
sl@0
|
139 |
|
sl@0
|
140 |
if (!iEndThread)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
iManager.DoExecuteJob();
|
sl@0
|
143 |
}
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
/* Release any use of EGL by this thread. */
|
sl@0
|
147 |
eglReleaseThread();
|
sl@0
|
148 |
|
sl@0
|
149 |
JQLOG(("** EXIT * COpenWfcMonitorThread::Run()"));
|
sl@0
|
150 |
return KErrNone;
|
sl@0
|
151 |
}
|