|
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: a Base class for starting the JVM. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef JVMSTARTERIMPL_H |
|
20 #define JVMSTARTERIMPL_H |
|
21 |
|
22 #include "jvmstarter.h" |
|
23 |
|
24 #include <algorithm> |
|
25 #include <string.h> |
|
26 #include <string> |
|
27 #include <list> |
|
28 |
|
29 namespace java // codescanner::namespace |
|
30 { |
|
31 |
|
32 namespace runtime // codescanner::namespace |
|
33 { |
|
34 |
|
35 /** |
|
36 * This class implements partially the interface JvmStarter. The class mainly |
|
37 * contains argument storing and modifying features. The static instance |
|
38 * getters and virtual JVM starting methods are left to be implemented by |
|
39 * the JVM specific starter which will be inherited from this class. |
|
40 */ |
|
41 |
|
42 |
|
43 OS_NONSHARABLE_CLASS(JvmStarterImpl) : public JvmStarter |
|
44 { |
|
45 public: |
|
46 |
|
47 /** |
|
48 * Destructor of the JvmStarterImpl. |
|
49 */ |
|
50 virtual ~JvmStarterImpl(); |
|
51 |
|
52 /** |
|
53 * @see jvmstarter.h |
|
54 */ |
|
55 virtual void appendClassPath(const std::wstring& file); |
|
56 |
|
57 /** |
|
58 * @see jvmstarter.h |
|
59 */ |
|
60 virtual void appendBootClassPath(const std::wstring& file); |
|
61 |
|
62 /** |
|
63 * @see jvmstarter.h |
|
64 */ |
|
65 virtual void prependBootClassPath(const std::wstring& file); |
|
66 |
|
67 /** |
|
68 * @see jvmstarter.h |
|
69 */ |
|
70 virtual void appendExtensionPath(const std::wstring& extensionPath); |
|
71 |
|
72 /** |
|
73 * @see jvmstarter.h |
|
74 */ |
|
75 virtual void setMainClass(const std::wstring& mainClass); |
|
76 |
|
77 /** |
|
78 * @see jvmstarter.h |
|
79 */ |
|
80 virtual void appendApplicationArgument(const std::wstring& argument); |
|
81 |
|
82 /** |
|
83 * @see jvmstarter.h |
|
84 */ |
|
85 virtual void appendSystemProperty(const std::wstring& systemproperty); |
|
86 |
|
87 /** |
|
88 * @see jvmstarter.h |
|
89 */ |
|
90 virtual void appendRawJvmArgument(const std::wstring& argument); |
|
91 |
|
92 /** |
|
93 * @see jvmstarter.h |
|
94 */ |
|
95 virtual void disableJit(); |
|
96 |
|
97 /** |
|
98 * @see jvmstarter.h |
|
99 */ |
|
100 virtual void enableThreadDumping(); |
|
101 |
|
102 protected: // Definitions |
|
103 |
|
104 /** |
|
105 * Clears all the std string & Lists. |
|
106 */ |
|
107 virtual void clear(); |
|
108 |
|
109 typedef std::list<std::wstring> JvmArgs_t; |
|
110 |
|
111 // A simple class for storing char* array that is deleted automatically |
|
112 // when going out of scope. |
|
113 class ScopedCharPointerArray |
|
114 { |
|
115 public: |
|
116 |
|
117 ScopedCharPointerArray(int size) : mBuffer(0), mSize(size) |
|
118 { |
|
119 mBuffer = new char* [size]; |
|
120 memset(mBuffer, 0, mSize * sizeof(char*)); |
|
121 } |
|
122 |
|
123 ~ScopedCharPointerArray() |
|
124 { |
|
125 for (int i = 0; i < mSize; i++) |
|
126 { |
|
127 delete[] mBuffer[i]; |
|
128 } |
|
129 delete[] mBuffer; |
|
130 } |
|
131 |
|
132 char** get() |
|
133 { |
|
134 return mBuffer; |
|
135 } |
|
136 |
|
137 private: |
|
138 |
|
139 /* |
|
140 * No copy constructor allowed. |
|
141 */ |
|
142 ScopedCharPointerArray(const ScopedCharPointerArray&); |
|
143 |
|
144 /* |
|
145 * No Assignment operator allowed. |
|
146 */ |
|
147 ScopedCharPointerArray& operator= (const ScopedCharPointerArray&); |
|
148 |
|
149 private: |
|
150 char** mBuffer; |
|
151 int mSize; |
|
152 }; |
|
153 |
|
154 // A simple class for storing char* pointers that is deleted automatically |
|
155 // when going out of scope. |
|
156 class ScopedCharPointer |
|
157 { |
|
158 public: |
|
159 |
|
160 ScopedCharPointer() |
|
161 { |
|
162 } |
|
163 |
|
164 ScopedCharPointer(char* ptr) : mBuffer(ptr) |
|
165 { |
|
166 } |
|
167 |
|
168 ~ScopedCharPointer() |
|
169 { |
|
170 delete[] mBuffer; |
|
171 } |
|
172 |
|
173 void set(char* ptr) |
|
174 { |
|
175 mBuffer = ptr; |
|
176 } |
|
177 |
|
178 char* get() |
|
179 { |
|
180 return mBuffer; |
|
181 } |
|
182 |
|
183 private: |
|
184 |
|
185 /* |
|
186 * No copy constructor allowed. |
|
187 */ |
|
188 ScopedCharPointer(const ScopedCharPointer&); |
|
189 |
|
190 /* |
|
191 * No Assignment operator allowed. |
|
192 */ |
|
193 ScopedCharPointer& operator= (const ScopedCharPointer&); |
|
194 |
|
195 private: |
|
196 char* mBuffer; |
|
197 }; |
|
198 |
|
199 |
|
200 protected: //Methods |
|
201 JvmStarterImpl(); // Default constructor allowed for inherited classes |
|
202 |
|
203 /** |
|
204 * Appends the given source path to the given destination path. If there |
|
205 * already exists a path a platform specific classpath separator is added |
|
206 * before doing the appending Converts the path separtors to platform |
|
207 * specifc ones. |
|
208 * @param source The source path to be appended. |
|
209 * @param destination The destination path where to be appended. |
|
210 */ |
|
211 void appendAndConvertClassPath(const std::wstring& source, |
|
212 std::wstring& destination); |
|
213 |
|
214 |
|
215 protected: // Members |
|
216 |
|
217 std::wstring mIdentifier; // For identifying the runtime. |
|
218 std::wstring mClassPath; // The classpath of the application |
|
219 std::wstring mBootClassPathAppend; // The appended boot classpath |
|
220 std::wstring mBootClassPathPrepend; // The prepended boot classpath |
|
221 std::wstring mExtensionPath; // The extension path to be used |
|
222 std::wstring mMainClass; // The main class of the application |
|
223 bool mJitDisabled; // Is the JIT disabled |
|
224 bool mTheadDumpEnabled; // Is the thread dump feature enabled |
|
225 Configuration mConfiguration; // CLDC or CDC |
|
226 JvmArgs_t mJvmArgs; // A list containing Jvm arguments. |
|
227 // This doesn't contain such |
|
228 // that has dedicated member variable |
|
229 // like the classpath |
|
230 JvmArgs_t mAppAndArgs; // A list containing application |
|
231 // class and arguments for the |
|
232 // application |
|
233 |
|
234 private: // Methods |
|
235 /** |
|
236 * No copy constructor allowed |
|
237 */ |
|
238 JvmStarterImpl(const JvmStarterImpl&); |
|
239 |
|
240 /** |
|
241 * No Assignment operator allowed |
|
242 */ |
|
243 JvmStarterImpl& operator= (const JvmStarterImpl&); |
|
244 |
|
245 }; |
|
246 |
|
247 } // end namespace runtime |
|
248 } // end namespace java |
|
249 |
|
250 |
|
251 #endif // JVMSTARTERIMPL_H |