|
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: DiagnosticImpl provides implementation for JavaDiagnostic |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "diagnosticimpl.h" |
|
20 #include "javaredirectserver.h" |
|
21 using namespace java::debug; |
|
22 |
|
23 _LIT(KJavaRedirectThread,"JavaRedirectServerThread"); |
|
24 const int REDIRECT_THREAD_STACK_SIZE = 0x5000; |
|
25 |
|
26 DiagnosticImpl::DiagnosticImpl() : CActive(EPriorityStandard), mListener(0) |
|
27 { |
|
28 } |
|
29 |
|
30 DiagnosticImpl::~DiagnosticImpl() |
|
31 { |
|
32 stop(); |
|
33 } |
|
34 |
|
35 TInt DiagnosticImpl::setDiagnosticListener(DiagnosticListener& aListener) |
|
36 { |
|
37 TInt rc = KErrAlreadyExists; |
|
38 if (!mListener) |
|
39 { |
|
40 mListener = &aListener; |
|
41 rc = start(); |
|
42 if (rc != KErrNone) |
|
43 { |
|
44 mListener = 0; |
|
45 } |
|
46 } |
|
47 return rc; |
|
48 } |
|
49 |
|
50 void DiagnosticImpl::removeDiagnosticListener() |
|
51 { |
|
52 stop(); |
|
53 mListener = 0; |
|
54 } |
|
55 |
|
56 TInt DiagnosticImpl::start() |
|
57 { |
|
58 TInt rc = mThread.Create( |
|
59 KJavaRedirectThread, |
|
60 reinterpret_cast<TThreadFunction>(messageLoop), |
|
61 REDIRECT_THREAD_STACK_SIZE, |
|
62 NULL, |
|
63 this); |
|
64 |
|
65 if (rc == KErrNone) |
|
66 { |
|
67 // block until thread has been started ok |
|
68 TRequestStatus rendezvousStatus; |
|
69 mThread.Rendezvous(rendezvousStatus); |
|
70 mThread.Resume(); |
|
71 User::WaitForRequest(rendezvousStatus); |
|
72 rc = rendezvousStatus.Int(); |
|
73 } |
|
74 return rc; |
|
75 } |
|
76 |
|
77 void DiagnosticImpl::stop() |
|
78 { |
|
79 if (mListener) |
|
80 { |
|
81 TRequestStatus status; |
|
82 mThread.Logon(status); |
|
83 |
|
84 TRequestStatus* istatus = &iStatus; |
|
85 mThread.RequestComplete(istatus, KErrNone); |
|
86 |
|
87 User::WaitForRequest(status); |
|
88 mThread.Close(); |
|
89 } |
|
90 } |
|
91 |
|
92 void DiagnosticImpl::messageLoop(TAny* aArgs) |
|
93 { |
|
94 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
95 TInt r = KErrNoMemory; |
|
96 if (cleanup) |
|
97 { |
|
98 DiagnosticImpl* me = reinterpret_cast<DiagnosticImpl*>(aArgs); |
|
99 TRAP(r,me->runServerL()); |
|
100 } |
|
101 |
|
102 RThread::Rendezvous(r); |
|
103 delete cleanup; |
|
104 } |
|
105 |
|
106 void DiagnosticImpl::runServerL() |
|
107 { |
|
108 CActiveScheduler* s = new(ELeave) CActiveScheduler; |
|
109 CleanupStack::PushL(s); |
|
110 CActiveScheduler::Install(s); |
|
111 |
|
112 java::util::CRedirectServer* server = new(ELeave) java::util::CRedirectServer(*this); |
|
113 CleanupStack::PushL(server); |
|
114 |
|
115 server->StartL(); |
|
116 |
|
117 CActiveScheduler::Add(this); |
|
118 iStatus = KRequestPending; |
|
119 SetActive(); |
|
120 |
|
121 RThread::Rendezvous(KErrNone); |
|
122 CActiveScheduler::Start(); |
|
123 |
|
124 CleanupStack::PopAndDestroy(server); |
|
125 CleanupStack::PopAndDestroy(s); |
|
126 } |
|
127 |
|
128 void DiagnosticImpl::RunL() |
|
129 { |
|
130 CActiveScheduler::Stop(); |
|
131 } |
|
132 |
|
133 void DiagnosticImpl::DoCancel() |
|
134 { |
|
135 } |
|
136 |
|
137 TInt DiagnosticImpl::RunError(TInt /*aError*/) |
|
138 { |
|
139 return KErrNone; |
|
140 } |
|
141 |
|
142 void DiagnosticImpl::systemOut(const TDesC8& aData) |
|
143 { |
|
144 mListener->systemOut(aData); |
|
145 } |
|
146 |
|
147 void DiagnosticImpl::systemErr(const TDesC8& aData) |
|
148 { |
|
149 mListener->systemErr(aData); |
|
150 } |
|
151 |
|
152 void DiagnosticImpl::log(const TDesC8& aData) |
|
153 { |
|
154 mListener->log(aData); |
|
155 } |