|
1 /* |
|
2 * Copyright (c) 2007-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef DYNAMICLIBLOADER_H |
|
20 #define DYNAMICLIBLOADER_H |
|
21 |
|
22 #include <string> |
|
23 #include "javaosheaders.h" |
|
24 |
|
25 namespace java |
|
26 { |
|
27 namespace util |
|
28 { |
|
29 |
|
30 //Opening dynamic library failed. |
|
31 const int OPENING_LIBRARY_FAILED = -20000; |
|
32 |
|
33 //Getting function from dynamic library failed. |
|
34 const int CANNOT_FIND_FUNCTION_FAILURE = -20001; |
|
35 |
|
36 class DynamicLibLoader |
|
37 { |
|
38 public: |
|
39 //Constructor(s) & destructor |
|
40 |
|
41 /** |
|
42 * Creates object for loading the given library dynamically. |
|
43 * @param libName The name of the lib to be loaded. |
|
44 * @param closeWhenDestructed Wheter to unload the library when the |
|
45 * object is destroyed. If is false, will create a memory leak. |
|
46 */ |
|
47 OS_IMPORT DynamicLibLoader(const char* libName); |
|
48 |
|
49 /** |
|
50 * Creates object for loading the given library dynamically. |
|
51 * @param libName The name of the lib to be loaded. |
|
52 * @param closeWhenDestructed Wheter to unload the library when the |
|
53 * object is destroyed. If is false, will create a memory leak. |
|
54 */ |
|
55 OS_IMPORT DynamicLibLoader(const char* libName, bool closeWhenDestructed); |
|
56 |
|
57 |
|
58 OS_IMPORT virtual ~DynamicLibLoader(); |
|
59 |
|
60 /** |
|
61 * Opens the library |
|
62 * @param containsByteCode For some OS it is relevant to know if the dll |
|
63 * contains rommized byte code. |
|
64 * @throw LibraryLoaderException with error code OPENING_LIBRARY_FAILED |
|
65 * if loading a library failed. |
|
66 */ |
|
67 OS_IMPORT void openLib(); |
|
68 |
|
69 /** |
|
70 * @throw This operation does not throw exceptions. |
|
71 */ |
|
72 OS_IMPORT void closeLib(); |
|
73 |
|
74 /** |
|
75 * @throw LibraryLoaderException with following error codes: |
|
76 * OPENING_LIBRARY_FAILED => loading a library failed. |
|
77 * CANNOT_FIND_FUNCTION_FAILURE => function cannot be found from the library. |
|
78 */ |
|
79 OS_IMPORT void* getFunction(const char* functionName, bool containsByteCode = false); |
|
80 |
|
81 /** |
|
82 * @throw See exceptions from getFunction(const char*) operation. |
|
83 */ |
|
84 OS_IMPORT static DynamicLibLoader* loadAndGetFunction(void*& functionPtr, |
|
85 const char* libName, |
|
86 const char* functionName); |
|
87 |
|
88 private: //Methods |
|
89 DynamicLibLoader(); //No default constructor allowed |
|
90 DynamicLibLoader(const DynamicLibLoader&); //No copy constructor allowed |
|
91 DynamicLibLoader& operator= (const DynamicLibLoader&); //No Assignment operator allowed |
|
92 |
|
93 private: //Members |
|
94 std::string mLibName; |
|
95 void* mHandle; |
|
96 bool mCloseOnDestroy; |
|
97 }; |
|
98 |
|
99 } //end namespace util |
|
100 } //end namespace java |
|
101 |
|
102 #endif // DYNAMICLIBLOADER_H |