|
1 /* |
|
2 * Copyright (c) 2008 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <basched.h> |
|
20 #include "fs_functor.h" |
|
21 #include "os_functionserver.h" |
|
22 #include "javasymbianoslayer.h" |
|
23 #include "logger.h" |
|
24 #include "exceptionbase.h" |
|
25 |
|
26 using namespace java::util; |
|
27 |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 |
|
32 inline OsFunctionServer::CFunctionSession::CFunctionSession() |
|
33 { |
|
34 JELOG2(EUtils); |
|
35 } |
|
36 |
|
37 TInt OsFunctionServer::CFunctionSession::doServiceL(TAction action, const TAny* param) |
|
38 { |
|
39 JELOG2(EUtils); |
|
40 switch (action) |
|
41 { |
|
42 case EExecute: |
|
43 (*static_cast<const Functor*>(param))(); // It doesn't look like it but this may leave |
|
44 return KErrNone; |
|
45 case EStop: |
|
46 ((OsFunctionServer*)Server())->startShutDown(); |
|
47 return KErrNone; |
|
48 default: |
|
49 return KErrNotSupported; |
|
50 } |
|
51 } |
|
52 |
|
53 void OsFunctionServer::CFunctionSession::ServiceL(const RMessage2& message) |
|
54 { |
|
55 JELOG2(EUtils); |
|
56 TRAPD(error, (doServiceL(static_cast<TAction>(message.Function()), message.Ptr0()))); |
|
57 if (error) |
|
58 { |
|
59 if (error == KLeaveExit) // This is used to exit the application, we obviously want to let it through |
|
60 { |
|
61 User::Leave(KLeaveExit); |
|
62 } |
|
63 } |
|
64 message.Complete(error); |
|
65 } |
|
66 |
|
67 OsFunctionServer::OsFunctionServer() |
|
68 : CServer2(EPriorityStandard, ESharableSessions) |
|
69 { |
|
70 JELOG2(EUtils); |
|
71 } |
|
72 |
|
73 OsFunctionServer::~OsFunctionServer() |
|
74 { |
|
75 JELOG2(EUtils); |
|
76 } |
|
77 void OsFunctionServer::startShutDown() |
|
78 { |
|
79 JELOG2(EUtils); |
|
80 mShutdown.startShutDown(); |
|
81 } |
|
82 |
|
83 void OsFunctionServer::startOsServer() |
|
84 { |
|
85 JELOG2(EUtils); |
|
86 TRAPD(err, StartL(KNullDesC)); |
|
87 if (err != 0) |
|
88 { |
|
89 std::string errorStr("FServer creation failed: "); |
|
90 errorStr.append(JavaCommonUtils::intToString(err)); |
|
91 throw java::util::ExceptionBase(errorStr, __FILE__, __FUNCTION__, __LINE__); |
|
92 } |
|
93 } |
|
94 |
|
95 |
|
96 // |
|
97 // Virtual methods from CServer2 |
|
98 // |
|
99 |
|
100 OS_EXPORT TInt OsFunctionServer::RunError(TInt error) |
|
101 { |
|
102 JELOG2(EUtils); |
|
103 if (error == KLeaveExit) // This is used to exit the application, we obviously want to let it through |
|
104 { |
|
105 return error; |
|
106 } |
|
107 else |
|
108 { |
|
109 return CServer2::RunError(error); |
|
110 } |
|
111 } |
|
112 |
|
113 OS_EXPORT CSession2* OsFunctionServer::NewSessionL(const TVersion& /*version*/, const RMessage2& /*message*/) const |
|
114 { |
|
115 JELOG2(EUtils); |
|
116 return new(ELeave) CFunctionSession(); |
|
117 } |
|
118 |
|
119 |
|
120 void OsFunctionServer::stopServerInsideServerThread() |
|
121 { |
|
122 JELOG2(EUtils); |
|
123 CActiveScheduler::Stop(); |
|
124 } |
|
125 |
|
126 ServerShutdown::ServerShutdown() |
|
127 : CActive(CActive::EPriorityStandard) |
|
128 { |
|
129 } |
|
130 |
|
131 void ServerShutdown::startShutDown() |
|
132 { |
|
133 CActiveScheduler::Add(this); |
|
134 iStatus=KRequestPending; |
|
135 TRequestStatus* status = &iStatus; |
|
136 User::RequestComplete(status, KErrNone); |
|
137 SetActive(); |
|
138 } |
|
139 |
|
140 |
|
141 void ServerShutdown::RunL() |
|
142 { |
|
143 JELOG2(EUtils); |
|
144 CActiveScheduler::Stop(); |
|
145 } |
|
146 |
|
147 TInt ServerShutdown::RunError(TInt error) |
|
148 { |
|
149 JELOG2(EUtils); |
|
150 if (error == KLeaveExit) |
|
151 { |
|
152 return error; |
|
153 } |
|
154 return KErrNone; |
|
155 } |
|
156 |
|
157 void ServerShutdown::DoCancel() |
|
158 { |
|
159 JELOG2(EUtils); |
|
160 // nop |
|
161 } |
|
162 |