|
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: locationfunctionserver |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef LOCATIONFUNCTIONSERVER_H |
|
20 #define LOCATIONFUNCTIONSERVER_H |
|
21 |
|
22 #include "monitor.h" |
|
23 #include "functionserver.h" |
|
24 #include "legacyeventserverwrapper.h" |
|
25 |
|
26 namespace java |
|
27 { |
|
28 namespace location |
|
29 { |
|
30 |
|
31 /** |
|
32 * If we have to execute some operation that essentially |
|
33 * needs ActiveScheduler, then we use this LocationFunctionServer. |
|
34 * |
|
35 * We must however be careful not to make callbacks through FunctionServer. |
|
36 * Reason: If in callback, app calls another method that needs FunctionServer |
|
37 * to execute, we enter a deadlock. |
|
38 */ |
|
39 |
|
40 class LocationFunctionServer: public java::util::FunctionServer, |
|
41 public LegacyEventServerWrapper |
|
42 { |
|
43 public: |
|
44 |
|
45 //Making these inline as it has nothing more to implement. |
|
46 //If implementation grows, then we write separate cpp |
|
47 |
|
48 LocationFunctionServer(JNIEnv& env, jobject peer) : |
|
49 java::util::FunctionServer("JavaLocationFunctionServer"), mVmAttached( |
|
50 false) |
|
51 { |
|
52 JELOG2(EJavaLocation); |
|
53 |
|
54 //Creates a new thread and starts active scheduler |
|
55 //This results in call to doServerSideInit() |
|
56 createServerToNewThread(); |
|
57 attachToVm(env, peer); |
|
58 mVmAttached = true; |
|
59 iServer = reinterpret_cast<java::util::FunctionServer*>(this); |
|
60 } |
|
61 |
|
62 LocationFunctionServer() : |
|
63 java::util::FunctionServer("JavaLocationFunctionServer"), mVmAttached( |
|
64 false) |
|
65 { |
|
66 JELOG2(EJavaLocation); |
|
67 |
|
68 //Creates a new thread and starts active scheduler |
|
69 //This results in call to doServerSideInit() |
|
70 createServerToNewThread(); |
|
71 iServer = reinterpret_cast<java::util::FunctionServer*>(this); |
|
72 } |
|
73 |
|
74 /** |
|
75 * If we are making any callback in FunctionServer thread context, then we |
|
76 * must query for the Thread specific JNI Environment variable. |
|
77 * This function that gives JNI environment variable specific to |
|
78 * Location Function Server thread. |
|
79 */ |
|
80 JNIEnv* getValidJniEnv() |
|
81 { |
|
82 JELOG2(EJavaLocation); |
|
83 return mJniEnv; |
|
84 } |
|
85 |
|
86 jobject getPeer() |
|
87 { |
|
88 return mJavaPeerObject; |
|
89 } |
|
90 |
|
91 ~LocationFunctionServer() |
|
92 { |
|
93 JELOG2(EJavaLocation); |
|
94 if (mVmAttached) |
|
95 { |
|
96 detachFromVm(); |
|
97 } |
|
98 stopServer(); |
|
99 } |
|
100 |
|
101 java::util::FunctionServer* getFunctionServer() const |
|
102 { |
|
103 JELOG2(EJavaLocation); |
|
104 return iServer; |
|
105 } |
|
106 |
|
107 private: |
|
108 void doServerSideInit() |
|
109 { |
|
110 JELOG2(EJavaLocation); |
|
111 FunctionServer::doServerSideInit(); |
|
112 } |
|
113 |
|
114 void vmDetached() |
|
115 { |
|
116 JELOG2(EJavaLocation); |
|
117 FunctionServer::vmDetached(); |
|
118 } |
|
119 private: |
|
120 bool mVmAttached; |
|
121 java::util::FunctionServer* iServer; |
|
122 }; |
|
123 |
|
124 } //end namespace location |
|
125 } //end namespace java |
|
126 |
|
127 #endif // LOCATIONFUNCTIONSERVER_H |