1 karl 1.21 //%2006////////////////////////////////////////////////////////////////////////
|
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 karl 1.13 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.21 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 kumpf 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
15 kumpf 1.3 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
18 kumpf 1.1 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.21 //
|
21 kumpf 1.3 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
22 kumpf 1.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
24 kumpf 1.3 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
27 kumpf 1.1 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
33 //
|
34 vageesh.umesh 1.19 // Modified By: Sushma Fernandes,
|
35 kumpf 1.2 // Hewlett-Packard Company (sushma_fernandes@hp.com)
|
36 vageesh.umesh 1.19 // Yi Zhou Hewlett-Packard Company (yi_zhou@hp.com)
37 // Sean Keenan (sean.keenan@hp.com)
|
38 joyce.j 1.15 // Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for PEP # 101
|
39 vageesh.umesh 1.19 // Vageesh Umesh, IBM (vagumesh@in.ibm.com) for BUG#2543
|
40 carolann.graves 1.24 // Carol Ann Krug Graves, Hewlett-Packard Company
41 // (carolann_graves@hp.com)
|
42 kumpf 1.1 //
43 //%/////////////////////////////////////////////////////////////////////////////
44
45 #include <Pegasus/Common/Config.h>
46 #include <cstdlib>
47 //#include <dlfcn.h>
|
48 konrad.r 1.9 #include <Pegasus/Common/FileSystem.h>
|
49 carolann.graves 1.24 #include <Pegasus/Common/Tracer.h>
|
50 kumpf 1.1 #include "HandlerTable.h"
51
|
52 yi.zhou 1.18 PEGASUS_USING_STD;
|
53 kumpf 1.1 PEGASUS_NAMESPACE_BEGIN
54
55 HandlerTable::HandlerTable()
56 {
57 }
58
|
59 yi.zhou 1.18 CIMHandler* HandlerTable::getHandler(
60 const String& handlerId,
61 CIMRepository* repository)
62 {
63 CIMHandler * handler;
64 {
65 ReadLock lock(_handlerTableLock);
66 handler = _lookupHandler(handlerId);
67 if (handler)
68 {
69 return (handler);
70 }
71 }
72
73 {
74 WriteLock lock(_handlerTableLock);
75 handler = _lookupHandler(handlerId);
76 // Note: Lock handler table until handler initialize is done.
77 // This is ok for handler since the initialization is simple.
78 if (!handler)
79 {
80 yi.zhou 1.18 handler = _loadHandler(handlerId);
81 handler->initialize(repository);
82 }
83
84 return (handler);
85 }
86 }
87
88 CIMHandler* HandlerTable::_lookupHandler(const String& handlerId)
|
89 kumpf 1.1 {
90 for (Uint32 i = 0, n = _handlers.size(); i < n; i++)
91 if (String::equal(_handlers[i].handlerId, handlerId))
92 return _handlers[i].handler;
93
94 return 0;
95 }
96
|
97 kumpf 1.26 typedef CIMHandler* (*CreateHandlerFunc)(const String&);
|
98 kumpf 1.1
|
99 yi.zhou 1.18 CIMHandler* HandlerTable::_loadHandler(const String& handlerId)
|
100 kumpf 1.1 {
|
101 gs.keenan 1.14 #if defined (PEGASUS_OS_VMS)
|
102 gs.keenan 1.23 String provDir = ConfigManager::getInstance()->getCurrentValue("providerDir");
103 String fileName = ConfigManager::getHomedPath(provDir) + "/" +
104 FileSystem::buildLibraryFileName(handlerId) + ".exe";
|
105 humberto 1.16 #elif defined(PEGASUS_OS_OS400)
|
106 chuck 1.17 Uint32 lastSlash = handlerId.reverseFind('/');
107 if (lastSlash == PEG_NOT_FOUND)
108 throw DynamicLoadFailed(handlerId);
109 String fileName = handlerId.subString(0, lastSlash);
110 String os400HandlerId = handlerId.subString(lastSlash + 1);
|
111 gs.keenan 1.14 #else
112 String fileName = ConfigManager::getHomedPath((PEGASUS_DEST_LIB_DIR) +
113 String("/") + FileSystem::buildLibraryFileName(handlerId));
114 #endif
|
115 kumpf 1.1
|
116 kumpf 1.25 HandlerEntry entry(handlerId, fileName);
|
117 kumpf 1.1
|
118 kumpf 1.25 if (!entry.handlerLibrary.load())
119 {
120 #if defined(PEGASUS_OS_TYPE_WINDOWS)
121 throw DynamicLoadFailed(fileName);
|
122 kumpf 1.1 #else
|
123 kumpf 1.25 throw DynamicLoadFailed(entry.handlerLibrary.getLoadErrorMessage());
|
124 kumpf 1.1 #endif
125 }
126
127 // Lookup the create handler symbol:
128
|
129 kumpf 1.26 CreateHandlerFunc func = (CreateHandlerFunc)
130 entry.handlerLibrary.getSymbol("PegasusCreateHandler");
|
131 yi.zhou 1.18
|
132 kumpf 1.1 if (!func)
|
133 yi.zhou 1.18 {
|
134 kumpf 1.26 throw DynamicLookupFailed("PegasusCreateHandler");
|
135 yi.zhou 1.18 }
|
136 kumpf 1.1
137 // Create the handler:
138
|
139 kumpf 1.26 entry.handler = func(handlerId);
|
140 kumpf 1.1
|
141 carolann.graves 1.27 //
142 // ATTN: to support dynamically pluggable handlers, the entry.handler
143 // returned from the PegasusCreateHandler_<handlerId> function would
144 // need to be validated to be non-null
145 //
146 PEGASUS_ASSERT(entry.handler);
|
147 kumpf 1.1
|
148 kumpf 1.25 _handlers.append(entry);
149
150 return entry.handler;
|
151 kumpf 1.1 }
152
|
153 vageesh.umesh 1.19 HandlerTable::~HandlerTable()
154 {
|
155 vageesh.umesh 1.20 for( Uint32 i = 0; i < _handlers.size(); i++ )
156 {
|
157 carolann.graves 1.24 //
158 // Call handler's terminate() method
159 //
160 try
161 {
162 _handlers[i].handler->terminate();
163 }
164 catch (...)
165 {
166 PEGASUS_ASSERT(0);
167 PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL3,
168 "Unknown error caught from " +
169 _handlers[i].handlerId +
170 " terminate() method");
171 }
172
|
173 vageesh.umesh 1.20 delete _handlers[i].handler;
174 }
|
175 vageesh.umesh 1.19 }
176
|
177 kumpf 1.1 PEGASUS_NAMESPACE_END
|