(file) Return to JMPIProvider.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / JMPI

  1 karl  1.12 //%2006////////////////////////////////////////////////////////////////////////
  2 schuur 1.1  //
  3 karl   1.5  // 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 karl   1.6  // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10             // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl   1.12 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12             // EMC Corporation; Symantec Corporation; The Open Group.
 13 schuur 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 mark.hamzy 1.13 //
 21 schuur     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: Yi Zhou, Hewlett-Packard Company(yi_zhou@hp.com)
 35                 //              Mike Day, IBM (mdday@us.ibm.com)
 36 mark.hamzy 1.8  //              Adrian Schuur, schuur@de.ibm.com
 37 schuur     1.1  //
 38                 //%/////////////////////////////////////////////////////////////////////////////
 39                 
 40                 #include "JMPIProvider.h"
 41                 
 42                 #include <Pegasus/Common/Tracer.h>
 43                 #include <Pegasus/ProviderManager2/JMPI/JMPIProvider.h>
 44                 #include <Pegasus/ProviderManager2/JMPI/JMPIProviderModule.h>
 45                 
 46                 PEGASUS_NAMESPACE_BEGIN
 47 schuur     1.2  PEGASUS_USING_STD;
 48 schuur     1.1  
 49 mark.hamzy 1.9  #ifdef PEGASUS_DEBUG
 50                 #define DDD(x) if (JMPIjvm::trace) x;
 51                 #else
 52                 #define DDD(x)
 53                 #endif
 54                 
 55 mark.hamzy 1.8  #include "Convert.h"
 56 schuur     1.1  
 57                 // set current operations to 1 to prevent an unload
 58                 // until the provider has had a chance to initialize
 59 mark.hamzy 1.13 JMPIProvider::JMPIProvider (const String       &name,
 60                                             JMPIProviderModule *module,
 61                                             ProviderVector     *mv)
 62                 {
 63                    DDD(PEGASUS_STD(cout)<<"--- JMPIProvider::JMPIProvider(name, module, mv)"<<PEGASUS_STD(endl));
 64                 
 65                    _module               = module;
 66                    _cimom_handle         = 0;
 67                    _java_cimom_handle    = new CIMOMHandle ();
 68                    _name                 = name;
 69                    _no_unload            = false;
 70                    _rm                   = 0;
 71                    _current_operations   = 1;
 72 carolann.graves 1.7     _currentSubscriptions = 0;
 73 mark.hamzy      1.13    miVector              = *mv;
 74                         jProvider             = mv->jProvider;
 75                         jProviderClass        = mv->jProviderClass;
 76                         noUnload              = false;
 77                         cachedClass           = NULL;
 78                      }
 79                      
 80                      JMPIProvider::JMPIProvider (JMPIProvider *pr)
 81                      {
 82                         DDD(PEGASUS_STD(cout)<<"--- JMPIProvider::JMPIProvider(pr)"<<PEGASUS_STD(endl));
 83                      
 84                         _module               = pr->_module;
 85                         _cimom_handle         = 0;
 86                         _java_cimom_handle    = new CIMOMHandle ();
 87                         _name                 = pr->_name;
 88                         _no_unload            = pr->noUnload;
 89                         _rm                   = 0;
 90                         _current_operations   = 1;
 91 carolann.graves 1.7     _currentSubscriptions = 0;
 92 mark.hamzy      1.13    miVector              = pr->miVector;
 93                         noUnload              = pr->noUnload;
 94                         cachedClass           = NULL;
 95 schuur          1.1  }
 96                      
 97                      JMPIProvider::~JMPIProvider(void)
 98                      {
 99 mark.hamzy      1.13    DDD(PEGASUS_STD(cout)<<"--- JMPIProvider::~JMPIProvider()"<<PEGASUS_STD(endl));
100                      
101                         delete _java_cimom_handle;
102 schuur          1.1     delete cachedClass;
103                      }
104                      
105                      JMPIProvider::Status JMPIProvider::getStatus(void) const
106                      {
107 mark.hamzy      1.10     AutoMutex lock(_statusMutex);
108 schuur          1.1      return(_status);
109                      }
110                      
111                      JMPIProviderModule *JMPIProvider::getModule(void) const
112                      {
113                          return(_module);
114                      }
115                      
116                      String JMPIProvider::getName(void) const
117                      {
118                          return(_name);
119                      }
120                      
121                      void JMPIProvider::initialize(CIMOMHandle& cimom)
122                      {
123 mark.hamzy      1.9      _status       = INITIALIZING;
124                          _cimom_handle = &cimom;
125                      
126                          DDD(PEGASUS_STD(cout)<<"--- JMPIProvider::Initialize()"<<PEGASUS_STD(endl));
127 schuur          1.1  
128 mark.hamzy      1.9      JvmVector *jv  = 0;
129                          JNIEnv    *env = JMPIjvm::attachThread(&jv);
130 schuur          1.3  
131 mark.hamzy      1.11     if (!env)
132                          {
133                              throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
134                                                             MessageLoaderParms("ProviderManager.JMPI.INIT_JVM_FAILED",
135                                                                                "Could not initialize the JVM (Java Virtual Machine) runtime environment."));
136                          }
137                      
138 mark.hamzy      1.9      // public abstract void initialize (org.pegasus.jmpi.CIMOMHandle ch)
139                          //        throws org.pegasus.jmpi.CIMException
140                          jmethodID id = env->GetMethodID((jclass)jProviderClass,
141                                                          "initialize",
142                                                          "(Lorg/pegasus/jmpi/CIMOMHandle;)V");
143 mark.hamzy      1.8  
144 mark.hamzy      1.10     DDD(PEGASUS_STD(cout)
145                              <<"--- JMPIProvider::Initialize:id = "
146                              <<PEGASUS_STD(hex)
147                              <<(int)id
148                              <<PEGASUS_STD(dec)
149                              <<PEGASUS_STD(endl));
150                      
151 schuur          1.1      JMPIjvm::checkException(env);
152 schuur          1.3  
153 mark.hamzy      1.10     if (id != NULL)
154                          {
155                             jstring jName = env->NewStringUTF(_name.getCString());
156                      
157                             JMPIjvm::checkException(env);
158 mark.hamzy      1.9  
159 mark.hamzy      1.13        jint    jCimomRef = DEBUG_ConvertCToJava (CIMOMHandle*, jint, _java_cimom_handle);
160 mark.hamzy      1.10        jobject jch       = env->NewObject(jv->CIMOMHandleClassRef,
161                                                                JMPIjvm::jv.CIMOMHandleNewISt,
162                                                                jCimomRef,
163                                                                jName);
164                      
165                             JMPIjvm::checkException(env);
166 schuur          1.3  
167 mark.hamzy      1.10        env->CallVoidMethod((jobject)jProvider,id,jch);
168 mark.hamzy      1.8  
169 mark.hamzy      1.10        JMPIjvm::checkException(env);
170                          }
171                          env->ExceptionClear();
172 schuur          1.3  
173 schuur          1.1      JMPIjvm::detachThread();
174                      
175 mark.hamzy      1.9      _status             = INITIALIZED;
176 schuur          1.1      _current_operations = 0;
177                      }
178                      
179                      Boolean JMPIProvider::tryTerminate(void)
180                      {
181                          return false;
182                      }
183                      
184                      void JMPIProvider::_terminate(void)
185                      {
186                      }
187                      
188                      
189                      void JMPIProvider::terminate(void)
190                      {
191                      }
192                      
193                      Boolean JMPIProvider::operator == (const void *key) const
194                      {
195                         if( (void *)this == key)
196                            return true;
197 schuur          1.1     return false;
198                      }
199                      
200                      Boolean JMPIProvider::operator == (const JMPIProvider &prov) const
201                      {
202                         if(String::equalNoCase(_name, prov._name))
203                            return true;
204                         return false;
205                      }
206                      /*
207                      void JMPIProvider::get_idle_timer(struct timeval *t)
208                      {
209                         if(t && _cimom_handle)
210                            _cimom_handle->get_idle_timer(t);
211                      }
212                      
213                      void JMPIProvider::update_idle_timer(void)
214                      {
215                         if(_cimom_handle)
216                            _cimom_handle->update_idle_timer();
217                      }
218 schuur          1.1  
219                      Boolean JMPIProvider::pending_operation(void)
220                      {
221                         if(_cimom_handle)
222                            return _cimom_handle->pending_operation();
223                         return false;
224                      }
225                      
226                      
227                      Boolean JMPIProvider::unload_ok(void)
228                      {
229                         return false;
230                      }
231                      */
232                      //   force provider manager to keep in memory
233                      void JMPIProvider::protect(void)
234                      {
235                        // _no_unload++;
236                      }
237                      
238                      // allow provider manager to unload when idle
239 schuur          1.1  void JMPIProvider::unprotect(void)
240                      {
241                        // _no_unload--;
242                      }
243                      
244 carolann.graves 1.7  Boolean JMPIProvider::testIfZeroAndIncrementSubscriptions ()
245                      {
246                          AutoMutex lock (_currentSubscriptionsMutex);
247                          Boolean isZero = (_currentSubscriptions == 0);
248                          _currentSubscriptions++;
249                      
250                          return isZero;
251                      }
252                      
253                      Boolean JMPIProvider::decrementSubscriptionsAndTestIfZero ()
254                      {
255                          AutoMutex lock (_currentSubscriptionsMutex);
256                          _currentSubscriptions--;
257                          Boolean isZero = (_currentSubscriptions == 0);
258                      
259                          return isZero;
260                      }
261                      
262                      Boolean JMPIProvider::testSubscriptions ()
263                      {
264                          AutoMutex lock (_currentSubscriptionsMutex);
265 carolann.graves 1.7      Boolean currentSubscriptions = (_currentSubscriptions > 0);
266                      
267                          return currentSubscriptions;
268                      }
269                      
270                      void JMPIProvider::resetSubscriptions ()
271                      {
272                          AutoMutex lock (_currentSubscriptionsMutex);
273                          _currentSubscriptions = 0;
274                      }
275                      
276                      void JMPIProvider::setProviderInstance (const CIMInstance & instance)
277                      {
278                          _providerInstance = instance;
279                      }
280                      
281                      CIMInstance JMPIProvider::getProviderInstance ()
282                      {
283                          return _providerInstance;
284                      }
285                      
286 schuur          1.1  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2