...
 
Commits (8)
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff is collapsed.
......@@ -122,7 +122,8 @@ oc_delete_link(oc_link_t *link)
oc_memb_free(&oc_params_s, p);
p = (oc_link_params_t *)oc_list_pop(link->params);
}
if (link->resource) {
if (oc_ri_is_app_resource_valid(link->resource) ||
oc_check_if_collection(link->resource)) {
link->resource->num_links--;
}
oc_free_string_array(&(link->rel));
......
......@@ -142,6 +142,19 @@ oc_ri_get_app_resources(void)
{
return oc_list_head(app_resources);
}
bool
oc_ri_is_app_resource_valid(oc_resource_t *resource)
{
oc_resource_t *res = oc_ri_get_app_resources();
while (res) {
if (res == resource) {
return true;
}
res = res->next;
}
return false;
}
#endif
int
......
......@@ -7,6 +7,48 @@
"application/json"
],
"paths":{
"/oc/con": {
"get": {
"description": "Resource that allows for Device specific information to be configured.\n",
"parameters": [
{
"$ref": "#/parameters/interface-all"
}
],
"responses": {
"200": {
"description" : "",
"schema": {
"$ref": "#/definitions/Configuration"
}
}
}
},
"post": {
"description": "Update the information about the Device\n",
"parameters": [
{
"$ref": "#/parameters/interface-rw"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ConfigurationUpdate"
}
}
],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/ConfigurationUpdate"
}
}
}
}
},
"/oic/p":{
"get":{
"responses":{
......@@ -324,6 +366,57 @@
}
},
"type":"object"
},
"Configuration": {
"properties": {
"rt": {
"description": "Resource Type of the Resource",
"items": {
"enum": ["oic.wk.con"],
"type": "string",
"maxLength": 64
},
"minItems": 1,
"uniqueItems": true,
"readOnly": true,
"type": "array",
"default": ["oic.wk.con"]
},
"n": {
"type": "string",
"readOnly": true,
"maxLength": 64,
"description": ""
},
"if" : {
"description": "The OCF Interfaces supported by this Resource",
"items": {
"enum": [
"oic.if.baseline",
"oic.if.rw"
],
"type": "string",
"maxLength": 64
},
"minItems": 1,
"uniqueItems": true,
"readOnly": true,
"type": "array"
}
},
"type" : "object",
"required": ["n"]
},
"ConfigurationUpdate" : {
"properties": {
"n": {
"description": "The human friendly name to be set on the Resource, this is also reflected in the same Property in oic.wk.d",
"maxLength": 64,
"type": "string"
}
},
"required": ["n"],
"type" : "object"
}
},
"info":{
......
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "oc_api.h"
static bool got_discovery_response = false;
static int
app_init(void)
{
int ret = oc_init_platform("Apple", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.phone", "Kishen's IPhone", "1.0", "1.0",
NULL, NULL);
return ret;
}
#define MAX_URI_LENGTH (30)
static char light_1[MAX_URI_LENGTH];
static oc_endpoint_t *light_server;
static bool light_state = false;
static oc_event_callback_retval_t
stop_observe(void *data)
{
(void)data;
PRINT("Stopping OBSERVE\n");
oc_stop_observe(light_1, light_server);
return OC_EVENT_DONE;
}
static void
post_light(oc_client_response_t *data)
{
PRINT("POST_light:\n");
if (data->code == OC_STATUS_CHANGED)
PRINT("POST response OK\n");
else
PRINT("POST response code %d\n", data->code);
}
static void
observe_light(oc_client_response_t *data)
{
PRINT("OBSERVE_light:\n");
oc_rep_t *rep = data->payload;
while (rep != NULL) {
PRINT("key %s, value ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
PRINT("%d\n", rep->value.boolean);
light_state = rep->value.boolean;
break;
default:
break;
}
rep = rep->next;
}
if (oc_init_post(light_1, light_server, NULL, &post_light, LOW_QOS, NULL)) {
oc_rep_start_root_object();
oc_rep_set_boolean(root, state, !light_state);
oc_rep_end_root_object();
if (oc_do_post())
PRINT("Sent POST request\n");
else
PRINT("Could not send POST\n");
} else
PRINT("Could not init POST\n");
}
static oc_discovery_flags_t
discovery(const char *anchor, const char *uri, oc_string_array_t types,
oc_interface_mask_t iface_mask, oc_endpoint_t *endpoint,
oc_resource_properties_t bm, void *user_data)
{
(void)anchor;
(void)iface_mask;
(void)user_data;
(void)bm;
int i;
int uri_len = strlen(uri);
uri_len = (uri_len >= MAX_URI_LENGTH) ? MAX_URI_LENGTH - 1 : uri_len;
for (i = 0; i < oc_string_array_get_allocated_size(types); i++) {
char *t = oc_string_array_get_item(types, i);
if (strlen(t) == 11 && strncmp(t, "oic.r.light", 11) == 0) {
light_server = endpoint;
strncpy(light_1, uri, uri_len);
light_1[uri_len] = '\0';
oc_do_observe(light_1, light_server, NULL, &observe_light, LOW_QOS, NULL);
oc_set_delayed_callback(NULL, &stop_observe, 30);
got_discovery_response = true;
return OC_STOP_DISCOVERY;
}
}
return OC_CONTINUE_DISCOVERY;
}
static oc_event_callback_retval_t
do_discovery(void *data)
{
(void)data;
if (got_discovery_response) {
return OC_EVENT_DONE;
}
oc_do_ip_discovery("oic.r.light", &discovery, NULL);
return OC_EVENT_CONTINUE;
}
static void
issue_requests(void)
{
oc_set_delayed_callback(NULL, &do_discovery, 10);
}
#include "contiki.h"
PROCESS(sample_client_process, "OCF client sample");
AUTOSTART_PROCESSES(&sample_client_process);
static void
signal_event_loop(void)
{
process_post(&sample_client_process, PROCESS_EVENT_TIMER, NULL);
}
PROCESS_THREAD(sample_client_process, ev, data)
{
static struct etimer et;
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.requests_entry = issue_requests };
static oc_clock_time_t next_event;
PROCESS_BEGIN();
int init = oc_main_init(&handler);
if (init < 0)
return init;
while (ev != PROCESS_EVENT_EXIT) {
next_event = oc_main_poll();
if (next_event != 0) {
next_event -= oc_clock_time();
etimer_set(&et, next_event);
}
PROCESS_YIELD();
}
PROCESS_END();
}
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "oc_api.h"
#include "pthread_cond.h"
#include "thread.h"
static int quit;
static mutex_t mutex;
static pthread_cond_t cv;
static struct timespec ts;
static bool got_discovery_response = false;
static void
set_device_custom_property(void *data)
{
(void)data;
oc_set_custom_device_property(purpose, "operate lamp");
}
static int
app_init(void)
{
int ret = oc_init_platform("Apple", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.phone", "Kishen's IPhone", "1.0", "1.0",
set_device_custom_property, NULL);
return ret;
}
#define MAX_URI_LENGTH (30)
static char light_1[MAX_URI_LENGTH];
static oc_endpoint_t *light_server;
static bool light_state = false;
static oc_event_callback_retval_t
stop_observe(void *data)
{
(void)data;
PRINT("Stopping OBSERVE\n");
oc_stop_observe(light_1, light_server);
return OC_EVENT_DONE;
}
static void
post_light(oc_client_response_t *data)
{
PRINT("POST_light:\n");
if (data->code == OC_STATUS_CHANGED)
PRINT("POST response OK\n");
else
PRINT("POST response code %d\n", data->code);
}
static void
observe_light(oc_client_response_t *data)
{
PRINT("OBSERVE_light:\n");
oc_rep_t *rep = data->payload;
while (rep != NULL) {
PRINT("key %s, value ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
PRINT("%d\n", rep->value.boolean);
light_state = rep->value.boolean;
break;
default:
break;
}
rep = rep->next;
}
if (oc_init_post(light_1, light_server, NULL, &post_light, LOW_QOS, NULL)) {
oc_rep_start_root_object();
oc_rep_set_boolean(root, state, !light_state);
oc_rep_end_root_object();
if (oc_do_post())
PRINT("Sent POST request\n");
else
PRINT("Could not send POST\n");
} else
PRINT("Could not init POST\n");
}
static oc_discovery_flags_t
discovery(const char *anchor, const char *uri, oc_string_array_t types,
oc_interface_mask_t iface_mask, oc_endpoint_t *endpoint,
oc_resource_properties_t bm, void *user_data)
{
(void)anchor;
(void)iface_mask;
(void)user_data;
(void)bm;
int i;
int uri_len = strlen(uri);
uri_len = (uri_len >= MAX_URI_LENGTH) ? MAX_URI_LENGTH - 1 : uri_len;
for (i = 0; i < (int)oc_string_array_get_allocated_size(types); i++) {
char *t = oc_string_array_get_item(types, i);
if (strlen(t) == 11 && strncmp(t, "oic.r.light", 11) == 0) {
light_server = endpoint;
strncpy(light_1, uri, uri_len);
light_1[uri_len] = '\0';
oc_do_observe(light_1, light_server, NULL, &observe_light, LOW_QOS, NULL);
oc_set_delayed_callback(NULL, &stop_observe, 30);
got_discovery_response = true;
return OC_STOP_DISCOVERY;
}
}
return OC_CONTINUE_DISCOVERY;
}
static oc_event_callback_retval_t
do_discovery(void *data)
{
(void)data;
if (got_discovery_response) {
return OC_EVENT_DONE;
}
oc_do_ip_discovery("oic.r.light", &discovery, NULL);
return OC_EVENT_CONTINUE;
}
static void
issue_requests(void)
{
oc_set_delayed_callback(NULL, &do_discovery, 10);
}
static void
signal_event_loop(void)
{
mutex_lock(&mutex);
pthread_cond_signal(&cv);
mutex_unlock(&mutex);
}
static char _oc_main_stack[THREAD_STACKSIZE_MAIN];
void *
oc_main_thread(void *arg)
{
(void)arg;
pthread_cond_init(&cv, NULL);
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.requests_entry = issue_requests };
if (oc_main_init(&handler) < 0) {
PRINT("client_riot: failed to initialize stack\n");
return NULL;
}
oc_clock_time_t next_event;
while (quit == 0) {
next_event = oc_main_poll();
mutex_lock(&mutex);
if (next_event == 0) {
pthread_cond_wait(&cv, &mutex);
} else if (oc_clock_time() < next_event) {
ts.tv_sec = (next_event / OC_CLOCK_SECOND);
ts.tv_nsec = (next_event % OC_CLOCK_SECOND) * 1.e09 / OC_CLOCK_SECOND;
pthread_cond_timedwait(&cv, &mutex, &ts);
}
mutex_unlock(&mutex);
}
oc_main_shutdown();
return NULL;
}
int
main(void)
{
thread_create(_oc_main_stack, sizeof(_oc_main_stack), 2, 0, oc_main_thread,
NULL, "OCF event thread");
fgetc(stdin);
quit = 1;
signal_event_loop();
return 0;
}
......@@ -31,7 +31,7 @@
static const size_t DEVICE = 0;
// define application specific values.
static const char *spec_version = "ocf.2.1.1";
static const char *spec_version = "ocf.2.0.5";
static const char *data_model_version = "ocf.res.1.3.0,ocf.sh.1.3.0";
static const char *deivce_uri = "/oic/d";
......
......@@ -7,6 +7,48 @@
"application/json"
],
"paths":{
"/oc/con": {
"get": {
"description": "",
"parameters": [
{
"$ref": "#/parameters/interface-rw"
}
],
"responses": {
"200": {
"description" : "",
"schema": {
"$ref": "#/definitions/Configuration"
}
}
}
},
"post": {
"description": "",
"parameters": [
{
"$ref": "#/parameters/interface-rw"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ConfigurationUpdate"
}
}
],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/ConfigurationUpdate"
}
}
}
}
},
"/platform?if=oic.if.ll":{
"get":{
"responses":{
......@@ -142,7 +184,7 @@
},
"parameters":[
{
"$ref":"#/parameters/interface-update"
"$ref":"#/parameters/interface-all40"
},
{
"schema":{
......@@ -232,7 +274,7 @@
},
"parameters":[
{
"$ref":"#/parameters/interface-all"
"$ref":"#/parameters/interface-rw"
}
],
"description":""
......@@ -250,7 +292,7 @@
},
"parameters":[
{
"$ref":"#/parameters/interface-update"
"$ref":"#/parameters/interface-all40"
},
{
"schema":{
......@@ -350,7 +392,7 @@
"description":""
},
"tag-pos-desc":{
"description":"Descriptive relative position of the Resource",
"description":"",
"type":"string",
"enum":[
"unknown",
......@@ -378,7 +420,7 @@
"tag-pos-rel":{
"type":"array",
"readOnly":true,
"description":"Relative position; against a known [0,0,0] point.",
"description":"",
"minItems":3,
"maxItems":3,
"items":{
......@@ -430,7 +472,7 @@
"items":{
"properties":{
"tag-pos-desc":{
"description":"Descriptive relative position of the Resource",
"description":"",
"type":"string",
"enum":[
"unknown",
......@@ -690,7 +732,7 @@
"description":""
},
"tag-pos-desc":{
"description":"Descriptive relative position of the Resource",
"description":"",
"type":"string",
"enum":[
"unknown",
......@@ -869,7 +911,7 @@
"items":{
"properties":{
"tag-pos-desc":{
"description":"Descriptive relative position of the Resource",
"description":"",
"type":"string",
"enum":[
"unknown",
......@@ -1195,7 +1237,7 @@
"oic.oic-link":{
"properties":{
"tag-pos-desc":{
"description":"Descriptive relative position of the Resource",
"description":"",
"type":"string",
"enum":[
"unknown",
......@@ -1335,7 +1377,7 @@
"description":""
},
"di":{
"type":"string",
"type":"string",
"pattern":"^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
"description":""
},
......@@ -1350,16 +1392,67 @@
"if"
],
"type":"object"
}
},
"Configuration": {
"properties": {
"rt": {
"description": "",
"items": {
"enum": ["oic.wk.con"],
"type": "string",
"maxLength": 64
},
"minItems": 1,
"uniqueItems": true,
"readOnly": true,
"type": "array",
"default": ["oic.wk.con"]
},
"n": {
"type": "string",
"readOnly": true,
"maxLength": 64,
"description": ""
},
"if" : {
"description": "",
"items": {
"enum": [
"oic.if.baseline",
"oic.if.rw"
],
"type": "string",
"maxLength": 64
},
"minItems": 1,
"uniqueItems": true,
"readOnly": true,
"type": "array"
}
},
"type" : "object",
"required": ["n"]
},
"ConfigurationUpdate" : {
"properties": {
"n": {
"description": "",
"maxLength": 64,
"type": "string"
}
},
"required": ["n"],
"type" : "object"
}
},
"info":{
"version":"20190215",
"title":"serverlite24521",
"termsOfService":"https://openconnectivityfoundation.github.io/core/DISCLAIMER.md",
"title":"serverlite",
"termsOfService":"",
"license":{
"x-copyright":"copyright 2016-2017, 2019 Open Connectivity Foundation, Inc. All rights reserved.",
"url":"https://github.com/openconnectivityfoundation/core/blob/e28a9e0a92e17042ba3e83661e4c0fbce8bdc4ba/LICENSE.md",
"name":"OCF Data Model License"
"x-copyright":"",
"url":"",
"name":""
}
},
"parameters":{
......@@ -1371,7 +1464,6 @@
],
"in":"query",
"name":"units",
"x-queryexample":"/TemperatureResURI?units=C",
"description":"",
"type":"string"
},
......@@ -1384,17 +1476,6 @@
"in":"query",
"name":"if"
},
"interface-update":{
"enum":[
"oic.if.ll",
"oic.if.create",
"oic.if.b",
"oic.if.baseline"
],
"type":"string",
"in":"query",
"name":"if"
},
"interface30":{
"enum":[
"oic.if.r",
......@@ -1425,7 +1506,7 @@
},
"interface-all40":{
"enum":[
"oic.if.ll",
"oic.if.ll",
"oic.if.create",
"oic.if.b",
"oic.if.baseline"
......@@ -1434,15 +1515,6 @@
"in":"query",
"name":"if"
},
"interface-all":{
"enum":[
"oic.if.rw",
"oic.if.baseline"
],
"type":"string",
"in":"query",
"name":"if"
},
"platforminterface-all":{
"enum":[
"oic.if.baseline"
......
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "oc_api.h"
static bool light_state = false;
static int
app_init(void)
{
int ret = oc_init_platform("Intel", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.light", "Kishen's light", "1.0", "1.0",
NULL, NULL);
return ret;
}
static void
get_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)user_data;
PRINT("GET_light:\n");
oc_rep_start_root_object();
switch (iface_mask) {
case OC_IF_BASELINE:
oc_process_baseline_interface(request->resource);
case OC_IF_RW:
oc_rep_set_boolean(root, state, light_state);
break;
default:
break;
}
oc_rep_end_root_object();
oc_send_response(request, OC_STATUS_OK);
PRINT("Light state %d\n", light_state);
}
static void
post_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)iface_mask;
(void)user_data;
PRINT("POST_light:\n");
bool state = false;
oc_rep_t *rep = request->request_payload;
while (rep != NULL) {
PRINT("key: %s ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
state = rep->value.boolean;
PRINT("value: %d\n", state);
break;
default:
oc_send_response(request, OC_STATUS_BAD_REQUEST);
return;
break;
}
rep = rep->next;
}
oc_send_response(request, OC_STATUS_CHANGED);
light_state = state;
}
static void
put_light(oc_request_t *request, oc_interface_mask_t iface_mask,
void *user_data)
{
post_light(request, iface_mask, user_data);
}
static void
register_resources(void)
{
oc_resource_t *res = oc_new_resource("lightbulb", "/light/1", 1, 0);
oc_resource_bind_resource_type(res, "oic.r.light");
oc_resource_bind_resource_interface(res, OC_IF_RW);
oc_resource_set_default_interface(res, OC_IF_RW);
oc_resource_set_discoverable(res, true);
oc_resource_set_periodic_observable(res, 1);
oc_resource_set_request_handler(res, OC_GET, get_light, NULL);
oc_resource_set_request_handler(res, OC_POST, post_light, NULL);
oc_resource_set_request_handler(res, OC_PUT, put_light, NULL);
oc_add_resource(res);
}
#include "contiki.h"
PROCESS(sample_server_process, "OCF server sample");
AUTOSTART_PROCESSES(&sample_server_process);
static void
signal_event_loop(void)
{
process_post(&sample_server_process, PROCESS_EVENT_TIMER, NULL);
}
PROCESS_THREAD(sample_server_process, ev, data)
{
static struct etimer et;
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.register_resources =
register_resources };
static oc_clock_time_t next_event;
PROCESS_BEGIN();
int init = oc_main_init(&handler);
if (init < 0)
return init;
while (ev != PROCESS_EVENT_EXIT) {
next_event = oc_main_poll();
if (next_event != 0) {
next_event -= oc_clock_time();
etimer_set(&et, next_event);
}
PROCESS_YIELD();
}
PROCESS_END();
}
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "oc_api.h"
static bool light_state = false;
static int
app_init(void)
{
int ret = oc_init_platform("Intel", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.light", "Kishen's light", "1.0", "1.0",
NULL, NULL);
return ret;
}
static void
get_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)user_data;
PRINT("GET_light:\n");
oc_rep_start_root_object();
switch (iface_mask) {
case OC_IF_BASELINE:
oc_process_baseline_interface(request->resource);
case OC_IF_RW:
oc_rep_set_boolean(root, state, light_state);
break;
default:
break;
}
oc_rep_end_root_object();
oc_send_response(request, OC_STATUS_OK);
PRINT("Light state %d\n", light_state);
}
static void
post_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)iface_mask;
(void)user_data;
PRINT("POST_light:\n");
bool state = false;
oc_rep_t *rep = request->request_payload;
while (rep != NULL) {
PRINT("key: %s ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
state = rep->value.boolean;
PRINT("value: %d\n", state);
break;
default:
oc_send_response(request, OC_STATUS_BAD_REQUEST);
return;
break;
}
rep = rep->next;
}
oc_send_response(request, OC_STATUS_CHANGED);
light_state = state;
}
static void
put_light(oc_request_t *request, oc_interface_mask_t iface_mask,
void *user_data)
{
post_light(request, iface_mask, user_data);
}
static void
register_resources(void)
{
oc_resource_t *res = oc_new_resource("lightbulb", "/light/1", 1, 0);
oc_resource_bind_resource_type(res, "oic.r.light");
oc_resource_bind_resource_interface(res, OC_IF_RW);
oc_resource_set_default_interface(res, OC_IF_RW);
oc_resource_set_discoverable(res, true);
oc_resource_set_periodic_observable(res, 1);
oc_resource_set_request_handler(res, OC_GET, get_light, NULL);
oc_resource_set_request_handler(res, OC_POST, post_light, NULL);
oc_resource_set_request_handler(res, OC_PUT, put_light, NULL);
oc_add_resource(res);
}
#include "pthread_cond.h"
#include "thread.h"
static int quit;
static mutex_t mutex;
static pthread_cond_t cv;
static struct timespec ts;
static void
signal_event_loop(void)
{
mutex_lock(&mutex);
pthread_cond_signal(&cv);
mutex_unlock(&mutex);
}
static char _oc_main_stack[THREAD_STACKSIZE_MAIN];
void *
oc_main_thread(void *arg)
{
(void)arg;
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.register_resources =
register_resources };
if (oc_main_init(&handler) < 0) {
PRINT("server_riot: failed to initialize stack\n");
return NULL;
}
oc_clock_time_t next_event;
while (!quit) {
next_event = oc_main_poll();
mutex_lock(&mutex);
if (next_event == 0) {
pthread_cond_wait(&cv, &mutex);
} else {
ts.tv_sec = (next_event / OC_CLOCK_SECOND);
ts.tv_nsec = (next_event % OC_CLOCK_SECOND) * 1.e09 / OC_CLOCK_SECOND;
pthread_cond_timedwait(&cv, &mutex, &ts);
}
mutex_unlock(&mutex);
}
oc_main_shutdown();
return NULL;
}
int
main(void)
{
thread_create(_oc_main_stack, sizeof(_oc_main_stack), 2, 0, oc_main_thread,
NULL, "OCF event thread");
fgetc(stdin);
quit = 1;
signal_event_loop();
return 0;
}
......@@ -269,6 +269,8 @@ int oc_ri_get_query_value(const char *query, size_t query_len, const char *key,
oc_interface_mask_t oc_ri_get_interface_mask(char *iface, size_t if_len);
bool oc_ri_is_app_resource_valid(oc_resource_t *resource);
#ifdef __cplusplus
}
#endif
......
......@@ -675,7 +675,7 @@ coap_receive(oc_message_t *msg)
message->token, message->token_len);
}
}
if (response_buffer) {
if (!error_response && response_buffer) {
OC_DBG("got response buffer for uri %s",
oc_string(response_buffer->href));
client_cb = (oc_client_cb_t *)response_buffer->client_cb;
......