(file) Return to indication_objects.c CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPIR

  1 dave.sudlik 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 dave.sudlik 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                 
 35                 /*
 36 ms.aruran   1.4     This file contains all necessary methods to keep track of the indication
 37                     objects created in a particular context.
 38 dave.sudlik 1.1 */
 39                 
 40                 
 41                 #include <stdio.h>
 42                 #include <stdlib.h>
 43                 #include <string.h>
 44                 #include <errno.h>
 45                 #if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
 46 ms.aruran   1.4 # include <error.h>
 47 dave.sudlik 1.1 #endif
 48                 
 49                 
 50                 #include "indication_objects.h"
 51                 #include "debug.h"
 52                 
 53                 #include <Pegasus/Provider/CMPI/cmpidt.h>
 54                 #include <Pegasus/Provider/CMPI/cmpimacs.h>
 55                 #include <Pegasus/Provider/CMPI/cmpift.h>
 56                 
 57                 extern CMPIBrokerExtFT *CMPI_BrokerExt_Ftab;
 58                 
 59                 static indication_objects *__indication_objects = NULL;
 60                 
 61                 static CMPI_MUTEX_TYPE _indication_objects_lock = NULL;
 62                 
 63                 #define INIT_LOCK(l) if (l==NULL) l=CMPI_BrokerExt_Ftab->newMutex(0);
 64                 
 65                 
 66                 // Helper function
 67                 void __free_ind_object (ind_object *obj)
 68 dave.sudlik 1.1 {
 69 ms.aruran   1.4     switch (obj->type)
 70                     {
 71                         case PEGASUS_INDICATION_OBJECT_TYPE_CMPI_SELECT_EXP :
 72                             CMRelease ( (CMPISelectExp*)obj->id);
 73                             break;
 74                         case PEGASUS_INDICATION_OBJECT_TYPE_CMPI_SELECT_COND:
 75                             CMRelease ( (CMPISelectCond*)obj->id);
 76                             break;
 77                         case PEGASUS_INDICATION_OBJECT_TYPE_CMPI_SUB_COND:
 78                             CMRelease ( (CMPISubCond*)obj->id);
 79                             break;
 80                         case PEGASUS_INDICATION_OBJECT_TYPE_CMPI_PREDICATE:
 81                             CMRelease ( (CMPIPredicate*)obj->id);
 82                             break;
 83                         default :
 84                             TRACE_CRITICAL(("Unknown Object type: %d", obj->type ));
 85                     }
 86 dave.sudlik 1.1 }
 87                 
 88                 /*
 89 ms.aruran   1.4     This function creates reference to the Object created in MB.
 90                     This reference is passed to Remote Daemon, any changes or any
 91                     calls made on this object on daemon side, will make UP calls
 92                     to MB and uses this object.
 93 dave.sudlik 1.1 */
 94 ms.aruran   1.4 CMPIUint32 create_indicationObject (
 95                     void *obj, 
 96                     CMPIUint32 ctx_id, 
 97                     CMPIUint8 type)
 98 dave.sudlik 1.1 {
 99                     indication_objects *tmp;
100                     ind_object *ind_obj;
101                 
102                     TRACE_NORMAL(("Creating Indication Object."));
103                 
104                     INIT_LOCK(_indication_objects_lock);
105                     CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);
106                 
107                     tmp = __indication_objects;
108                     while (tmp)
109                     {
110                         if (tmp->ctx_id == ctx_id)
111                         {
112                             break;
113                         }
114                         tmp = tmp->next;
115                     }
116                     if (!tmp)
117                     {
118                         tmp = (indication_objects *)
119 ms.aruran   1.4         malloc ( sizeof ( indication_objects ) );
120 dave.sudlik 1.1         tmp->ctx_id = ctx_id;
121                         tmp->next = __indication_objects;
122                         __indication_objects = tmp;
123                         tmp->objects = NULL;
124                     }
125                     ind_obj = (ind_object*) malloc ( sizeof ( ind_object ) );
126                     ind_obj->id = (CMPIUint32) obj;
127                     ind_obj->type = type;
128                     ind_obj->next = tmp->objects;
129                     tmp->objects = ind_obj;
130                 
131                     CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
132                 
133                     TRACE_INFO(("Created object with id: %u", ind_obj->id ));
134                 
135                     return ind_obj->id;
136                 }
137                 
138                 int remove_indicationObject (void *obj, CMPIUint32 ctx_id)
139                 {
140                     ind_object **tmp;
141 dave.sudlik 1.1     indication_objects *curr;
142                     CMPIUint32 id = ( (ind_object*)obj)->id;
143                 
144                     TRACE_NORMAL(("Deleting Indication Object."));
145                 
146                     INIT_LOCK(_indication_objects_lock);
147                     CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);
148                     curr = __indication_objects;
149                     while (curr)
150                     {
151                         if (curr->ctx_id == ctx_id)
152                         {
153                             break;
154                         }
155                         curr = curr->next;
156                     }
157 ms.aruran   1.4     for (tmp = &curr->objects; *tmp != NULL; *tmp = (*tmp)->next)
158 dave.sudlik 1.1     {
159 ms.aruran   1.4         if ((*tmp)->id == id)
160 dave.sudlik 1.1         {
161                             ind_object *r = (*tmp);
162                             (*tmp) = r->next;
163                             __free_ind_object (r);
164                             TRACE_INFO(("Deleted Indication Object with ID: %u", id));
165                             CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
166                             return 0;
167                         }
168                     }
169                     CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
170 ms.aruran   1.4     return -1;
171 dave.sudlik 1.1 }
172                 
173                 void* get_indicationObject (CMPIUint32 id, CMPIUint32 ctx_id)
174                 {
175                     indication_objects *curr;
176                     ind_object *tmp;
177                     int global_context = 0;
178                 
179                     TRACE_NORMAL(("Getting the  Indication Object."));
180                 
181                     INIT_LOCK(_indication_objects_lock);
182                     CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);
183                 
184                     do
185                     {
186                         curr = __indication_objects;
187                         while (curr)
188                         {
189                             if (curr->ctx_id == ctx_id)
190                             {
191                                 break;
192 dave.sudlik 1.1             }
193                             curr = curr->next;
194                         }
195                         if (!curr && !global_context)
196                         {
197 ms.aruran   1.4             global_context = 1;
198                             ctx_id = PEGASUS_INDICATION_GLOBAL_CONTEXT;
199 dave.sudlik 1.1         }
200                         else
201                         {
202                             break;
203                         }
204                     }while (global_context);
205                 
206 ms.aruran   1.4     for (tmp = curr ? curr->objects : NULL; tmp != NULL; tmp = tmp->next)
207 dave.sudlik 1.1     {
208                         if (tmp->id == id)
209                         {
210                             TRACE_INFO(("Got the Indication Object with ID: %u", id));
211                             CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
212 ms.aruran   1.4             return(void*)tmp->id;
213 dave.sudlik 1.1         }
214                     }
215                     CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
216                 
217 ms.aruran   1.4     return NULL;
218 dave.sudlik 1.1 
219                 }
220                 
221                 void cleanup_indicationObjects (CMPIUint32 ctx_id)
222                 {
223 venkat.puvvada 1.3     indication_objects *tmp, *prev;
224 dave.sudlik    1.1     ind_object *obj;
225                    
226                        TRACE_NORMAL(("Cleaning all Indication Objects."));
227                    
228                        INIT_LOCK(_indication_objects_lock);
229                        CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);
230                        tmp = __indication_objects;
231                        while (tmp)
232                        {
233                            if (tmp->ctx_id == ctx_id)
234                            {
235                                break;
236                            }
237 venkat.puvvada 1.3         prev = tmp;
238 dave.sudlik    1.1         tmp = tmp->next;
239                        }
240 venkat.puvvada 1.3     if (!tmp)
241                        {
242                            TRACE_CRITICAL(("Indication context id (%u) not found.", ctx_id));
243                            return;
244                        }
245 dave.sudlik    1.1     while (tmp->objects)
246                        {
247                            obj = tmp->objects;
248                            tmp->objects = tmp->objects->next;
249                            __free_ind_object (obj);
250                        }
251 venkat.puvvada 1.3     if (tmp == __indication_objects)
252                        {
253                            __indication_objects = __indication_objects->next;
254                        }
255                        else
256                        {
257                            prev->next = tmp->next;
258                        }
259                        free (tmp);
260 dave.sudlik    1.1     CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
261                    }
262                    

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2