[457] | 1 | /**
|
---|
| 2 | * @file
|
---|
| 3 | * SNMP server MIB API to implement thread synchronization
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
| 7 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
---|
| 8 | * All rights reserved.
|
---|
| 9 | *
|
---|
| 10 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
| 11 | * are permitted provided that the following conditions are met:
|
---|
| 12 | *
|
---|
| 13 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
| 14 | * this list of conditions and the following disclaimer.
|
---|
| 15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
| 16 | * this list of conditions and the following disclaimer in the documentation
|
---|
| 17 | * and/or other materials provided with the distribution.
|
---|
| 18 | * 3. The name of the author may not be used to endorse or promote products
|
---|
| 19 | * derived from this software without specific prior written permission.
|
---|
| 20 | *
|
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
---|
| 22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
---|
| 23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
---|
| 24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
| 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
---|
| 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
| 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
| 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
---|
| 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
---|
| 30 | * OF SUCH DAMAGE.
|
---|
| 31 | *
|
---|
| 32 | * This file is part of the lwIP TCP/IP stack.
|
---|
| 33 | *
|
---|
| 34 | * Author: Dirk Ziegelmeier <dziegel@gmx.de>
|
---|
| 35 | *
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #ifndef LWIP_HDR_APPS_SNMP_THREADSYNC_H
|
---|
| 39 | #define LWIP_HDR_APPS_SNMP_THREADSYNC_H
|
---|
| 40 |
|
---|
| 41 | #include "lwip/apps/snmp_opts.h"
|
---|
| 42 |
|
---|
| 43 | #ifdef __cplusplus
|
---|
| 44 | extern "C" {
|
---|
| 45 | #endif
|
---|
| 46 |
|
---|
| 47 | #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
|
---|
| 48 |
|
---|
| 49 | #include "lwip/apps/snmp_core.h"
|
---|
| 50 | #include "lwip/sys.h"
|
---|
| 51 |
|
---|
| 52 | typedef void (*snmp_threadsync_called_fn)(void* arg);
|
---|
| 53 | typedef void (*snmp_threadsync_synchronizer_fn)(snmp_threadsync_called_fn fn, void* arg);
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | /** Thread sync runtime data. For internal usage only. */
|
---|
| 57 | struct threadsync_data
|
---|
| 58 | {
|
---|
| 59 | union {
|
---|
| 60 | snmp_err_t err;
|
---|
| 61 | s16_t s16;
|
---|
| 62 | } retval;
|
---|
| 63 | union {
|
---|
| 64 | const u32_t *root_oid;
|
---|
| 65 | void *value;
|
---|
| 66 | } arg1;
|
---|
| 67 | union {
|
---|
| 68 | u8_t root_oid_len;
|
---|
| 69 | u16_t len;
|
---|
| 70 | } arg2;
|
---|
| 71 | const struct snmp_threadsync_node *threadsync_node;
|
---|
| 72 | struct snmp_node_instance proxy_instance;
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | /** Thread sync instance. Needed EXCATLY once for every thread to be synced into. */
|
---|
| 76 | struct snmp_threadsync_instance
|
---|
| 77 | {
|
---|
| 78 | sys_sem_t sem;
|
---|
| 79 | sys_mutex_t sem_usage_mutex;
|
---|
| 80 | snmp_threadsync_synchronizer_fn sync_fn;
|
---|
| 81 | struct threadsync_data data;
|
---|
| 82 | };
|
---|
| 83 |
|
---|
| 84 | /** SNMP thread sync proxy leaf node */
|
---|
| 85 | struct snmp_threadsync_node
|
---|
| 86 | {
|
---|
| 87 | /* inherited "base class" members */
|
---|
| 88 | struct snmp_leaf_node node;
|
---|
| 89 |
|
---|
| 90 | const struct snmp_leaf_node *target;
|
---|
| 91 | struct snmp_threadsync_instance *instance;
|
---|
| 92 | };
|
---|
| 93 |
|
---|
| 94 | snmp_err_t snmp_threadsync_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance);
|
---|
| 95 | snmp_err_t snmp_threadsync_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance);
|
---|
| 96 |
|
---|
| 97 | /** Create thread sync proxy node */
|
---|
| 98 | #define SNMP_CREATE_THREAD_SYNC_NODE(oid, target_leaf_node, threadsync_instance) \
|
---|
| 99 | {{{ SNMP_NODE_THREADSYNC, (oid) }, \
|
---|
| 100 | snmp_threadsync_get_instance, \
|
---|
| 101 | snmp_threadsync_get_next_instance }, \
|
---|
| 102 | (target_leaf_node), \
|
---|
| 103 | (threadsync_instance) }
|
---|
| 104 |
|
---|
| 105 | /** Create thread sync instance data */
|
---|
| 106 | void snmp_threadsync_init(struct snmp_threadsync_instance *instance, snmp_threadsync_synchronizer_fn sync_fn);
|
---|
| 107 |
|
---|
| 108 | #endif /* LWIP_SNMP */
|
---|
| 109 |
|
---|
| 110 | #ifdef __cplusplus
|
---|
| 111 | }
|
---|
| 112 | #endif
|
---|
| 113 |
|
---|
| 114 | #endif /* LWIP_HDR_APPS_SNMP_THREADSYNC_H */
|
---|