1 karl 1.5 //%2006////////////////////////////////////////////////////////////////////////
|
2 h.sterling 1.1 //
3 // 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 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.5 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 h.sterling 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 //
21 // 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 //%/////////////////////////////////////////////////////////////////////////////
33
34 h.sterling 1.1 #include "ConsumerModule.h"
35
36 #include <Pegasus/Common/FileSystem.h>
37 #include <Pegasus/Common/MessageLoader.h> //l10n
38 #include <Pegasus/Common/Tracer.h>
|
39 mike 1.8 #include <Pegasus/Common/ThreadPool.h>
|
40 h.sterling 1.1
41 #include <Pegasus/Provider/CIMIndicationConsumerProvider.h>
42 #include <Pegasus/DynListener/ConsumerManager.h>
43
44 PEGASUS_USING_STD;
45 PEGASUS_NAMESPACE_BEGIN
46
47
|
48 kumpf 1.6 ConsumerModule::ConsumerModule()
|
49 h.sterling 1.1 {
50 }
51
52 ConsumerModule::~ConsumerModule(void)
53 {
54 }
55
56 // The caller assumes the repsonsibility of making sure the libraryPath is correctly formatted
57 CIMIndicationConsumerProvider* ConsumerModule::load(const String & consumerName, const String & libraryPath)
58 {
59 PEG_METHOD_ENTER(TRC_LISTENER, "ConsumerModule::load");
60
61 //check whether the module is cached; if it's not already in memory, load it
|
62 kumpf 1.6 if (!_library.isLoaded())
|
63 h.sterling 1.1 {
64 if (!FileSystem::exists(libraryPath) || !FileSystem::canRead(libraryPath))
65 {
|
66 h.sterling 1.3 throw Exception(MessageLoaderParms("DynListener.ConsumerModule.INVALID_LIBRARY_PATH",
|
67 h.sterling 1.1 "The library ($0:$1) does not exist or cannot be read.",
68 libraryPath,
69 consumerName));
70 }
71
|
72 kumpf 1.6 _library = DynamicLibrary(libraryPath);
|
73 kumpf 1.7 }
|
74 kumpf 1.6
|
75 kumpf 1.7 PEG_TRACE_STRING(TRC_LISTENER, Tracer::LEVEL2, "Loading library: " + consumerName);
|
76 h.sterling 1.1
|
77 kumpf 1.7 if (!_library.load())
|
78 h.sterling 1.1 {
|
79 h.sterling 1.3 throw Exception(MessageLoaderParms("DynListener.ConsumerModule.CANNOT_LOAD_LIBRARY",
80 "Cannot load consumer library ($0:$1), load error $2",
|
81 kumpf 1.6 _library.getFileName(),
|
82 h.sterling 1.1 consumerName,
|
83 kumpf 1.6 _library.getLoadErrorMessage()));
|
84 h.sterling 1.1 }
85
|
86 kumpf 1.7 PEG_TRACE_STRING(TRC_LISTENER, Tracer::LEVEL2, "Successfully loaded library " + consumerName);
87
|
88 h.sterling 1.1 // locate the entry point
|
89 kumpf 1.6 CIMProvider* (*createProvider)(const String&) =
90 (CIMProvider* (*)(const String&))
91 _library.getSymbol("PegasusCreateProvider");
|
92 h.sterling 1.1
93 if (!createProvider)
94 {
|
95 kumpf 1.7 _library.unload();
|
96 h.sterling 1.3 throw Exception(MessageLoaderParms("DynListener.ConsumerModule.ENTRY_POINT_NOT_FOUND",
97 "The entry point for consumer library ($0:$1) cannot be found.",
|
98 h.sterling 1.1 libraryPath,
99 consumerName));
100 }
101
102 // create the consumer provider
|
103 kumpf 1.7 CIMProvider* providerRef = createProvider(consumerName);
|
104 h.sterling 1.1
105 if(!providerRef)
106 {
|
107 kumpf 1.7 _library.unload();
|
108 h.sterling 1.3 throw Exception(MessageLoaderParms("DynListener.ConsumerModule.CREATE_PROVIDER_FAILED",
109 "createProvider failed for consumer library ($0:$1)",
|
110 h.sterling 1.1 libraryPath,
111 consumerName));
112 }
113
114 // test for the appropriate interface
115 CIMIndicationConsumerProvider* consumerRef = dynamic_cast<CIMIndicationConsumerProvider *>(providerRef);
116 if(!consumerRef)
117 {
|
118 kumpf 1.7 _library.unload();
|
119 h.sterling 1.3 throw Exception(MessageLoaderParms("DynListener.ConsumerModule.CONSUMER_IS_NOT_A",
120 "Consumer ($0:$1) is not a CIMIndicationConsumerProvider.",
|
121 h.sterling 1.1 libraryPath,
122 consumerName));
123 }
124
125 PEG_METHOD_EXIT();
126 return consumerRef;
127 }
128
129 void ConsumerModule::unloadModule(void)
130 {
131 PEG_METHOD_ENTER(TRC_LISTENER, "ConsumerModule::unloadModule");
132
|
133 kumpf 1.7 PEG_TRACE_STRING(TRC_LISTENER, Tracer::LEVEL3,
134 "Unloading module " + _library.getFileName());
135 _library.unload();
|
136 h.sterling 1.1
137 PEG_METHOD_EXIT();
138 }
139
140 PEGASUS_NAMESPACE_END
141
|