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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2