1 karl 1.16 //%2006////////////////////////////////////////////////////////////////////////
|
2 chip 1.1 //
|
3 karl 1.7 // 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.4 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.7 // 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.11 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.16 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 chip 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // 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 // 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.4 //
|
21 chip 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // 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 // 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 // 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: Chip Vincent (cvincent@us.ibm.com)
33 //
34 // Modified By:
|
35 kumpf 1.13 // Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
36 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
37 // Mike Day, IBM (mdday@us.ibm.com)
38 // Adrian Schuur, IBM (schuur@de.ibm.com)
|
39 joyce.j 1.10 // Josephine Eskaline Joyce (jojustin@in.ibm.com) for PEP#101
|
40 kumpf 1.13 // Sean Keenan, Hewlett-Packard Company <sean.keenan@hp.com>
41 // Roger Kumpf, Hewlett-Packard Company <roger_kumpf@hp.com>
|
42 aruran.ms 1.15 // Aruran, IBM (ashanmug@in.ibm.com) for Bug#4585
|
43 chip 1.1 //
44 //%/////////////////////////////////////////////////////////////////////////////
45
46 #include "ProviderModule.h"
47
48 #include <Pegasus/Common/FileSystem.h>
|
49 kumpf 1.13 #include <Pegasus/Common/MessageLoader.h>
|
50 chip 1.3
51 #ifdef PEGASUS_OS_OS400
|
52 kumpf 1.13 # include "CreateProviderOS400SystemState.h"
|
53 chip 1.3 #endif
|
54 chip 1.1
|
55 kumpf 1.13
|
56 chip 1.1 PEGASUS_NAMESPACE_BEGIN
57
|
58 kumpf 1.13 ProviderModule::ProviderModule(const String& fileName)
|
59 chip 1.1 : _fileName(fileName),
|
60 kumpf 1.13 _refCount(0),
61 _library(0)
|
62 chip 1.1 {
63 }
64
|
65 kumpf 1.13 ProviderModule::~ProviderModule()
|
66 chip 1.1 {
|
67 aruran.ms 1.15 if (_library != 0)
68 {
69 System::unloadDynamicLibrary(_library);
70 _library = 0;
71 _refCount = 0;
72 }
|
73 chip 1.1 }
74
|
75 kumpf 1.13 CIMProvider* ProviderModule::load(const String& providerName)
|
76 chip 1.1 {
|
77 kumpf 1.13 CIMProvider* provider = 0;
|
78 chip 1.1
79 // dynamically load the provider library
|
80 kumpf 1.13 if (_library == 0)
|
81 chip 1.1 {
|
82 kumpf 1.13 _library =
83 System::loadDynamicLibrary((const char *)_fileName.getCString());
|
84 chip 1.1
|
85 kumpf 1.13 if (_library == 0)
86 {
87 // ATTN: does unload() need to be called?
88 throw Exception(MessageLoaderParms(
89 "ProviderManager.ProviderModule.CANNOT_LOAD_LIBRARY",
90 "ProviderLoadFailure ($0:$1):Cannot load library, error: $2",
91 _fileName,
92 providerName,
93 System::dynamicLoadError()));
94 }
|
95 chip 1.1 }
96
|
97 kumpf 1.13 // find library entry point
|
98 chip 1.1 CIMProvider * (*createProvider)(const String &) = 0;
99
|
100 kumpf 1.13 createProvider = (CIMProvider* (*)(const String&))System::loadDynamicSymbol(
|
101 chip 1.1 _library, "PegasusCreateProvider");
102
|
103 kumpf 1.13 if (createProvider == 0)
|
104 chip 1.1 {
|
105 kumpf 1.13 throw Exception(MessageLoaderParms(
106 "ProviderManager.ProviderModule.ENTRY_POINT_NOT_FOUND",
|
107 chip 1.3 "ProviderLoadFailure ($0:$1):entry point not found.",
|
108 chip 1.1 _fileName,
109 providerName));
110 }
111
112 // invoke the provider entry point
|
113 chip 1.3 #ifndef PEGASUS_OS_OS400
|
114 chip 1.1 provider = createProvider(providerName);
|
115 chip 1.3 #else
116 // On OS/400, need to call a layer of code that does platform-specific
117 // checks before calling the provider
|
118 kumpf 1.13 provider = OS400_CreateProvider(
119 providerName.getCString(), createProvider, _fileName);
|
120 chip 1.3 #endif
121
|
122 chip 1.1 // test for the appropriate interface
123 if(dynamic_cast<CIMProvider *>(provider) == 0)
124 {
|
125 kumpf 1.13 throw Exception(MessageLoaderParms(
126 "ProviderManager.ProviderModule.PROVIDER_IS_NOT_A",
|
127 chip 1.3 "ProviderLoadFailure ($0:$1):provider is not a CIMProvider.",
|
128 chip 1.1 _fileName,
|
129 chip 1.3 providerName));
|
130 chip 1.1 }
|
131 kumpf 1.13 _refCount++;
|
132 chip 1.1 return(provider);
133 }
134
|
135 kumpf 1.13 void ProviderModule::unloadModule()
|
136 chip 1.1 {
|
137 mike 1.14 if (_refCount.decAndTestIfZero())
|
138 chip 1.1 {
|
139 kumpf 1.13 if (_library != 0)
|
140 david.dillard 1.8 {
141 System::unloadDynamicLibrary(_library);
142 _library = 0;
143 }
|
144 chip 1.1 }
145 }
146
147 PEGASUS_NAMESPACE_END
|