1 martin 1.21 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.22 //
|
3 martin 1.21 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.22 //
|
10 martin 1.21 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.22 //
|
17 martin 1.21 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.22 //
|
20 martin 1.21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.22 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.22 //
|
28 martin 1.21 //////////////////////////////////////////////////////////////////////////
|
29 chip 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include "ProviderModule.h"
33
34 #include <Pegasus/Common/FileSystem.h>
|
35 kumpf 1.13 #include <Pegasus/Common/MessageLoader.h>
|
36 chip 1.3
|
37 chip 1.1 PEGASUS_NAMESPACE_BEGIN
38
|
39 kumpf 1.13 ProviderModule::ProviderModule(const String& fileName)
|
40 kumpf 1.18 : _library(fileName)
|
41 chip 1.1 {
42 }
43
|
44 kumpf 1.13 ProviderModule::~ProviderModule()
|
45 chip 1.1 {
46 }
47
|
48 kumpf 1.13 CIMProvider* ProviderModule::load(const String& providerName)
|
49 chip 1.1 {
50 // dynamically load the provider library
|
51 kumpf 1.18 if (!_library.load())
|
52 chip 1.1 {
|
53 kumpf 1.18 throw Exception(MessageLoaderParms(
54 "ProviderManager.ProviderModule.CANNOT_LOAD_LIBRARY",
55 "ProviderLoadFailure ($0:$1):Cannot load library, error: $2",
56 _library.getFileName(),
57 providerName,
58 _library.getLoadErrorMessage()));
|
59 chip 1.1 }
60
|
61 kumpf 1.13 // find library entry point
|
62 kumpf 1.19 CIMProvider * (*createProvider)(const String&) =
|
63 kumpf 1.17 (CIMProvider* (*)(const String&))
64 _library.getSymbol("PegasusCreateProvider");
|
65 chip 1.1
|
66 kumpf 1.13 if (createProvider == 0)
|
67 chip 1.1 {
|
68 kumpf 1.18 _library.unload();
|
69 kumpf 1.13 throw Exception(MessageLoaderParms(
70 "ProviderManager.ProviderModule.ENTRY_POINT_NOT_FOUND",
|
71 chip 1.3 "ProviderLoadFailure ($0:$1):entry point not found.",
|
72 kumpf 1.17 _library.getFileName(),
|
73 chip 1.1 providerName));
74 }
75
76 // invoke the provider entry point
|
77 kumpf 1.17 CIMProvider* provider = createProvider(providerName);
|
78 chip 1.3
|
79 chip 1.1 // test for the appropriate interface
|
80 kumpf 1.17 if (dynamic_cast<CIMProvider *>(provider) == 0)
|
81 chip 1.1 {
|
82 kumpf 1.18 _library.unload();
|
83 kumpf 1.13 throw Exception(MessageLoaderParms(
84 "ProviderManager.ProviderModule.PROVIDER_IS_NOT_A",
|
85 chip 1.3 "ProviderLoadFailure ($0:$1):provider is not a CIMProvider.",
|
86 kumpf 1.17 _library.getFileName(),
|
87 chip 1.3 providerName));
|
88 chip 1.1 }
|
89 kumpf 1.17
|
90 kumpf 1.19 return provider;
|
91 chip 1.1 }
92
|
93 kumpf 1.13 void ProviderModule::unloadModule()
|
94 chip 1.1 {
|
95 kumpf 1.18 _library.unload();
|
96 chip 1.1 }
97
98 PEGASUS_NAMESPACE_END
|