32 #if LWIP_SNMP && (NO_SYS == 0) 40 call_synced_function(
struct threadsync_data *call_data, snmp_threadsync_called_fn fn)
42 sys_mutex_lock(&call_data->threadsync_node->instance->sem_usage_mutex);
43 call_data->threadsync_node->instance->sync_fn(fn, call_data);
44 sys_sem_wait(&call_data->threadsync_node->instance->sem);
49 threadsync_get_value_synced(
void *ctx)
51 struct threadsync_data *call_data = (
struct threadsync_data*)ctx;
53 call_data->retval.u16 = call_data->proxy_instance.get_value(&call_data->proxy_instance, call_data->arg1.value);
58 threadsync_get_value(
struct snmp_node_instance* instance,
void* value)
60 struct threadsync_data *call_data = (
struct threadsync_data*)instance->reference.ptr;
62 call_data->arg1.value = value;
63 call_synced_function(call_data, threadsync_get_value_synced);
65 return call_data->retval.u16;
69 threadsync_set_test_synced(
void *ctx)
71 struct threadsync_data *call_data = (
struct threadsync_data*)ctx;
73 call_data->retval.u8 = call_data->proxy_instance.set_test(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
78 threadsync_set_test(
struct snmp_node_instance* instance,
u16_t len,
void *value)
80 struct threadsync_data *call_data = (
struct threadsync_data*)instance->reference.ptr;
82 call_data->arg1.value = value;
83 call_data->arg2.len = len;
84 call_synced_function(call_data, threadsync_set_test_synced);
86 return call_data->retval.u8;
90 threadsync_set_value_synced(
void *ctx)
92 struct threadsync_data *call_data = (
struct threadsync_data*)ctx;
94 call_data->retval.u8 = call_data->proxy_instance.set_value(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
99 threadsync_set_value(
struct snmp_node_instance* instance,
u16_t len,
void *value)
101 struct threadsync_data *call_data = (
struct threadsync_data*)instance->reference.ptr;
103 call_data->arg1.value = value;
104 call_data->arg2.len = len;
105 call_synced_function(call_data, threadsync_set_value_synced);
107 return call_data->retval.u8;
111 threadsync_release_instance_synced(
void* ctx)
113 struct threadsync_data *call_data = (
struct threadsync_data*)ctx;
115 call_data->proxy_instance.release_instance(&call_data->proxy_instance);
120 threadsync_release_instance(
struct snmp_node_instance *instance)
122 struct threadsync_data *call_data = (
struct threadsync_data*)instance->reference.ptr;
124 if(call_data->proxy_instance.release_instance !=
NULL) {
125 call_synced_function(call_data, threadsync_release_instance_synced);
130 get_instance_synced(
void* ctx)
132 struct threadsync_data *call_data = (
struct threadsync_data*)ctx;
133 const struct snmp_leaf_node *leaf = (
const struct snmp_leaf_node*)call_data->proxy_instance.node;
135 call_data->retval.u8 = leaf->get_instance(call_data->arg1.root_oid, call_data->arg2.root_oid_len, &call_data->proxy_instance);
141 get_next_instance_synced(
void* ctx)
143 struct threadsync_data *call_data = (
struct threadsync_data*)ctx;
144 const struct snmp_leaf_node *leaf = (
const struct snmp_leaf_node*)call_data->proxy_instance.node;
146 call_data->retval.u8 = leaf->get_next_instance(call_data->arg1.root_oid, call_data->arg2.root_oid_len, &call_data->proxy_instance);
152 do_sync(
const u32_t *root_oid,
u8_t root_oid_len,
struct snmp_node_instance* instance, snmp_threadsync_called_fn fn)
154 const struct snmp_threadsync_node *threadsync_node = (
const struct snmp_threadsync_node*)instance->node;
155 struct threadsync_data *call_data = &threadsync_node->instance->data;
157 if(threadsync_node->node.node.oid != threadsync_node->target->node.oid) {
159 return SNMP_ERR_NOSUCHINSTANCE;
162 memset(&call_data->proxy_instance, 0,
sizeof(call_data->proxy_instance));
164 instance->reference.ptr = call_data;
165 snmp_oid_assign(&call_data->proxy_instance.instance_oid, instance->instance_oid.id, instance->instance_oid.len);
167 call_data->proxy_instance.node = &threadsync_node->target->node;
168 call_data->threadsync_node = threadsync_node;
170 call_data->arg1.root_oid = root_oid;
171 call_data->arg2.root_oid_len = root_oid_len;
172 call_synced_function(call_data, fn);
174 if(call_data->retval.u8 == SNMP_ERR_NOERROR) {
175 instance->access = call_data->proxy_instance.access;
176 instance->asn1_type = call_data->proxy_instance.asn1_type;
177 instance->release_instance = threadsync_release_instance;
178 instance->get_value = (call_data->proxy_instance.get_value !=
NULL)? threadsync_get_value :
NULL;
179 instance->set_value = (call_data->proxy_instance.set_value !=
NULL)? threadsync_set_value :
NULL;
180 instance->set_test = (call_data->proxy_instance.set_test !=
NULL)? threadsync_set_test :
NULL;
181 snmp_oid_assign(&instance->instance_oid, call_data->proxy_instance.instance_oid.id, call_data->proxy_instance.instance_oid.len);
184 return call_data->retval.u8;
188 snmp_threadsync_get_instance(
const u32_t *root_oid,
u8_t root_oid_len,
struct snmp_node_instance* instance)
190 return do_sync(root_oid, root_oid_len, instance, get_instance_synced);
194 snmp_threadsync_get_next_instance(
const u32_t *root_oid,
u8_t root_oid_len,
struct snmp_node_instance* instance)
196 return do_sync(root_oid, root_oid_len, instance, get_next_instance_synced);
200 void snmp_threadsync_init(
struct snmp_threadsync_instance *instance, snmp_threadsync_synchronizer_fn sync_fn)
206 instance->sync_fn = sync_fn;
err_t sys_mutex_new(sys_mutex_t *mutex)
void sys_mutex_unlock(sys_mutex_t *mutex)
void sys_mutex_lock(sys_mutex_t *mutex)
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
#define sys_sem_wait(sem)
#define LWIP_ASSERT(message, assertion)
void sys_sem_signal(sys_sem_t *sem)
#define LWIP_DEBUGF(debug, message)