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

  1 karl  1.6 //%2005////////////////////////////////////////////////////////////////////////
  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 schuur 1.1 //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13            // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16            // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18 mark.hamzy 1.8 //
 19 schuur     1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20                // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21                // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22                // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23                // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24                // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25                // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26                // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27                //
 28                //==============================================================================
 29                //
 30                // Author: Chip Vincent (cvincent@us.ibm.com)
 31                //
 32                // Modified By: Yi Zhou, Hewlett-Packard Company(yi_zhou@hp.com)
 33                //              Mike Day, IBM (mdday@us.ibm.com)
 34 mark.hamzy 1.8 //              Adrian Schuur, schuur@de.ibm.com
 35 schuur     1.1 //
 36                //%/////////////////////////////////////////////////////////////////////////////
 37                
 38                #include "JMPIProvider.h"
 39                
 40                #include <Pegasus/Common/Tracer.h>
 41                #include <Pegasus/ProviderManager2/JMPI/JMPIProvider.h>
 42                #include <Pegasus/ProviderManager2/JMPI/JMPIProviderModule.h>
 43                
 44                PEGASUS_NAMESPACE_BEGIN
 45 schuur     1.2 PEGASUS_USING_STD;
 46 schuur     1.1 
 47 mark.hamzy 1.9 #ifdef PEGASUS_DEBUG
 48                #define DDD(x) if (JMPIjvm::trace) x;
 49                #else
 50                #define DDD(x)
 51                #endif
 52                
 53 mark.hamzy 1.8 #include "Convert.h"
 54 schuur     1.1 
 55                // set current operations to 1 to prevent an unload
 56                // until the provider has had a chance to initialize
 57                JMPIProvider::JMPIProvider(const String & name,
 58                		   JMPIProviderModule *module,
 59                		   ProviderVector *mv)
 60                   : _module(module), _cimom_handle(0), _name(name),
 61                     _no_unload(0), _rm(0)
 62                {
 63                   _current_operations = 1;
 64 carolann.graves 1.7    _currentSubscriptions = 0;
 65 schuur          1.1    miVector=*mv;
 66                        jProvider=mv->jProvider;
 67                        jProviderClass=mv->jProviderClass;
 68                        noUnload=false;
 69                        cachedClass=NULL;
 70                     }
 71                     
 72                     JMPIProvider::JMPIProvider(JMPIProvider *pr)
 73                       : _module(pr->_module), _cimom_handle(0), _name(pr->_name),
 74                         _no_unload(0), _rm(0)
 75                     {
 76                        _current_operations = 1;
 77 carolann.graves 1.7    _currentSubscriptions = 0;
 78 schuur          1.1    miVector=pr->miVector;
 79                        _cimom_handle=new CIMOMHandle();
 80                        noUnload=pr->noUnload;
 81                        cachedClass=NULL;
 82                     }
 83                     
 84                     JMPIProvider::~JMPIProvider(void)
 85                     {
 86                        delete cachedClass;
 87                     }
 88                     
 89                     JMPIProvider::Status JMPIProvider::getStatus(void) const
 90                     {
 91 mark.hamzy      1.10     AutoMutex lock(_statusMutex);
 92 schuur          1.1      return(_status);
 93                      }
 94                      
 95                      JMPIProviderModule *JMPIProvider::getModule(void) const
 96                      {
 97                          return(_module);
 98                      }
 99                      
