OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [snmp/] [lib/] [current/] [src/] [callback.c] - Blame information for rev 856

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      ./lib/current/src/callback.c
4
//
5
//
6
//==========================================================================
7
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
8
// -------------------------------------------                              
9
// This file is part of eCos, the Embedded Configurable Operating System.   
10
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
11
//
12
// eCos is free software; you can redistribute it and/or modify it under    
13
// the terms of the GNU General Public License as published by the Free     
14
// Software Foundation; either version 2 or (at your option) any later      
15
// version.                                                                 
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT      
18
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
20
// for more details.                                                        
21
//
22
// You should have received a copy of the GNU General Public License        
23
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
24
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
25
//
26
// As a special exception, if other files instantiate templates or use      
27
// macros or inline functions from this file, or you compile this file      
28
// and link it with other works to produce a work based on this file,       
29
// this file does not by itself cause the resulting work to be covered by   
30
// the GNU General Public License. However the source code for this file    
31
// must still be made available in accordance with section (3) of the GNU   
32
// General Public License v2.                                               
33
//
34
// This exception does not invalidate any other reasons why a work based    
35
// on this file might be covered by the GNU General Public License.         
36
// -------------------------------------------                              
37
// ####ECOSGPLCOPYRIGHTEND####                                              
38
//####UCDSNMPCOPYRIGHTBEGIN####
39
//
40
// -------------------------------------------
41
//
42
// Portions of this software may have been derived from the UCD-SNMP
43
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
44
// California at Davis, which was originally based on the Carnegie Mellon
45
// University SNMP implementation.  Portions of this software are therefore
46
// covered by the appropriate copyright disclaimers included herein.
47
//
48
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
49
// -------------------------------------------
50
//
51
//####UCDSNMPCOPYRIGHTEND####
52
//==========================================================================
53
//#####DESCRIPTIONBEGIN####
54
//
55
// Author(s):    hmt
56
// Contributors: hmt
57
// Date:         2000-05-30
58
// Purpose:      Port of UCD-SNMP distribution to eCos.
59
// Description:  
60
//              
61
//
62
//####DESCRIPTIONEND####
63
//
64
//==========================================================================
65
/********************************************************************
66
       Copyright 1989, 1991, 1992 by Carnegie Mellon University
67
 
68
                          Derivative Work -
69
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
70
 
71
                         All Rights Reserved
72
 
73
Permission to use, copy, modify and distribute this software and its
74
documentation for any purpose and without fee is hereby granted,
75
provided that the above copyright notice appears in all copies and
76
that both that copyright notice and this permission notice appear in
77
supporting documentation, and that the name of CMU and The Regents of
78
the University of California not be used in advertising or publicity
79
pertaining to distribution of the software without specific written
80
permission.
81
 
82
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
83
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
84
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
85
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
86
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
87
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
88
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
89
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
90
*********************************************************************/
91
/* callback.c: A generic callback mechanism */
92
 
93
#include <config.h>
94
#include <sys/types.h>
95
#include <stdio.h>
96
#if HAVE_STDLIB_H
97
#include <stdlib.h>
98
#endif
99
#if HAVE_WINSOCK_H
100
#include <winsock.h>
101
#endif
102
#if HAVE_NETINET_IN_H
103
#include <netinet/in.h>
104
#endif
105
#if HAVE_STRING_H
106
#include <string.h>
107
#else
108
#include <strings.h>
109
#endif
110
 
111
#if HAVE_DMALLOC_H
112
#include <dmalloc.h>
113
#endif
114
 
115
#include "tools.h"
116
#include "callback.h"
117
#include "asn1.h"
118
#include "snmp_api.h"
119
#include "snmp_debug.h"
120
 
121
static struct snmp_gen_callback *thecallbacks[MAX_CALLBACK_IDS][MAX_CALLBACK_SUBIDS];
122
 
123
/* the chicken. or the egg.  You pick. */
124
void
125
init_callbacks(void) {
126
  /* probably not needed? Should be full of 0's anyway? */
127
  /* (poses a problem if you put init_callbacks() inside of
128
     init_snmp() and then want the app to register a callback before
129
     init_snmp() is called in the first place.  -- Wes */
130
  /* memset(thecallbacks, 0, sizeof(thecallbacks)); */
131
}
132
 
133
int
134
snmp_register_callback(int major, int minor, SNMPCallback *new_callback,
135
                       void *arg) {
136
 
137
  struct snmp_gen_callback *scp;
138
 
139
  if (major >= MAX_CALLBACK_IDS || minor >= MAX_CALLBACK_SUBIDS) {
140
    return SNMPERR_GENERR;
141
  }
142
 
143
  if (thecallbacks[major][minor] != NULL) {
144
    /* get to the end of the list */
145
    for(scp = thecallbacks[major][minor]; scp->next != NULL; scp = scp->next);
146
 
147
    /* mallocate a new entry */
148
    scp->next = SNMP_MALLOC_STRUCT(snmp_gen_callback);
149
    scp = scp->next;
150
  } else {
151
    /* mallocate a new entry */
152
    scp = SNMP_MALLOC_STRUCT(snmp_gen_callback);
153
 
154
    /* make the new node the head */
155
    thecallbacks[major][minor] = scp;
156
  }
157
 
158
  if (scp == NULL)
159
    return SNMPERR_GENERR;
160
 
161
  scp->sc_client_arg = arg;
162
  scp->sc_callback = new_callback;
163
 
164
  DEBUGMSGTL(("callback","registered callback for maj=%d min=%d\n",
165
              major, minor));
166
 
167
  return SNMPERR_SUCCESS;
168
}
169
 
170
int
171
snmp_call_callbacks(int major, int minor, void *caller_arg) {
172
  struct snmp_gen_callback *scp;
173
 
174
  if (major >= MAX_CALLBACK_IDS || minor >= MAX_CALLBACK_SUBIDS) {
175
    return SNMPERR_GENERR;
176
  }
177
 
178
  DEBUGMSGTL(("callback","START calling callbacks for maj=%d min=%d\n",
179
              major, minor));
180
 
181
  /* for each registered callback of type major and minor */
182
  for(scp = thecallbacks[major][minor]; scp != NULL; scp = scp->next) {
183
 
184
    DEBUGMSGTL(("callback","calling a callback for maj=%d min=%d\n",
185
                major, minor));
186
 
187
    /* call them */
188
    (*(scp->sc_callback))(major, minor, caller_arg, scp->sc_client_arg);
189
  }
190
 
191
  DEBUGMSGTL(("callback","END calling callbacks for maj=%d min=%d\n",
192
              major, minor));
193
 
194
  return SNMPERR_SUCCESS;
195
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.