1 kumpf 1.1 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // 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 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
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 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 kumpf 1.1 // 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 //%/////////////////////////////////////////////////////////////////////////////
33
34 #ifndef Pegasus_ProviderAgent_h
35 #define Pegasus_ProviderAgent_h
36
37 #include <Pegasus/Common/Config.h>
38 #include <Pegasus/Common/AnonymousPipe.h>
39 #include <Pegasus/Common/Thread.h>
40 #include <Pegasus/Common/ThreadPool.h>
41 #include <Pegasus/Common/Signal.h>
42 #include <Pegasus/ProviderManagerService/BasicProviderManagerRouter.h>
43 kumpf 1.1
44 PEGASUS_NAMESPACE_BEGIN
45
46 class ProviderAgent
47 {
48 public:
49 /** Constructor */
50 ProviderAgent(
51 const String& agentId,
52 AnonymousPipe* pipeFromServer,
53 AnonymousPipe* pipeToServer);
54
55 /** Destructor */
56 ~ProviderAgent();
57
58 /**
59 Start the Provider Agent reading and processing requests from the
60 CIM Server. This method returns when the Provider Agent is exiting.
61 The Provider Agent exits when: 1) Its provider module is disabled,
62 stopped, or idle, 2) It is unable to communicate with the CIM Server,
63 3) It receives a TERM or HUP signal, or 4) It encounters an
64 kumpf 1.1 unrecoverable error.
65 */
66 void run();
67
68 private:
69 //
70 // Private methods
71 //
72
73 /** Unimplemented */
74 ProviderAgent();
75 /** Unimplemented */
76 ProviderAgent(const ProviderAgent&);
77 /** Unimplemented */
78 ProviderAgent& operator=(const ProviderAgent&);
79
80 /**
81 Read a request from the _pipeFromServer and process it.
82
83 @return true if the Provider Agent successfully received a request
84 from the CIM Server; false otherwise.
85 kumpf 1.1 */
86 Boolean _readAndProcessRequest();
87
88 /**
89 Forward a request to the _providerManagerRouter. Catch exceptions
90 and add them to the cimException attribute in the response.
91
92 @param request The CIMRequestMessage to process.
93 @return A CIMResponseMessage resulting from the processing of the
94 specified CIMRequestMessage.
95 */
96 Message* _processRequest(CIMRequestMessage* request);
97
98 /**
99 Write a message to the _pipeToServer. On error, set _terminating
100 to true.
101
102 @param message The message to write to the CIM Server.
103 */
104 void _writeResponse(Message* message);
105
106 kumpf 1.1 /**
107 Forward a request to the _providerManagerRouter. Catch exceptions
108 and add them to the cimException attribute in the response.
109 Write the response message to the _pipeToServer. On error, set
110 _terminating to true.
111
112 This method allows a request message to be processed asynchronously
113 in its own thread.
114
115 @param arg A pointer to a ProviderAgentRequest object containing a
116 reference to the ProviderAgent object and the request
117 message to process.
118 */
119 static ThreadReturnType PEGASUS_THREAD_CDECL
120 _processRequestAndWriteResponse(void* arg);
121
122 /**
123 Callback function to which all generated indications are sent for
124 processing.
125 */
126 static void _indicationCallback(
127 kumpf 1.1 CIMProcessIndicationRequestMessage* request);
128
129 /**
130 Callback function to which all response chunks are sent for processing.
131 */
132 static void _responseChunkCallback(
133 CIMRequestMessage* request, CIMResponseMessage* response);
134
135 void _unloadIdleProviders();
136 static ThreadReturnType PEGASUS_THREAD_CDECL
137 _unloadIdleProvidersHandler(void* arg) throw();
138
139 static void _terminateSignalHandler(
140 int s_n, PEGASUS_SIGINFO_T* s_info, void* sig);
141
142 //
143 // Private data
144 //
145
146 /**
147 ProviderAgent reference used by the terminateSignalHandler to
148 kumpf 1.1 indicate that the Provider Agent should exit.
149 */
150 static ProviderAgent* _providerAgent;
151
152 /**
153 String used to identify this Provider Agent instance.
154 */
155 String _agentId;
156
157 /**
158 The pipe connection on which the Provider Agent reads requests
159 from the CIM Server.
160 */
161 AnonymousPipe* _pipeFromServer;
162 /**
163 The pipe connection on which the Provider Agent writes responses
164 (and indications) to the CIM Server.
165 */
166 AnonymousPipe* _pipeToServer;
167 /**
168 This lock must be held whenever writing on the _pipeToServer
169 kumpf 1.1 connection.
170 */
171 Mutex _pipeToServerMutex;
172
173 /**
174 Indicates whether the Provider Agent should exit.
175 */
176 Boolean _terminating;
177
178 /**
179 The ProviderManagerRouter to which all provider operations are
180 forwarded for processing.
181 */
182 BasicProviderManagerRouter _providerManagerRouter;
183
184 /**
185 Indicates the number of threads currently attempting to unload idle
186 providers. This value is used to prevent multiple threads from
187 unloading idle providers concurrently.
188 */
189 AtomicInt _unloadIdleProvidersBusy;
190 kumpf 1.1
191 /**
192 Holds the last provider module instance received from the CIM Server
193 in a ProviderIdContainer. Since the provider module instance rarely
194 changes, an optimization is used to send it only when it differs from
195 the last provider module instance sent.
196 */
197 CIMInstance _providerModuleCache;
198
199 /**
200 Indicates whether the Indication Service has completed initialization.
201
202 For more information, please see the description of the
203 ProviderManagerRouter::_subscriptionInitComplete member variable.
204 */
205 Boolean _subscriptionInitComplete;
206
207 /**
208 A thread pool used for asynchronous processing of provider operations.
209 */
210 ThreadPool _threadPool;
211 kumpf 1.1
212 /**
213 Indicates if the provider agent has been successful initialised already.
214 */
215 Boolean _isInitialised;
216 };
217
218 PEGASUS_NAMESPACE_END
219
220 #endif /* Pegasus_ProviderAgent_h */
|