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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [snmp/] [lib/] [v2_0/] [src/] [callback.c] - Blame information for rev 773

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

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

powered by: WebSVN 2.1.0

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