1 schuur 1.1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000 - 2003 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRgACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 schuur 1.1 //==============================================================================
23 //
24 // Author: Chip Vincent (cvincent@us.ibm.com)
25 //
26 // Modified By: Yi Zhou, Hewlett-Packard Company(yi_zhou@hp.com)
27 // Mike Day, IBM (mdday@us.ibm.com)
28 // Adrian Schuur, schuur@de.ibm.com
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_JMPIProvider_h
33 #define Pegasus_JMPIProvider_h
34
35 #include "JMPIImpl.h"
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/IPC.h>
38 #include <Pegasus/Provider/CIMOMHandle.h>
39 #include <Pegasus/Provider/CIMInstanceProvider.h>
40 #include <Pegasus/Provider/CIMAssociationProvider.h>
41 #include <Pegasus/Provider/CIMMethodProvider.h>
42
43 schuur 1.1 //#include <Pegasus/ProviderManager2/CMPI/CMPIResolverModule.h>
44
45 #include <Pegasus/Server/Linkage.h>
46
47 PEGASUS_NAMESPACE_BEGIN
48
49 class JMPIProviderModule;
50 class CMPIResolverModule;
51
52 struct ProviderVector {
53 jclass jProviderClass;
54 jobject jProvider;
55 };
56
57 // The JMPIProvider class represents the logical provider extracted from a
58 // provider module. It is wrapped in a facade to stabalize the interface
59 // and is directly tied to a module.
60
61 class PEGASUS_SERVER_LINKAGE JMPIProvider :
62 public virtual CIMProvider
63 {
64 schuur 1.1 public:
65
66 enum Status
67 {
68 UNKNOWN,
69 INITIALIZING,
70 INITIALIZED,
71 TERMINATING,
72 TERMINATED
73 };
74
75 public:
76
77
78 class pm_service_op_lock {
79 private:
80 pm_service_op_lock(void);
81 public:
82 pm_service_op_lock(JMPIProvider *provider) : _provider(provider)
83 { _provider->protect(); }
84 ~pm_service_op_lock(void)
85 schuur 1.1 { _provider->unprotect(); }
86 JMPIProvider * _provider;
87 };
88
89 // typedef JMPIProviderFacade Base;
90
91 JMPIProvider(const String & name,
92 JMPIProviderModule *module,
93 ProviderVector *mv);
94 JMPIProvider(JMPIProvider*);
95
96 virtual ~JMPIProvider(void);
97
98 virtual void initialize(CIMOMHandle & cimom);
99
100 virtual Boolean tryTerminate(void);
101 virtual void terminate(void);
102 virtual void _terminate(void);
103
104 Status getStatus(void) const;
105 String getName(void) const;
106 schuur 1.1 void setResolver(CMPIResolverModule *rm) { _rm=rm; }
107
108 JMPIProviderModule *getModule(void) const;
109
110 // << Mon Oct 14 15:42:24 2002 mdd >> for use with DQueue template
111 // to allow conversion from using Array<>
112 Boolean operator == (const void *key) const;
113 Boolean operator == (const JMPIProvider & prov) const;
114
115 // virtual void get_idle_timer(struct timeval *);
116 // virtual void update_idle_timer(void);
117 // virtual Boolean pending_operation(void);
118 // virtual Boolean unload_ok(void);
119
120 // force provider manager to keep in memory
121 virtual void protect(void);
122 // allow provider manager to unload when idle
123 virtual void unprotect(void);
124
125 protected:
126 Status _status;
127 schuur 1.1 JMPIProviderModule *_module;
128 ProviderVector miVector;
129 Boolean noUnload;
130 CIMClass *cachedClass;
131
132 private:
133 friend class JMPILocalProviderManager;
134 friend class JMPIProviderManager;
135 friend class ProviderManagerService;
136 // friend class OpProviderHolder;
137 CIMOMHandle *_cimom_handle;
138 void *jProviderClass,*jProvider;
139 String _name;
140 AtomicInt _no_unload;
141 CMPIResolverModule *_rm;
142 Uint32 _quantum;
143 AtomicInt _current_operations;
144 //};
145
146
147 //
148 schuur 1.1 // Used to encapsulate the incrementing/decrementing of the _current_operations
149 // for a JMPIProvider so it won't be unloaded during operations.
150 //
151
152 class OpProviderHolder
153 {
154 private:
155 JMPIProvider* _provider;
156
157 public:
158 OpProviderHolder(): _provider( NULL )
159 {
160 }
161 OpProviderHolder( const OpProviderHolder& p ): _provider( NULL )
162 {
163 SetProvider( p._provider );
164 }
165 OpProviderHolder( JMPIProvider* p ): _provider( NULL )
166 {
167 SetProvider( p );
168 }
169 schuur 1.1 ~OpProviderHolder()
170 {
171 UnSetProvider();
172 }
173 JMPIProvider& GetProvider()
174 {
175 return(*_provider);
176 }
177
178 OpProviderHolder& operator=( const OpProviderHolder& x )
179 {
180 if(this == &x)
181 return(*this);
182 SetProvider( x._provider );
183
184 return(*this);
185 }
186
187 void SetProvider( JMPIProvider* p )
188 {
189 UnSetProvider();
190 schuur 1.1 if(p)
191 {
192 _provider = p;
193 _provider->_current_operations++;
194 }
195 }
196
197 void UnSetProvider()
198 {
199 if(_provider)
200 {
201 _provider->_current_operations--;
202 _provider = NULL;
203 }
204 }
205 };
206 };
207
208 PEGASUS_NAMESPACE_END
209
210 #endif
|