|
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: JavaOsLayer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <stdlib.h> |
|
20 #include <dlfcn.h> |
|
21 |
|
22 #include "logger.h" |
|
23 #include "javaoslayer.h" |
|
24 |
|
25 using namespace java::util; |
|
26 |
|
27 OS_EXPORT void JavaOsLayer::getOsSpecificLibName(std::string& result, |
|
28 const char* libName) |
|
29 { |
|
30 JELOG2(EUtils); |
|
31 if (libName) |
|
32 { |
|
33 result += "lib"; |
|
34 result += libName; |
|
35 result += ".so"; |
|
36 LOG2(EUtils, EInfo, |
|
37 "JavaOsLayer::getOsSpecificLibName(), Name: %s, Result: %s", |
|
38 libName, result.c_str()); |
|
39 } |
|
40 else |
|
41 { |
|
42 ELOG(EUtils, "JavaOsLayer::getOsSpecificLibName() libname was null"); |
|
43 } |
|
44 } |
|
45 |
|
46 OS_EXPORT void JavaOsLayer::getOsSpecificJavaRootPath(std::string& path) |
|
47 { |
|
48 JELOG2(EUtils); |
|
49 path = getenv("JAVA_BIN_ROOT"); |
|
50 LOG1(EUtils, EInfo, "JavaOsLayer::getOsSpecificLibName() Path: %s", |
|
51 path.c_str()); |
|
52 } |
|
53 |
|
54 |
|
55 |
|
56 void appendTrailingSlash(std::string& path) |
|
57 { |
|
58 if (path[path.length()-1] != '/') |
|
59 { |
|
60 path += '/'; |
|
61 } |
|
62 } |
|
63 |
|
64 OS_EXPORT std::string& JavaOsLayer::getBinRoot(std::string& path, bool /*append*/) |
|
65 //Argument append is not relevant in Linux environment |
|
66 { |
|
67 JELOG2(EUtils); |
|
68 path = getenv("JAVA_BIN_ROOT"); |
|
69 appendTrailingSlash(path); |
|
70 return path; |
|
71 } |
|
72 |
|
73 OS_EXPORT std::string& JavaOsLayer::getResRoot(std::string& path, bool /*append*/) |
|
74 //Argument append is not relevant in Linux environment |
|
75 { |
|
76 JELOG2(EUtils); |
|
77 path = getenv("JAVA_BIN_ROOT"); |
|
78 appendTrailingSlash(path); |
|
79 return path; |
|
80 } |
|
81 |
|
82 OS_EXPORT std::string& JavaOsLayer::getMidpRoot(std::string& path, bool /*append*/) |
|
83 //Argument append is not relevant in Linux environment |
|
84 { |
|
85 JELOG2(EUtils); |
|
86 path = getenv("JAVA_BIN_ROOT"); |
|
87 appendTrailingSlash(path); |
|
88 return path; |
|
89 } |
|
90 |
|
91 OS_EXPORT std::string& JavaOsLayer::getJavaCaptainRoot(std::string& path, bool /*append*/) |
|
92 //Argument append is not relevant in Linux environment |
|
93 { |
|
94 JELOG2(EUtils); |
|
95 path = getenv("JAVA_BIN_ROOT"); |
|
96 appendTrailingSlash(path); |
|
97 return path; |
|
98 } |
|
99 |
|
100 OS_EXPORT DriveId JavaOsLayer::getMidpDrive() |
|
101 { |
|
102 // JELOG2(EUtils); |
|
103 return DriveId(); |
|
104 } |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 OS_EXPORT void* JavaOsLayer::dlopen(const char* libName) |
|
122 { |
|
123 JELOG2(EUtils); |
|
124 void* lib = 0; |
|
125 if (libName) |
|
126 { |
|
127 lib = ::dlopen(libName, RTLD_LAZY); |
|
128 LOG2(EUtils, EInfo, "JavaOsLayer::dlopen(%s) Handle: %X", libName, |
|
129 lib); |
|
130 if (lib == 0) |
|
131 { |
|
132 char* errstr; |
|
133 errstr = dlerror(); |
|
134 if (errstr != 0) |
|
135 { |
|
136 /* |
|
137 ELOG2(EUtils, "JavaOsLayer::dlopen(%s) failed. Reason: %s", |
|
138 libName, errstr); |
|
139 */ |
|
140 } |
|
141 } |
|
142 } |
|
143 else |
|
144 { |
|
145 ELOG(EUtils, "JavaOsLayer::dlopen() libname was null"); |
|
146 } |
|
147 return lib; |
|
148 } |
|
149 |
|
150 OS_EXPORT void* JavaOsLayer::dlsym(void* handle, const char* name, bool) |
|
151 { |
|
152 JELOG2(EUtils); |
|
153 void* func = 0; |
|
154 if (handle && name) |
|
155 { |
|
156 func = ::dlsym(handle, name); |
|
157 LOG2(EUtils, EInfo, "JavaOsLayer::dlsym(%s) fPtr: %X", name, func); |
|
158 if (func == 0) |
|
159 { |
|
160 char* errstr; |
|
161 errstr = dlerror(); |
|
162 if (errstr != 0) |
|
163 { |
|
164 ELOG2(EUtils, "JavaOsLayer::dlsym(%s) failed. Reason: %s", |
|
165 name, errstr); |
|
166 } |
|
167 } |
|
168 } |
|
169 else |
|
170 { |
|
171 ELOG2(EUtils, "JavaOsLayer::dlsym() null argument handle: %X, name %X", |
|
172 handle, name); |
|
173 } |
|
174 return func; |
|
175 } |
|
176 |
|
177 OS_EXPORT int JavaOsLayer::dlclose(void* handle) |
|
178 { |
|
179 JELOG2(EUtils); |
|
180 int result = -1; |
|
181 if (handle) |
|
182 { |
|
183 result = ::dlclose(handle); |
|
184 if (result != 0) |
|
185 { |
|
186 ELOG1(EUtils, "JavaOsLayer::dlclose() failed. Reason: %d", result); |
|
187 } |
|
188 } |
|
189 else |
|
190 { |
|
191 ELOG(EUtils, "JavaOsLayer::dlclose() null handle"); |
|
192 } |
|
193 return result; |
|
194 } |
|
195 |
|
196 OS_EXPORT void JavaOsLayer::startUpTrace(const std::string& /*header*/, |
|
197 int /*freeMem*/, int /*totalMem*/) |
|
198 { |
|
199 //NOP for Linux at the moment. |
|
200 } |