|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef BLUETOOTHFUNCTIONSERVER_H |
|
20 #define BLUETOOTHFUNCTIONSERVER_H |
|
21 |
|
22 #include "monitor.h" |
|
23 #include "functionserver.h" |
|
24 |
|
25 namespace java |
|
26 { |
|
27 namespace bluetooth |
|
28 { |
|
29 |
|
30 /** |
|
31 * BluetoothFunctionServer will be created when BluetoothStackS60 is created. |
|
32 * Handle of this will be stored in Java side and will be passed to native |
|
33 * calls that need this. If we have to execute some operation that essentially |
|
34 * needs ActiveScheduler, then we use this. |
|
35 * |
|
36 * We must however be careful not to make callbacks through FunctionServer. |
|
37 * Reason: If in callback, app calls another method that needs FunctionServer |
|
38 * to execute, we enter a deadlock. |
|
39 */ |
|
40 |
|
41 class BluetoothFunctionServer: public java::util::FunctionServer |
|
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 BluetoothFunctionServer(JNIEnv& env, jobject peer) : |
|
49 java::util::FunctionServer("JavaBluetoothFunctionServer") |
|
50 { |
|
51 JELOG2(EJavaBluetooth); |
|
52 |
|
53 //Creates a new thread and starts active scheduler |
|
54 //This results in call to doServerSideInit() |
|
55 createServerToNewThread(); |
|
56 attachToVm(env, peer); |
|
57 mAttachedToVm = true; |
|
58 } |
|
59 |
|
60 BluetoothFunctionServer() : |
|
61 java::util::FunctionServer("JavaBluetoothPushFunctionServer") |
|
62 { |
|
63 JELOG2(EJavaBluetooth); |
|
64 |
|
65 //Creates a new thread and starts active scheduler |
|
66 //This results in call to doServerSideInit() |
|
67 createServerToNewThread(); |
|
68 mAttachedToVm = false; |
|
69 } |
|
70 |
|
71 /** |
|
72 * If we are making any callback in FunctionServer thread context, then we |
|
73 * must query for the Thread specific JNI Environment variable. |
|
74 * This function that gives JNI environment variable specific to |
|
75 * Bluetooth Function Server thread. |
|
76 */ |
|
77 JNIEnv* getValidJniEnv() |
|
78 { |
|
79 return mJniEnv; |
|
80 } |
|
81 |
|
82 jobject getPeer() |
|
83 { |
|
84 return mJavaPeerObject; |
|
85 } |
|
86 |
|
87 void attach(JNIEnv* jni, jobject peer) |
|
88 { |
|
89 attachToVm(*jni, peer); |
|
90 mAttachedToVm = true; |
|
91 } |
|
92 |
|
93 bool attachedToVm() |
|
94 { |
|
95 return mAttachedToVm; |
|
96 } |
|
97 |
|
98 ~BluetoothFunctionServer() |
|
99 { |
|
100 if (mAttachedToVm) |
|
101 { |
|
102 detachFromVm(); |
|
103 } |
|
104 stopServer(); |
|
105 } |
|
106 |
|
107 private: |
|
108 void doServerSideInit() |
|
109 { |
|
110 JELOG2(EJavaBluetooth); |
|
111 FunctionServer::doServerSideInit(); |
|
112 //Nothing needs to be done here. |
|
113 } |
|
114 |
|
115 void vmDetached() |
|
116 { |
|
117 JELOG2(EJavaBluetooth); |
|
118 FunctionServer::vmDetached(); |
|
119 } |
|
120 |
|
121 //We can execute methods in Function server context using |
|
122 //CallMethodL() calls. |
|
123 |
|
124 private: |
|
125 bool mAttachedToVm; |
|
126 }; |
|
127 |
|
128 } //end namespace bluetooth |
|
129 } //end namespace java |
|
130 |
|
131 #endif // BLUETOOTHFUNCTIONSERVER_H |