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

  1 martin 1.21 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.22 //
  3 martin 1.21 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.22 //
 10 martin 1.21 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.22 //
 17 martin 1.21 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.22 //
 20 martin 1.21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.22 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.22 //
 28 martin 1.21 //////////////////////////////////////////////////////////////////////////
 29 schuur 1.1  //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32             #include "JMPIProvider.h"
 33             
 34             #include <Pegasus/Common/Tracer.h>
 35             #include <Pegasus/ProviderManager2/JMPI/JMPIProvider.h>
 36             #include <Pegasus/ProviderManager2/JMPI/JMPIProviderModule.h>
 37             
 38             PEGASUS_NAMESPACE_BEGIN
 39 schuur 1.2  PEGASUS_USING_STD;
 40 schuur 1.1  
 41 mark.hamzy 1.8  #include "Convert.h"
 42 schuur     1.1  
 43                 // set current operations to 1 to prevent an unload
 44                 // until the provider has had a chance to initialize
 45 mark.hamzy 1.13 JMPIProvider::JMPIProvider (const String       &name,
 46                                             JMPIProviderModule *module,
 47                                             ProviderVector     *mv)
 48                 {
 49 thilo.boehm 1.19    PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
 50                         "JMPIProvider::JMPIProvider(name, module, mv)");
 51 mark.hamzy  1.13 
 52                     _module               = module;
 53                     _cimom_handle         = 0;
 54                     _java_cimom_handle    = new CIMOMHandle ();
 55                     _name                 = name;
 56                     _no_unload            = false;
 57                     _current_operations   = 1;
 58 carolann.graves 1.7     _currentSubscriptions = 0;
 59 mark.hamzy      1.13    miVector              = *mv;
 60                         jProvider             = mv->jProvider;
 61                         jProviderClass        = mv->jProviderClass;
 62                         noUnload              = false;
 63                         cachedClass           = NULL;
 64 thilo.boehm     1.19 
 65                         PEG_METHOD_EXIT();
 66 mark.hamzy      1.13 }
 67                      
 68                      JMPIProvider::JMPIProvider (JMPIProvider *pr)
 69                      {
 70 thilo.boehm     1.19    PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
 71                             "JMPIProvider::JMPIProvider(pr)");
 72 mark.hamzy      1.13 
 73                         _module               = pr->_module;
 74                         _cimom_handle         = 0;
 75                         _java_cimom_handle    = new CIMOMHandle ();
 76                         _name                 = pr->_name;
 77                         _no_unload            = pr->noUnload;
 78                         _current_operations   = 1;
 79 carolann.graves 1.7     _currentSubscriptions = 0;
 80 mark.hamzy      1.13    miVector              = pr->miVector;
 81                         noUnload              = pr->noUnload;
 82                         cachedClass           = NULL;
 83 thilo.boehm     1.19 
 84                         PEG_METHOD_EXIT();
 85 schuur          1.1  }
 86                      
 87                      JMPIProvider::~JMPIProvider(void)
 88                      {
 89 thilo.boehm     1.19    PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
 90                             "JMPIProvider::~JMPIProvider");
 91 mark.hamzy      1.13 
 92                         delete _java_cimom_handle;
 93 schuur          1.1     delete cachedClass;
 94 thilo.boehm     1.19 
 95                         PEG_METHOD_EXIT();
 96 schuur          1.1  }
 97                      
 98                      JMPIProvider::Status JMPIProvider::getStatus(void) const
 99                      {
100 mark.hamzy      1.10     AutoMutex lock(_statusMutex);
101 schuur          1.1      return(_status);
102                      }
103                      
104                      JMPIProviderModule *JMPIProvider::getModule(void) const
105                      {
106                          return(_module);
107                      }
108                      
109                      String JMPIProvider::getName(void) const
110                      {
111                          return(_name);
112                      }
113                      
114                      void JMPIProvider::initialize(CIMOMHandle& cimom)
115                      {
116 mark.hamzy      1.9      _status       = INITIALIZING;
117                          _cimom_handle = &cimom;
118                      
119 thilo.boehm     1.19     PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
120                              "JMPIProvider::Initialize");
121 schuur          1.1  
122 mark.hamzy      1.9      JvmVector *jv  = 0;
123                          JNIEnv    *env = JMPIjvm::attachThread(&jv);
124 schuur          1.3  
125 mark.hamzy      1.11     if (!env)
126                          {
127 marek           1.20        PEG_TRACE_CSTRING( TRC_PROVIDERMANAGER, Tracer::LEVEL1,
128 thilo.boehm     1.19            "JMPIProvider:"
129                                     "Could not initialize the JVM (Java Virtual Machine) "
130                                     "runtime environment.");
131                      
132                              PEG_METHOD_EXIT();
133 marek           1.18         throw PEGASUS_CIM_EXCEPTION_L(
134                                  CIM_ERR_FAILED,
135                                  MessageLoaderParms(
136 thilo.boehm     1.19                 "ProviderManager.JMPI.JMPIProvider.INIT_JVM_FAILED",
137 marek           1.18                 "Could not initialize the JVM (Java Virtual Machine)"
138                                          " runtime environment."));
139 mark.hamzy      1.11     }
140                      
141 mark.hamzy      1.9      // public abstract void initialize (org.pegasus.jmpi.CIMOMHandle ch)
142                          //        throws org.pegasus.jmpi.CIMException
143                          jmethodID id = env->GetMethodID((jclass)jProviderClass,
144                                                          "initialize",
145                                                          "(Lorg/pegasus/jmpi/CIMOMHandle;)V");
146 mark.hamzy      1.8  
147 thilo.boehm     1.19     PEG_TRACE(( TRC_PROVIDERMANAGER, Tracer::LEVEL4,
148                              "JVM id = %X",(long)id));
149 mark.hamzy      1.10 
150 schuur          1.1      JMPIjvm::checkException(env);
151 schuur          1.3  
152 mark.hamzy      1.10     if (id != NULL)
153                          {
154                             jstring jName = env->NewStringUTF(_name.getCString());
155                      
156                             JMPIjvm::checkException(env);
157 mark.hamzy      1.9  
158 marek           1.18        jlong jCimomRef = DEBUG_ConvertCToJava(
159                                                   CIMOMHandle*,
160                                                   jlong,
161                                                   _java_cimom_handle);
162 mark.hamzy      1.10        jobject jch       = env->NewObject(jv->CIMOMHandleClassRef,
163 mark.hamzy      1.17                                           JMPIjvm::jv.CIMOMHandleNewJSt,
164 mark.hamzy      1.10                                           jCimomRef,
165                                                                jName);
166                      
167                             JMPIjvm::checkException(env);
168 schuur          1.3  
169 mark.hamzy      1.10        env->CallVoidMethod((jobject)jProvider,id,jch);
170 mark.hamzy      1.8  
171 mark.hamzy      1.10        JMPIjvm::checkException(env);
172                          }
173                          env->ExceptionClear();
174 schuur          1.3  
175 schuur          1.1      JMPIjvm::detachThread();
176                      
177 mark.hamzy      1.9      _status             = INITIALIZED;
178 schuur          1.1      _current_operations = 0;
179 thilo.boehm     1.19 
180                          PEG_METHOD_EXIT();
181                          return;
182 schuur          1.1  }
183                      
184                      Boolean JMPIProvider::tryTerminate(void)
185                      {
186                          return false;
187                      }
188                      
189                      void JMPIProvider::_terminate(void)
190                      {
191                      }
192                      
193                      
194                      void JMPIProvider::terminate(void)
195                      {
196                      }
197                      
198                      /*
199                      Boolean JMPIProvider::unload_ok(void)
200                      {
201                         return false;
202                      }
203 schuur          1.1  */
204                      //   force provider manager to keep in memory
205                      void JMPIProvider::protect(void)
206                      {
207                        // _no_unload++;
208                      }
209                      
210                      // allow provider manager to unload when idle
211                      void JMPIProvider::unprotect(void)
212                      {
213                        // _no_unload--;
214                      }
215                      
216 carolann.graves 1.7  Boolean JMPIProvider::testIfZeroAndIncrementSubscriptions ()
217                      {
218                          AutoMutex lock (_currentSubscriptionsMutex);
219                          Boolean isZero = (_currentSubscriptions == 0);
220                          _currentSubscriptions++;
221                      
222                          return isZero;
223                      }
224                      
225                      Boolean JMPIProvider::decrementSubscriptionsAndTestIfZero ()
226                      {
227                          AutoMutex lock (_currentSubscriptionsMutex);
228                          _currentSubscriptions--;
229                          Boolean isZero = (_currentSubscriptions == 0);
230                      
231                          return isZero;
232                      }
233                      
234                      Boolean JMPIProvider::testSubscriptions ()
235                      {
236                          AutoMutex lock (_currentSubscriptionsMutex);
237 carolann.graves 1.7      Boolean currentSubscriptions = (_currentSubscriptions > 0);
238                      
239                          return currentSubscriptions;
240                      }
241                      
242                      void JMPIProvider::resetSubscriptions ()
243                      {
244                          AutoMutex lock (_currentSubscriptionsMutex);
245                          _currentSubscriptions = 0;
246                      }
247                      
248                      void JMPIProvider::setProviderInstance (const CIMInstance & instance)
249                      {
250                          _providerInstance = instance;
251                      }
252                      
253                      CIMInstance JMPIProvider::getProviderInstance ()
254                      {
255                          return _providerInstance;
256                      }
257                      
258 schuur          1.1  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2