(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                    _current_operations   = 1;
 71 carolann.graves 1.7     _currentSubscriptions = 0;
 72 mark.hamzy      1.13    miVector              = *mv;
 73                         jProvider             = mv->jProvider;
 74                         jProviderClass        = mv->jProviderClass;
 75                         noUnload              = false;
 76                         cachedClass           = NULL;
 77                      }
 78                      
 79                      JMPIProvider::JMPIProvider (JMPIProvider *pr)
 80                      {
 81                         DDD(PEGASUS_STD(cout)<<"--- JMPIProvider::JMPIProvider(pr)"<<PEGASUS_STD(endl));
 82                      
 83                         _module               = pr->_module;
 84                         _cimom_handle         = 0;
 85                         _java_cimom_handle    = new CIMOMHandle ();
 86                         _name                 = pr->_name;
 87                         _no_unload            = pr->noUnload;
 88                         _current_operations   = 1;
 89 carolann.graves 1.7     _currentSubscriptions = 0;
 90 mark.hamzy      1.13    miVector              = pr->miVector;
 91                         noUnload              = pr->noUnload;
 92                         cachedClass           = NULL;
 93 schuur          1.1  }
 94                      
 95                      JMPIProvider::~JMPIProvider(void)
 96                      {
 97 mark.hamzy      1.13    DDD(PEGASUS_STD(cout)<<"--- JMPIProvider::~JMPIProvider()"<<PEGASUS_STD(endl));
 98                      
 99                         delete _java_cimom_handle;
100 schuur          1.1     delete cachedClass;
101                      }
102                      
103                      JMPIProvider::Status JMPIProvider::getStatus(void) const
104                      {
105 mark.hamzy      1.10     AutoMutex lock(_statusMutex);
106 schuur          1.1      return(_status);
107                      }
108                      
109                      JMPIProviderModule *JMPIProvider::getModule(void) const
110                      {
111                          return(_module);
112                      }
113                      
114                      String JMPIProvider::getName(void) const
115                      {
116                          return(_name);
117                      }
118                      
119                      void JMPIProvider::initialize(CIMOMHandle& cimom)
120                      {
121 mark.hamzy      1.9      _status       = INITIALIZING;
122                          _cimom_handle = &cimom;
123                      
124                          DDD(PEGASUS_STD(cout)<<"--- JMPIProvider::Initialize()"<<PEGASUS_STD(endl));
125 schuur          1.1  
126 mark.hamzy      1.9      JvmVector *jv  = 0;
127                          JNIEnv    *env = JMPIjvm::attachThread(&jv);
128 schuur          1.3  
129 mark.hamzy      1.11     if (!env)
130                          {
131                              throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
132                                                             MessageLoaderParms("ProviderManager.JMPI.INIT_JVM_FAILED",
133                                                                                "Could not initialize the JVM (Java Virtual Machine) runtime environment."));
134                          }
135                      
136 mark.hamzy      1.9      // public abstract void initialize (org.pegasus.jmpi.CIMOMHandle ch)
137                          //        throws org.pegasus.jmpi.CIMException
138                          jmethodID id = env->GetMethodID((jclass)jProviderClass,
139                                                          "initialize",
140                                                          "(Lorg/pegasus/jmpi/CIMOMHandle;)V");
141 mark.hamzy      1.8  
142 mark.hamzy      1.10     DDD(PEGASUS_STD(cout)
143                              <<"--- JMPIProvider::Initialize:id = "
144                              <<PEGASUS_STD(hex)
145 mark.hamzy      1.17         <<(long)id
146 mark.hamzy      1.10         <<PEGASUS_STD(dec)
147                              <<PEGASUS_STD(endl));
148                      
149 schuur          1.1      JMPIjvm::checkException(env);
150 schuur          1.3  
151 mark.hamzy      1.10     if (id != NULL)
152                          {
153                             jstring jName = env->NewStringUTF(_name.getCString());
154                      
155                             JMPIjvm::checkException(env);
156 mark.hamzy      1.9  
157 mark.hamzy      1.17        jlong    jCimomRef = DEBUG_ConvertCToJava (CIMOMHandle*, jlong, _java_cimom_handle);
158 mark.hamzy      1.10        jobject jch       = env->NewObject(jv->CIMOMHandleClassRef,
159 mark.hamzy      1.17                                           JMPIjvm::jv.CIMOMHandleNewJSt,
160 mark.hamzy      1.10                                           jCimomRef,
161                                                                jName);
162                      
163                             JMPIjvm::checkException(env);
164 schuur          1.3  
165 mark.hamzy      1.10        env->CallVoidMethod((jobject)jProvider,id,jch);
166 mark.hamzy      1.8  
167 mark.hamzy      1.10        JMPIjvm::checkException(env);
168                          }
169                          env->ExceptionClear();
170 schuur          1.3  
171 schuur          1.1      JMPIjvm::detachThread();
172                      
173 mark.hamzy      1.9      _status             = INITIALIZED;
174 schuur          1.1      _current_operations = 0;
175                      }
176                      
177                      Boolean JMPIProvider::tryTerminate(void)
178                      {
179                          return false;
180                      }
181                      
182                      void JMPIProvider::_terminate(void)
183                      {
184                      }
185                      
186                      
187                      void JMPIProvider::terminate(void)
188                      {
189                      }
190                      
191                      /*
192                      Boolean JMPIProvider::unload_ok(void)
193                      {
194                         return false;
195 schuur          1.1  }
196                      */
197                      //   force provider manager to keep in memory
198                      void JMPIProvider::protect(void)
199                      {
200                        // _no_unload++;
201                      }
202                      
203                      // allow provider manager to unload when idle
204                      void JMPIProvider::unprotect(void)
205                      {
206                        // _no_unload--;
207                      }
208                      
209 carolann.graves 1.7  Boolean JMPIProvider::testIfZeroAndIncrementSubscriptions ()
210                      {
211                          AutoMutex lock (_currentSubscriptionsMutex);
212                          Boolean isZero = (_currentSubscriptions == 0);
213                          _currentSubscriptions++;
214                      
215                          return isZero;
216                      }
217                      
218                      Boolean JMPIProvider::decrementSubscriptionsAndTestIfZero ()
219                      {
220                          AutoMutex lock (_currentSubscriptionsMutex);
221                          _currentSubscriptions--;
222                          Boolean isZero = (_currentSubscriptions == 0);
223                      
224                          return isZero;
225                      }
226                      
227                      Boolean JMPIProvider::testSubscriptions ()
228                      {
229                          AutoMutex lock (_currentSubscriptionsMutex);
230 carolann.graves 1.7      Boolean currentSubscriptions = (_currentSubscriptions > 0);
231                      
232                          return currentSubscriptions;
233                      }
234                      
235                      void JMPIProvider::resetSubscriptions ()
236                      {
237                          AutoMutex lock (_currentSubscriptionsMutex);
238                          _currentSubscriptions = 0;
239                      }
240                      
241                      void JMPIProvider::setProviderInstance (const CIMInstance & instance)
242                      {
243                          _providerInstance = instance;
244                      }
245                      
246                      CIMInstance JMPIProvider::getProviderInstance ()
247                      {
248                          return _providerInstance;
249                      }
250                      
251 schuur          1.1  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2