(file) Return to provmgr.h CVS log (file) (dir) Up to [OMI] / omi / provmgr

  1 mike  1.1 /*
  2           **==============================================================================
  3           **
  4           ** Open Management Infrastructure (OMI)
  5           **
  6           ** Copyright (c) Microsoft Corporation
  7           ** 
  8           ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9           ** use this file except in compliance with the License. You may obtain a copy 
 10           ** of the License at 
 11           **
 12           **     http://www.apache.org/licenses/LICENSE-2.0 
 13           **
 14           ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15           ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
 16           ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
 17           ** MERCHANTABLITY OR NON-INFRINGEMENT. 
 18           **
 19           ** See the Apache 2 License for the specific language governing permissions 
 20           ** and limitations under the License.
 21           **
 22 mike  1.1 **==============================================================================
 23           */
 24           
 25           #ifndef _provmgr_h
 26           #define _provmgr_h
 27           
 28           #include <common.h>
 29 krisbash 1.4 #include <pal/shlib.h>
 30              #include <pal/lock.h>
 31 mike     1.1 #include <base/base.h>
 32              #include <base/messages.h>
 33 krisbash 1.4 #include <base/interaction.h>
 34 mike     1.2 #include <sock/selector.h>
 35 krisbash 1.4 #include <provreg/provreg.h>
 36              #include <omi_error/errorutil.h>
 37 mike     1.1 
 38              BEGIN_EXTERNC
 39              
 40 krisbash 1.4 #define PROVMGR_IDLE_TIMEOUT_USEC   (MI_ULL(90) * MI_ULL(1000000))
 41              
 42 mike     1.1 typedef struct _ProvMgr     ProvMgr;
 43 krisbash 1.4 struct _SubscriptionManager;
 44              typedef struct _SubscriptionContext SubscriptionContext;
 45 mike     1.1 
 46              /*
 47                  Callback to notify that prov-mgr unloaded all libraries
 48              */
 49              typedef void (*ProvMgrCallbackOnIdle)(
 50                  ProvMgr* mgr,
 51                  void* callbackData);
 52              
 53              struct _ProvMgr
 54              {
 55 krisbash 1.4     char providerDir[PAL_MAX_PATH_SIZE];
 56 mike     1.1 
 57                  /* Linked list of loaded providers */
 58                  struct _Library* head;
 59                  struct _Library* tail;
 60 krisbash 1.4     /* make library list threadsafe */
 61                  Lock liblock;
 62 mike     1.1 
 63                  /* timer notification */
 64                  Handler     timeoutHandler;
 65                  MI_Uint64   idleTimeoutUsec;
 66              
 67                  /* idle notifications */
 68                  ProvMgrCallbackOnIdle   idleCallback;
 69                  void*                   idleCallbackData;
 70              
 71                  /* selector (for timeouts support) */
 72                  Selector* selector;
 73 krisbash 1.4 
 74                  /* Support for local session */
 75                  MI_Application localApplication;
 76                  MI_Session localSession;
 77                  ptrdiff_t localSessionInitialized; /* 0 =  no, 1 = initializing, 2 = initialized */
 78              
 79                  ThreadID ioThreadId;
 80 mike     1.1 };
 81              
 82              MI_Result ProvMgr_Init(
 83                  ProvMgr* self,
 84                  Selector* selector,
 85                  ProvMgrCallbackOnIdle idleCallback,
 86                  void* idleCallbackData,
 87                  const char* providerDir);
 88              
 89              MI_Result ProvMgr_Destroy(
 90                  ProvMgr* self);
 91              
 92 krisbash 1.4 MI_Result ProvMgr_NewRequest(
 93                  _In_ ProvMgr* self, 
 94                  _In_ const ProvRegEntry* proventry,
 95                  _Inout_ InteractionOpenParams* params );
 96                  
 97              typedef struct _ProvMgr_OpenCallbackData
 98              {
 99                  ProvMgr*        self;
100                  ProvRegEntry*   provRegEntry;
101              } ProvMgr_OpenCallbackData;
102              
103              MI_INLINE
104              void ProvMgr_OpenCallback(
105                  _Inout_ InteractionOpenParams* params )
106              {
107                  MI_Result result;
108                  ProvMgr_OpenCallbackData* data =  (ProvMgr_OpenCallbackData*)params->callbackData;
109 mike     1.1 
110 krisbash 1.4     result = ProvMgr_NewRequest( data->self, data->provRegEntry, params );
111                  if( MI_RESULT_OK != result )
112                  {
113                      Strand_FailOpenWithResult(params, result, PostResultMsg_NewAndSerialize);
114                  }
115              }
116                  
117 mike     1.1 /* MI_ServerFT is preceded directly by one of these. Providers may
118               * inerally case backwards to find this structure but they should verify
119               * the magic number.
120               */
121              typedef struct _ProvMgrFT
122              {
123                  MI_Uint32 magic;
124                  void* (*FindSymbol)(const char* name);
125              }
126              ProvMgrFT;
127              
128              #define PROVMGRFT_MAGIC 0xF19768D7
129              
130              /* 
131                  Provider access
132              */
133 krisbash 1.4 
134              typedef struct _Library Library;
135              
136              typedef struct _Provider
137              {
138                  struct _Provider* next;
139                  struct _Provider* prev;
140              
141                  MI_CONST MI_ClassDecl* classDecl;
142                  void* self;
143              
144                  /* number of outstanding requests */
145                  volatile ptrdiff_t   refCounter;
146              
147                  /* time when last outstanding request was handled */
148                  MI_Uint64   idleSince;
149              
150                  /* indicator if Provider refused idle-unload */
151                  MI_Boolean  refusedUnload;
152              
153                  /* pointer to lib object */
154 krisbash 1.4     Library* lib;
155              
156              #ifndef DISABLE_INDICATION
157                  /* memory of subMgr was allocated along with Provider object */
158                  /* which will be released upon freeing Provider */
159                  struct _SubscriptionManager* subMgr;
160              #endif /* #ifndef DISABLE_INDICATION */
161              
162              }Provider;
163              
164              struct _Library
165              {
166                  struct _Library* next;
167                  struct _Library* prev;
168                  char libraryName[PAL_MAX_PATH_SIZE];
169                  Shlib* handle;
170                  const MI_Module* module;
171                  MI_Module_Self* self;
172                  struct _Provider* head;
173                  struct _Provider* tail;
174                  /* make provider list threadsafe */
175 krisbash 1.4     Lock provlock;
176                  ProvMgr* provmgr; 
177                  int instanceLifetimeContext;
178              };
179 mike     1.1 
180              /*
181                  Adding reference to the provider:
182                  used by context functions
183              */
184              void Provider_Addref(Provider* provider);
185              
186              /*
187 krisbash 1.4  * Finalize provider before free memory
188               */
189              void Provider_Finalize(_In_ _Post_invalid_ Provider* provider);
190              
191              /*
192 mike     1.1     Decrementing provider's reference
193                  so prov mgr knows when provider becomes idle
194              */
195              void Provider_Release(Provider* provider);
196              
197              /*
198                  Sets 'refuse-unload' provider option
199              */
200              void Provider_SetRefuseUnloadFlag(Provider* provider, MI_Boolean flag);
201              
202 krisbash 1.4 
203              #ifndef DISABLE_INDICATION
204              
205 mike     1.1 /*
206 krisbash 1.4  * Disables indications on the specified provider.  Must be called once the
207               * last subscription has been removed from the provider.
208               */
209              MI_Result Provider_TerminateIndication(
210                  _In_ Provider* provider,
211                  _In_ MI_Result result, 
212                  _In_opt_ const ZChar* errorMessage,
213                  _In_opt_ const MI_Instance* cimError );
214              
215              /*
216               * Invoke EnableIndication if not called yet;
217               * and invoke Subscribe call to provider;
218               *
219               * To ensure enable/disable thread-safe, and since
220               * OMI has single IO thread, this function has to be scheduled
221               * on separate thread for OMI.
222               * TODO: remove separate thread if have multi-IO threads implemented
223               */
224              void Provider_InvokeSubscribe(
225                  _In_ Provider* provider,
226                  _In_ SubscribeReq* msg,
227 krisbash 1.4     _In_ SubscriptionContext* subscrContext);
228              
229              MI_Result Provider_InvokeDisable(
230                  _Inout_ Provider* provider);
231              
232              /*
233               * Deletes the specified subscription.  This should only be called from a
234               * SubscriptionContext's Post handler.  Calls DisableIndications if it is the
235               * last subscription for a provider.
236               */
237              MI_Result Provider_RemoveSubscription(
238                  _Inout_ Provider* provider,
239                  _In_ MI_Uint64 subscriptionID);
240              
241              /*
242               * For Internal use only
243               *
244               * Designed for use by Context handlers for invoking Unsubscribe requests on
245               * the specified provider
246               */
247              MI_Result Provider_ContextInvokeUnsubscribe(
248 krisbash 1.4     _Inout_ Provider* provider,
249                  _Inout_ SubscribeReq* originalMsg,
250                  _In_ MI_Uint64 subscriptionID);
251              
252              #endif /* #ifndef DISABLE_INDICATION */
253              
254              
255              /* Implementation for MI_Context_GetLocalSession as the actual session is owned by the ProvMgr */
256              MI_Result ProvMgr_GetLocalSesson(
257                  _Inout_ ProvMgr* self,
258                  _Out_ MI_Session *localSession);
259 mike     1.1 
260              END_EXTERNC
261              
262              #endif /* _provmgr_h */

ViewCVS 0.9.2