1 /*****************************************************************************/
2 /* Software Testing Automation Framework (STAF) */
3 /* (C) Copyright IBM Corp. 2001 */
4 /* */
5 /* This software is licensed under the Eclipse Public License (EPL) V1.0. */
6 /*****************************************************************************/
7
8 #ifndef STAF_DynamicLibraryInlImpl
9 #define STAF_DynamicLibraryInlImpl
10
11 #include "STAF.h"
12 #include "STAFDynamicLibrary.h"
13 #include "STAFException.h"
14
STAFDynamicLibrary(const char * libraryName)15 STAF_INLINE STAFDynamicLibrary::STAFDynamicLibrary(const char *libraryName)
16 : fDynaLibImpl(0)
17 {
18 STAFString_t error = 0;
19 STAFRC_t rc = STAFDynamicLibraryOpen(&fDynaLibImpl, libraryName,
20 &error);
21 if (rc)
22 {
23 STAFString errorMsg("STAFDynamicLibraryOpen");
24
25 if (rc == kSTAFBaseOSError)
26 errorMsg += ": " + STAFString(error, STAFString::kShallow);
27
28 STAFException se(errorMsg.toCurrentCodePage()->buffer(), rc);
29 THROW_STAF_EXCEPTION(se);
30 }
31 }
32
33
getAddress(const char * name)34 STAF_INLINE void *STAFDynamicLibrary::getAddress(const char *name)
35 {
36 STAFString_t error = 0;
37 void *address = 0;
38 STAFRC_t rc = STAFDynamicLibraryGetAddress(fDynaLibImpl, name, &address,
39 &error);
40 if (rc)
41 {
42 STAFString errorMsg("STAFDynamicLibraryGetAddress");
43
44 if (rc == kSTAFBaseOSError)
45 errorMsg += ": " + STAFString(error, STAFString::kShallow);
46
47 STAFException se(errorMsg.toCurrentCodePage()->buffer(), rc);
48 THROW_STAF_EXCEPTION(se);
49 }
50
51 return address;
52 }
53
54
~STAFDynamicLibrary()55 STAF_INLINE STAFDynamicLibrary::~STAFDynamicLibrary()
56 {
57 STAFString_t error = 0;
58 unsigned int osRC = 0;
59 STAFRC_t rc = STAFDynamicLibraryClose(&fDynaLibImpl, &error);
60
61 if (rc == kSTAFBaseOSError) STAFStringDestruct(&error, &osRC);
62 }
63
64 #endif
65