00001 /* 00002 * $Id$ 00003 * 00004 * SNMPStats Module 00005 * Copyright (C) 2006 SOMA Networks, INC. 00006 * Written by: Jeffrey Magder (jmagder@somanetworks.com) 00007 * 00008 * This file is part of Kamailio, a free SIP server. 00009 * 00010 * Kamailio is free software; you can redistribute it and/or modify it 00011 * under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version 00014 * 00015 * Kamailio is distributed in the hope that it will be useful, but 00016 * WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 * USA 00024 * 00025 * History: 00026 * -------- 00027 * 2006-11-23 initial version (jmagder) 00028 */ 00029 00055 #ifndef _SNMPSTATS_USER_UTILITIES_ 00056 #define _SNMPSTATS_USER_UTILITIES_ 00057 00058 #include "../../str.h" 00059 #include "../../locking.h" 00060 00061 #include "snmpstats_globals.h" 00062 #include "hashTable.h" 00063 00064 #include "../usrloc/ucontact.h" 00065 00066 /* Represents an element of the interprocess buffer. */ 00067 typedef struct interprocessBuffer 00068 { 00069 char *stringName; 00070 char *stringContact; 00071 int callbackType; 00072 struct interprocessBuffer *next; 00073 00074 ucontact_t *contactInfo; 00075 00076 } interprocessBuffer_t; 00077 00078 /* Both of these will be used to reference in the interprocess buffer */ 00079 extern interprocessBuffer_t *frontRegUserTableBuffer; 00080 extern interprocessBuffer_t *endRegUserTableBuffer; 00081 00082 /* A request to consume the interprocess buffer could occur at the same time 00083 * there is a request to add to the interprocess buffer. (Or vice-versa). This 00084 * lock is used to prevent these race conditions. */ 00085 extern gen_lock_t *interprocessCBLock; 00086 extern hashSlot_t *hashTable; 00087 00088 /* 00089 * Initialize shared memory used to buffer communication between the usrloc 00090 * module and the SNMPStats module. (Specifically, the user and contact tables) 00091 */ 00092 int initInterprocessBuffers(void); 00093 00094 /* USRLOC Callback Handler: 00095 * 00096 * This function should be registered to receive callbacks from the usrloc 00097 * module. It can be called for any of the callbacks listed in ul_Callback.h. 00098 * The callback type will be passed in 'type', and the contact the callback 00099 * applies to will be supplied in 'contactInfo. This information will be copied 00100 * into the interprocess buffer. The interprocess buffer will beconsumed at a 00101 * later time, when consumeInterprocessBuffer() is called. 00102 * 00103 * This callback is thread safe with respect to the consumeInterprocessBuffer() 00104 * function. Specifically, the interprocess buffer should not be corrupted by 00105 * any race conditions between this function and the consumeInterprocessBuffer() 00106 * function. 00107 */ 00108 void handleContactCallbacks(ucontact_t *contactInfo, int type, void *param); 00109 00110 00111 /* Interprocess Buffer consumption Function. This function will iterate over 00112 * every element of the interprocess buffer, and add or remove the specified 00113 * contacts and users. Whether the contacts are added or removed is dependent 00114 * on if the original element was added as a result of a UL_CONTACT_INSERT or 00115 * UL_CONTACT_EXPIRE callback. 00116 * 00117 * The function will free any memory occupied by the interprocess buffer. 00118 * 00119 * Note: This function is believed to be thread safe. Specifically, it protects 00120 * corruption of the interprocess buffer through the interprocessCBLock. 00121 * This ensures no corruption of the buffer by race conditions. The lock 00122 * has been designed to be occupied for as short a period as possible, so 00123 * as to prevent long waits. Specifically, once we start consumption of 00124 * the list, other processes are free to continue even before we are done. 00125 * This is made possible by simply changing the head of the interprocess 00126 * buffer, and then releasing the lock. 00127 */ 00128 void consumeInterprocessBuffer(void); 00129 00130 void freeInterprocessBuffer(void); 00131 00132 #endif
1.7.1