1 karl 1.12 //%2004////////////////////////////////////////////////////////////////////////
|
2 kumpf 1.1 //
|
3 karl 1.12 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.7 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.12 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 kumpf 1.1 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
11 kumpf 1.3 // of this software and associated documentation files (the "Software"), to
12 // deal in the Software without restriction, including without limitation the
13 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
14 kumpf 1.1 // sell copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
|
17 kumpf 1.3 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
18 kumpf 1.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
19 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
20 kumpf 1.3 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
23 kumpf 1.1 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26 //==============================================================================
27 //
28 // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
29 //
|
30 kumpf 1.2 // Modified By: Sushma Fernandes,
31 // Hewlett-Packard Company (sushma_fernandes@hp.com)
|
32 kumpf 1.6 // : Yi Zhou Hewlett-Packard Company (yi_zhou@hp.com)
|
33 kumpf 1.1 //
34 //%/////////////////////////////////////////////////////////////////////////////
35
36 #include <Pegasus/Common/Config.h>
37 #include <cstdlib>
38 //#include <dlfcn.h>
39 #include <Pegasus/Common/Destroyer.h>
40 #include <Pegasus/Common/System.h>
|
41 konrad.r 1.9 #include <Pegasus/Common/FileSystem.h>
|
42 kumpf 1.1 #include "HandlerTable.h"
43
44 PEGASUS_NAMESPACE_BEGIN
45
46 HandlerTable::HandlerTable()
47 {
48
49 }
50
51 CIMHandler* HandlerTable::lookupHandler(const String& handlerId)
52 {
53 for (Uint32 i = 0, n = _handlers.size(); i < n; i++)
54 if (String::equal(_handlers[i].handlerId, handlerId))
55 return _handlers[i].handler;
56
57 return 0;
58 }
59
60 typedef CIMHandler* (*CreateHandlerFunc)();
61
62 CIMHandler* HandlerTable::loadHandler(const String& handlerId)
63 kumpf 1.1 {
|
64 kumpf 1.10 String fileName = ConfigManager::getHomedPath(PEGASUS_DEST_LIB_DIR) +
|
65 kumpf 1.11 String("/") + FileSystem::buildLibraryFileName(handlerId);
|
66 kumpf 1.1
67 DynamicLibraryHandle libraryHandle =
|
68 kumpf 1.10 System::loadDynamicLibrary(fileName.getCString());
|
69 kumpf 1.1
70 if (!libraryHandle) {
71 #ifdef PEGASUS_OS_TYPE_WINDOWS
|
72 kumpf 1.10 throw DynamicLoadFailed(fileName);
|
73 kumpf 1.1 #else
|
74 kumpf 1.5 String errorMsg = System::dynamicLoadError();
75 throw DynamicLoadFailed(errorMsg);
|
76 kumpf 1.1 #endif
77 }
78
79 // Lookup the create handler symbol:
80
|
81 kumpf 1.5 String functionName = "PegasusCreateHandler_";
82 functionName.append(handlerId);
|
83 kumpf 1.1
84 CreateHandlerFunc func = (CreateHandlerFunc)System::loadDynamicSymbol(
|
85 kumpf 1.5 libraryHandle, functionName.getCString());
|
86 kumpf 1.1
87 if (!func)
|
88 kumpf 1.5 throw DynamicLookupFailed(functionName);
|
89 kumpf 1.1
90 // Create the handler:
91
92 CIMHandler* handler = func();
93
94 if (!handler)
95 throw CreateHandlerReturnedNull(
|
96 kumpf 1.10 fileName,
|
97 kumpf 1.5 functionName);
|
98 kumpf 1.1
99 if (handler)
100 {
101 Entry entry;
102 entry.handlerId = handlerId;
103 entry.handler = handler;
104 _handlers.append(entry);
105 }
106
107 return handler;
108 }
109
110 PEGASUS_NAMESPACE_END
|