(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                    This file contains all necessary methods to keep track of the indication
 37                    objects created in a particular context.
 38                 */
 39                 
 40                 
 41                 #include <stdio.h>
 42                 #include <stdlib.h>
 43 dave.sudlik 1.1 #include <string.h>
 44                 #include <errno.h>
 45                 #if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
 46                 #include <error.h>
 47                 #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 dave.sudlik 1.1 
 65                 
 66                 // Helper function
 67                 void __free_ind_object (ind_object *obj)
 68                 {
 69                    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 dave.sudlik 1.1    }
 86                 }
 87                 
 88                 /*
 89                    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                 */
 94                 CMPIUint32 create_indicationObject (void *obj, CMPIUint32 ctx_id, CMPIUint8 type)
 95                 {
 96                     indication_objects *tmp;
 97                     ind_object *ind_obj;
 98                 
 99                     TRACE_NORMAL(("Creating Indication Object."));
100                 
101                     INIT_LOCK(_indication_objects_lock);
102                     CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);
103                 
104                     tmp = __indication_objects;
105                     while (tmp)
106 dave.sudlik 1.1     {
107                         if (tmp->ctx_id == ctx_id)
108                         {
109                             break;
110                         }
111                         tmp = tmp->next;
112                     }
113                     if (!tmp)
114                     {
115                         tmp = (indication_objects *)
116                                malloc ( sizeof ( indication_objects ) );
117                         tmp->ctx_id = ctx_id;
118                         tmp->next = __indication_objects;
119                         __indication_objects = tmp;
120                         tmp->objects = NULL;
121                     }
122                     ind_obj = (ind_object*) malloc ( sizeof ( ind_object ) );
123                     ind_obj->id = (CMPIUint32) obj;
124                     ind_obj->type = type;
125                     ind_obj->next = tmp->objects;
126                     tmp->objects = ind_obj;
127 dave.sudlik 1.1 
128                     CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
129                 
130                     TRACE_INFO(("Created object with id: %u", ind_obj->id ));
131                 
132                     return ind_obj->id;
133                 }
134                 
135                 int remove_indicationObject (void *obj, CMPIUint32 ctx_id)
136                 {
137                     ind_object **tmp;
138                     indication_objects *curr;
139                     CMPIUint32 id = ( (ind_object*)obj)->id;
140                 
141                     TRACE_NORMAL(("Deleting Indication Object."));
142                 
143                     INIT_LOCK(_indication_objects_lock);
144                     CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);
145                     curr = __indication_objects;
146                     while (curr)
147                     {
148 dave.sudlik 1.1         if (curr->ctx_id == ctx_id)
149                         {
150                             break;
151                         }
152                         curr = curr->next;
153                     }
154                     for (tmp = &curr->objects; *tmp != NULL; *tmp = (*tmp)->next )
155                     {
156                         if ( (*tmp)->id == id)
157                         {
158                             ind_object *r = (*tmp);
159                             (*tmp) = r->next;
160                             __free_ind_object (r);
161                             TRACE_INFO(("Deleted Indication Object with ID: %u", id));
162                             CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
163                             return 0;
164                         }
165                     }
166                     CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
167                    return -1;
168                 }
169 dave.sudlik 1.1 
170                 void* get_indicationObject (CMPIUint32 id, CMPIUint32 ctx_id)
171                 {
172                     indication_objects *curr;
173                     ind_object *tmp;
174                     int global_context = 0;
175                 
176                     TRACE_NORMAL(("Getting the  Indication Object."));
177                 
178                     INIT_LOCK(_indication_objects_lock);
179                     CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);
180                 
181                     do
182                     {
183                         curr = __indication_objects;
184                         while (curr)
185                         {
186                             if (curr->ctx_id == ctx_id)
187                             {
188                                 break;
189                             }
190 dave.sudlik 1.1             curr = curr->next;
191                         }
192                         if (!curr && !global_context)
193                         {
194                           global_context = 1;
195                           ctx_id = PEGASUS_INDICATION_GLOBAL_CONTEXT;
196                         }
197                         else
198                         {
199                             break;
200                         }
201                     }while (global_context);
202                 
203                     for (tmp = curr ? curr->objects : NULL; tmp != NULL; tmp = tmp->next )
204                     {
205                         if (tmp->id == id)
206                         {
207                             TRACE_INFO(("Got the Indication Object with ID: %u", id));
208                             CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
209                             return (void*)tmp->id;
210                         }
211 dave.sudlik 1.1     }
212                     CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
213                 
214                    return NULL;
215                 
216                 }
217                 
218                 void cleanup_indicationObjects (CMPIUint32 ctx_id)
219                 {
220                     indication_objects *tmp;
221                     ind_object *obj;
222                 
223                     TRACE_NORMAL(("Cleaning all Indication Objects."));
224                 
225                     INIT_LOCK(_indication_objects_lock);
226                     CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);
227                     tmp = __indication_objects;
228                     while (tmp)
229                     {
230                         if (tmp->ctx_id == ctx_id)
231                         {
232 dave.sudlik 1.1             break;
233                         }
234                         tmp = tmp->next;
235                     }
236                     while (tmp->objects)
237                     {
238                         obj = tmp->objects;
239                         tmp->objects = tmp->objects->next;
240                         __free_ind_object (obj);
241                     }
242                     CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
243                 }
244                 

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2