2cc4b563ae6760d38a2b1e4cd3b38c95433952f7
[tpot/pegasus/.git] / src / Pegasus / ProviderManager / ProviderManager.cpp
1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 //
23 // Author: Chip Vincent (cvincent@us.ibm.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #include "ProviderManager.h"
30
31 #include <Pegasus/Common/Tracer.h>
32
33 PEGASUS_NAMESPACE_BEGIN
34
35 ProviderManager::ProviderManager(void)
36 {
37 }
38
39 ProviderManager::~ProviderManager(void)
40 {
41     // terminate all providers
42     for(Uint32 i = 0, n = _providers.size(); i < n; i++)
43     {
44         try
45         {
46             _providers[i].terminate();
47         }
48         catch(...)
49         {
50         }
51     }
52 }
53
54 Provider ProviderManager::getProvider(
55     const String & fileName,
56     const String & providerName)
57 {
58     //PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, "ProviderManager::getProvider");
59     //PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4, "fileName = " + fileName + "; providerName = " + providerName);
60
61     // check list for requested provider and return if found
62     for(Uint32 i = 0, n = _providers.size(); i < n; i++)
63     {
64         if(String::equalNoCase(providerName, _providers[i].getName()))
65         {
66             return(_providers[i]);
67         }
68     }
69
70     // create provider module
71     Provider provider(providerName, fileName);
72
73     // create a CIMOMHandle
74     MessageQueue * queue = MessageQueue::lookup("Server::ProviderManagerService");
75
76     PEGASUS_ASSERT(queue != 0);
77
78     MessageQueueService * service = dynamic_cast<MessageQueueService *>(queue);
79
80     PEGASUS_ASSERT(service != 0);
81
82     CIMOMHandle _cimom(service);
83
84     // initialize provider
85     provider.initialize(_cimom);
86
87     // add provider to list
88     _providers.append(provider);
89
90     //PEG_METHOD_EXIT();
91
92     // recurse to get the provider as it resides in the array (rather than the local instance)
93     return(getProvider(fileName, providerName));
94 }
95
96 void ProviderManager::addProviderToTable(const String & providerName, Boolean BlockFlag)
97 {
98     /*
99     ProviderBlockedEntry providerInfo(providerName, BlockFlag);
100
101     // add providerInfo to provider block table
102     _providerBT.append(providerInfo);
103     */
104 }
105
106 void ProviderManager::removeProviderFromTable(const String & providerName)
107 {
108     /*
109     for(Uint32 i=0, n=_providerBT.size(); i<n; i++)
110     {
111         if(String::equalNoCase(providerName,_providerBT[i].getProviderName()))
112         {
113             _providerBT.remove(i);
114         }
115     }
116     */
117 }
118
119 Uint32 ProviderManager::blockProvider(const String & providerName)
120 {
121     /*
122     for(Uint32 i=0, n=_providerBT.size(); i<n; i++)
123     {
124         if(String::equalNoCase(providerName,_providerBT[i].getProviderName()))
125         {
126             _providerBT[i].setProviderBlockFlag(true);
127             return(0);
128         }
129     }
130     */
131
132     return(1);
133 }
134
135 Uint32 ProviderManager::unblockProvider(const String & providerName)
136 {
137     /*
138     for(Uint32 i=0, n=_providerBT.size(); i<n; i++)
139     {
140         if(String::equalNoCase(providerName,_providerBT[i].getProviderName()))
141         {
142             _providerBT[i].setProviderBlockFlag(false);
143             return(0);
144         }
145     }
146     */
147
148     return(1);
149 }
150
151 Boolean ProviderManager::isProviderBlocked(const String & providerName)
152 {
153     /*
154     for(Uint32 i=0, n=_providerBT.size(); i<n; i++)
155     {
156         if(String::equalNoCase(providerName,_providerBT[i].getProviderName()))
157         {
158             return(_providerBT[i].getProviderBlockFlag());
159         }
160     }
161     */
162
163     return(false);
164 }
165
166 void ProviderManager::createProviderBlockTable(Array<CIMNamedInstance> & namedinstances)
167 {
168     /*
169     String providerName;
170     Boolean blockFlag;
171     CIMInstance instance;
172
173     for(Uint32 i = 0, n = namedinstances.size(); i < n; i++)
174     {
175         instance = namedinstances[i].getInstance();
176         providerName = instance.getProperty(
177             instance.findProperty("Name")).getValue().toString();
178         instance.getProperty(instance.findProperty("blocked")).
179             getValue().get(blockFlag);
180         
181         addProviderToTable(providerName, blockFlag);
182     }
183     */
184 }
185
186 Uint32 ProviderManager::stopProvider(const String & providerName)
187 {
188     /*
189     // check list for requested provider. If found, terminate the
190     // provider and unload library
191     for(Uint32 i = 0, n = _providers.size(); i < n; i++)
192     {
193         if(String::equalNoCase(providerName, _providers[i].getProviderName()))
194         {
195             // Terminate the provider, unload its library, and remove its entry
196             _providers[i].getProvider()->terminate();
197             // ATTN: Only unload if this is the last provider loaded from this library
198             _providers[i].unload();
199             _providers.remove(i);
200             return(0);
201         }
202     }
203
204     // if provider is not loaded, just return
205     */
206     return(0);
207 }
208
209 void ProviderManager::shutdownAllProviders(const String & providerName, const String & className)
210 {
211     /*
212     //
213     // For each provider in the list, call its terminate() method, skipping
214     // the specified provider.
215     //
216     Uint32 numProviders = _providers.size();
217
218     Uint32 index = 0;
219
220     while(numProviders > 0)
221     {
222         if(String::equalNoCase(providerName, _providers[index].getProviderName()))
223         {
224             stopProvider(providerName);
225         }
226         else
227         {
228             index++;
229         }
230         
231         numProviders--;
232     }
233     */
234 }
235
236 // ATTN: disabled temporarily
237 /*
238 PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL ProviderManager::monitorThread(void * arg)
239 {
240     Thread * thread = reinterpret_cast<Thread *>(arg);
241
242     ProviderManager * _this = reinterpret_cast<ProviderManager *>(thread->get_parm());
243
244     // check provider list every 30 seconds for providers to unload
245     for(Uint32 timeout = 0; true; timeout += 30)
246     {
247         thread->sleep(30000);
248
249         // check each provider for timeouts less than the current timeout
250         //for(Uint32 i = 0, n = _this->_providers.size(); i < n; i++)
251
252         // start with highest entry to prevent out-of-bounds
253         // exception in case a removed entry - Markus
254
255         for(Uint32 i = _this->_providers.size(); i > 0;)
256         {
257             // We want to count down to 0, but Uint32 will never go < 0
258             i--;
259
260             // get provider timeout
261
262             #if defined(PEGASUS_OS_HPUX)
263             Uint32 provider_timeout = 0xffffffff;
264             #else
265             Uint32 provider_timeout = 30;
266             #endif
267
268             if((provider_timeout != 0xffffffff) && (provider_timeout <= timeout))
269             {
270                 PEGASUS_STD(cout) << "unloading provider for " << _this->_providers[i].getClassName() << " in " << _this->_providers[i].getProviderName() << PEGASUS_STD(endl);
271                 void * mypr = (void *)_this->_providers[i].getProvider();
272
273                 _this->_providers[i].getProvider()->terminate();
274                 _this->_providers.remove(i);
275             }
276         }
277     }
278
279     PEGASUS_STD(cout) << "provider monitor stopped" << PEGASUS_STD(endl);
280
281     return(0);
282 }
283 */
284
285 PEGASUS_NAMESPACE_END