100                      String JMPIProvider::getName(void) const
101                      {
102                          return(_name);
103                      }
104                      
105                      void JMPIProvider::initialize(CIMOMHandle& cimom)
106                      {
107 mark.hamzy      1.9      _status       = INITIALIZING;
108                          _cimom_handle = &cimom;
109                      
110                          DDD(PEGASUS_STD(cout)<<"--- JMPIProvider::Initialize()"<<PEGASUS_STD(endl));
111 schuur          1.1  
112 mark.hamzy      1.9      JvmVector *jv  = 0;
113                          JNIEnv    *env = JMPIjvm::attachThread(&jv);
114 schuur          1.3  
115 mark.hamzy      1.11     if (!env)
116                          {
117                              throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
118                                                             MessageLoaderParms("ProviderManager.JMPI.INIT_JVM_FAILED",
119                                                                                "Could not initialize the JVM (Java Virtual Machine) runtime environment."));
120                          }
121                      
122 mark.hamzy      1.9      // public abstract void initialize (org.pegasus.jmpi.CIMOMHandle ch)
123                          //        throws org.pegasus.jmpi.CIMException
124                          jmethodID id = env->GetMethodID((jclass)jProviderClass,
125                                                          "initialize",
126                                                          "(Lorg/pegasus/jmpi/CIMOMHandle;)V");
127 mark.hamzy      1.8  
128 mark.hamzy      1.10     DDD(PEGASUS_STD(cout)
129                              <<"--- JMPIProvider::Initialize:id = "
130                              <<PEGASUS_STD(hex)
131                              <<(int)id
132                              <<PEGASUS_STD(dec)
133                              <<PEGASUS_STD(endl));
134                      
135 schuur          1.1      JMPIjvm::checkException(env);
136 schuur          1.3  
137 mark.hamzy      1.10     if (id != NULL)
138                          {
139                             jstring jName = env->NewStringUTF(_name.getCString());
140                      
141                             JMPIjvm::checkException(env);
142 mark.hamzy      1.9  
143 mark.hamzy      1.10        jint    jCimomRef = DEBUG_ConvertCToJava (CIMOMHandle*, jint, &cimom);
144                             jobject jch       = env->NewObject(jv->CIMOMHandleClassRef,
145                                                                JMPIjvm::jv.CIMOMHandleNewISt,
146                                                                jCimomRef,
147                                                                jName);
148                      
149                             JMPIjvm::checkException(env);
150 schuur          1.3  
151 mark.hamzy      1.10        env->CallVoidMethod((jobject)jProvider,id,jch);
152 mark.hamzy      1.8  
153 mark.hamzy      1.10        JMPIjvm::checkException(env);
154                          }
155                          env->ExceptionClear();
156 schuur          1.3  
157 schuur          1.1      JMPIjvm::detachThread();
158                      
159 mark.hamzy      1.9      _status             = INITIALIZED;
160 schuur          1.1      _current_operations = 0;
161                      }
162                      
163                      Boolean JMPIProvider::tryTerminate(void)
164                      {
165                          return false;
166                      }
167                      
168                      void JMPIProvider::_terminate(void)
169                      {
170                      }
171                      
172                      
173                      void JMPIProvider::terminate(void)
174                      {
175                      }
176                      
177                      Boolean JMPIProvider::operator == (const void *key) const
178                      {
179                         if( (void *)this == key)
180                            return true;
181 schuur          1.1     return false;
182                      }
183                      
184                      Boolean JMPIProvider::operator == (const JMPIProvider &prov) const
185                      {
186                         if(String::equalNoCase(_name, prov._name))
187                            return true;
188                         return false;
189                      }
190                      /*
191                      void JMPIProvider::get_idle_timer(struct timeval *t)
192                      {
193                         if(t && _cimom_handle)
194                            _cimom_handle->get_idle_timer(t);
195                      }
196                      
197                      void JMPIProvider::update_idle_timer(void)
198                      {
199                         if(_cimom_handle)
200                            _cimom_handle->update_idle_timer();
201                      }
202 schuur          1.1  
203                      Boolean JMPIProvider::pending_operation(void)
204                      {
205                         if(_cimom_handle)
206                            return _cimom_handle->pending_operation();
207                         return false;
208                      }
209                      
210                      
211                      Boolean JMPIProvider::unload_ok(void)
212                      {
213                         return false;
214                      }
215                      */
216                      //   force provider manager to keep in memory
217                      void JMPIProvider::protect(void)
218                      {
219                        // _no_unload++;
220                      }
221                      
222                      // allow provider manager to unload when idle
223 schuur          1.1  void JMPIProvider::unprotect(void)
224                      {
225                        // _no_unload--;
226                      }
227                      
228 carolann.graves 1.7  Boolean JMPIProvider::testIfZeroAndIncrementSubscriptions ()
229                      {
230                          AutoMutex lock (_currentSubscriptionsMutex);
231                          Boolean isZero = (_currentSubscriptions == 0);
232                          _currentSubscriptions++;
233                      
234                          return isZero;
235                      }
236                      
237                      Boolean JMPIProvider::decrementSubscriptionsAndTestIfZero ()
238                      {
239                          AutoMutex lock (_currentSubscriptionsMutex);
240                          _currentSubscriptions--;
241                          Boolean isZero = (_currentSubscriptions == 0);
242                      
243                          return isZero;
244                      }
245                      
246                      Boolean JMPIProvider::testSubscriptions ()
247                      {
248                          AutoMutex lock (_currentSubscriptionsMutex);
249 carolann.graves 1.7      Boolean currentSubscriptions = (_currentSubscriptions > 0);
250                      
251                          return currentSubscriptions;
252                      }
253                      
254                      void JMPIProvider::resetSubscriptions ()
255                      {
256                          AutoMutex lock (_currentSubscriptionsMutex);
257                          _currentSubscriptions = 0;
258                      }
259                      
260                      void JMPIProvider::setProviderInstance (const CIMInstance & instance)
261                      {
262                          _providerInstance = instance;
263                      }
264                      
265                      CIMInstance JMPIProvider::getProviderInstance ()
266                      {
267                          return _providerInstance;
268                      }
269                      
270 schuur          1.1  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2