From ed929947845a1bf101db03a8eaf9ccb6d55a9496 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Thu, 29 Mar 2012 18:05:07 +0200 Subject: [PATCH] Clean-up and fix for rest-server-example. --- apps/er-coap-07/er-coap-07-observing.c | 3 +++ apps/er-coap-07/er-coap-07-separate.c | 2 +- apps/er-coap-07/er-coap-07-separate.h | 2 +- apps/erbium/erbium.h | 4 ++-- examples/er-rest-example/Makefile | 6 +++--- examples/er-rest-example/rest-server-example.c | 9 +++------ 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/er-coap-07/er-coap-07-observing.c b/apps/er-coap-07/er-coap-07-observing.c index 5c8b5e465..23fae45c4 100644 --- a/apps/er-coap-07/er-coap-07-observing.c +++ b/apps/er-coap-07/er-coap-07-observing.c @@ -60,6 +60,9 @@ LIST(observers_list); coap_observer_t * coap_add_observer(uip_ipaddr_t *addr, uint16_t port, const uint8_t *token, size_t token_len, const char *url) { + /* Remove existing observe relationship, if any. */ + coap_remove_observer_by_url(addr, port, url); + coap_observer_t *o = memb_alloc(&observers_memb); if (o) diff --git a/apps/er-coap-07/er-coap-07-separate.c b/apps/er-coap-07/er-coap-07-separate.c index b9bca9abc..7a2a7b859 100644 --- a/apps/er-coap-07/er-coap-07-separate.c +++ b/apps/er-coap-07/er-coap-07-separate.c @@ -54,7 +54,7 @@ #endif /*----------------------------------------------------------------------------*/ -int +void coap_separate_reject() { coap_error_code = SERVICE_UNAVAILABLE_5_03; diff --git a/apps/er-coap-07/er-coap-07-separate.h b/apps/er-coap-07/er-coap-07-separate.h index 62b25c095..896485d42 100644 --- a/apps/er-coap-07/er-coap-07-separate.h +++ b/apps/er-coap-07/er-coap-07-separate.h @@ -59,7 +59,7 @@ typedef struct coap_separate { } coap_separate_t; int coap_separate_handler(resource_t *resource, void *request, void *response); -int coap_separate_reject(); +void coap_separate_reject(); int coap_separate_accept(void *request, coap_separate_t *separate_store); void coap_separate_resume(void *response, coap_separate_t *separate_store, uint8_t code); diff --git a/apps/erbium/erbium.h b/apps/erbium/erbium.h index 2a511e8e1..bf0cb8eee 100644 --- a/apps/erbium/erbium.h +++ b/apps/erbium/erbium.h @@ -269,8 +269,8 @@ resource_t resource_##name = {NULL, flags, url, attributes, parent##_handler, NU */ #define EVENT_RESOURCE(name, flags, url, attributes) \ void name##_handler(void *, void *, uint8_t *, uint16_t, int32_t *); \ -resource_t resource_##name = {NULL, flags, url, attributes, name##_handler, NULL, NULL, NULL}; \ -int name##_event_handler(resource_t*) +void name##_event_handler(resource_t*); \ +resource_t resource_##name = {NULL, flags, url, attributes, name##_handler, NULL, NULL, NULL} /* * Macro to define a periodic resource diff --git a/examples/er-rest-example/Makefile b/examples/er-rest-example/Makefile index 38029c574..979e9f477 100644 --- a/examples/er-rest-example/Makefile +++ b/examples/er-rest-example/Makefile @@ -5,8 +5,10 @@ CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" # for static routing, if enabled ifneq ($(TARGET), minimal-net) +ifneq ($(TARGET), native) PROJECT_SOURCEFILES += static-routing.c endif +endif # variable for root Makefile.include WITH_UIP6=1 @@ -25,7 +27,7 @@ else ${info INFO: compiling without RPL} UIP_CONF_RPL=0 CFLAGS += -DUIP_CONF_ND6_DEF_MAXDADNS=0 -CFLAGS += -DHARD_CODED_ADDRESS=\"2001:620:8:1010::10\" +CFLAGS += -DHARD_CODED_ADDRESS=\"fdfd::10\" CFLAGS += -DUIP_CONF_BUFFER_SIZE=1280 endif @@ -37,13 +39,11 @@ ifeq ($(WITH_COAP), 7) ${info INFO: compiling with CoAP-07} CFLAGS += -DWITH_COAP=7 CFLAGS += -DREST=coap_rest_implementation -CFLAGS += -DUIP_CONF_TCP=0 APPS += er-coap-07 else ifeq ($(WITH_COAP), 3) ${info INFO: compiling with CoAP-03} CFLAGS += -DWITH_COAP=3 CFLAGS += -DREST=coap_rest_implementation -CFLAGS += -DUIP_CONF_TCP=0 APPS += er-coap-03 else ${info INFO: compiling with HTTP} diff --git a/examples/er-rest-example/rest-server-example.c b/examples/er-rest-example/rest-server-example.c index a958c1d2a..911069d88 100644 --- a/examples/er-rest-example/rest-server-example.c +++ b/examples/er-rest-example/rest-server-example.c @@ -381,16 +381,14 @@ separate_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer */ if (separate_active) { - REST.set_response_status(response, REST.status.SERVICE_UNAVAILABLE); - const char *msg = "AlreadyInUse"; - REST.set_response_payload(response, msg, strlen(msg)); + coap_separate_reject(); } else { separate_active = 1; /* Take over and skip response by engine. */ - coap_separate_yield(request, &separate_store->request_metadata); + coap_separate_accept(request, &separate_store->request_metadata); /* Be aware to respect the Block2 option, which is also stored in the coap_separate_t. */ /* @@ -710,8 +708,7 @@ PROCESS_THREAD(rest_server_example, ev, data) rest_activate_event_resource(&resource_event); #endif #if defined (PLATFORM_HAS_BUTTON) && REST_RES_SEPARATE && WITH_COAP > 3 - /* Use this pre-handler for separate response resources. */ - rest_set_pre_handler(&resource_separate, coap_separate_handler); + /* No pre-handler anymore, user coap_separate_accept() and coap_separate_reject(). */ rest_activate_resource(&resource_separate); #endif #if defined (PLATFORM_HAS_BUTTON) && (REST_RES_EVENT || (REST_RES_SEPARATE && WITH_COAP > 3))