You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/11/22 01:17:00 UTC
[01/27] incubator-mynewt-core git commit: oic;
no need for timed_events pseudo-task anymore.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop a0ba34869 -> 7131b026f
oic; no need for timed_events pseudo-task anymore.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7b47dc1e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7b47dc1e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7b47dc1e
Branch: refs/heads/develop
Commit: 7b47dc1e6627201c9b22cb860e82ca60cdd1302c
Parents: 3ff2428
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 15 20:27:15 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:47 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_ri.c | 55 --------------------------------------------
1 file changed, 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7b47dc1e/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 2ae8a61..7d08b82 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -59,13 +59,6 @@ OC_LIST(client_cbs);
OC_MEMB(client_cbs_s, oc_client_cb_t, MAX_NUM_CONCURRENT_REQUESTS);
#endif /* OC_CLIENT */
-OC_LIST(timed_callbacks);
-OC_MEMB(event_callbacks_s, oc_event_callback_t, NUM_OC_CORE_RESOURCES +
- MAX_APP_RESOURCES +
- MAX_NUM_CONCURRENT_REQUESTS);
-
-OC_PROCESS(timed_callback_events, "OC timed callbacks");
-
// TODO: Define and use a complete set of error codes.
int oc_stack_errno;
@@ -200,7 +193,6 @@ start_processes(void)
{
allocate_events();
oc_etimer_init();
- oc_process_start(&timed_callback_events, NULL);
oc_process_start(&coap_engine, NULL);
oc_process_start(&message_buffer_handler, NULL);
@@ -215,7 +207,6 @@ static void
stop_processes(void)
{
oc_etimer_deinit();
- oc_process_exit(&timed_callback_events);
oc_process_exit(&coap_engine);
#ifdef OC_SECURITY
@@ -256,7 +247,6 @@ oc_ri_init(void)
oc_list_init(client_cbs);
#endif
- oc_list_init(timed_callbacks);
start_processes();
oc_create_discovery_resource();
}
@@ -309,39 +299,6 @@ oc_ri_add_resource(oc_resource_t *resource)
}
#endif /* OC_SERVER */
-static void
-poll_event_callback_timers(oc_list_t list, struct oc_memb *cb_pool)
-{
- oc_event_callback_t *event_cb = (oc_event_callback_t *)oc_list_head(list),
- *next;
-
- while (event_cb != NULL) {
- next = event_cb->next;
-
- if (oc_etimer_expired(&event_cb->timer)) {
- if (event_cb->callback(event_cb->data) == DONE) {
- oc_list_remove(list, event_cb);
- oc_memb_free(cb_pool, event_cb);
- } else {
- OC_PROCESS_CONTEXT_BEGIN(&timed_callback_events);
- oc_etimer_restart(&event_cb->timer);
- OC_PROCESS_CONTEXT_END(&timed_callback_events);
- }
- }
-
- event_cb = next;
- }
-}
-
-static void
-check_event_callbacks(void)
-{
-#ifdef OC_SERVER
- poll_event_callback_timers(observe_callbacks, &event_callbacks_s);
-#endif /* OC_SERVER */
- poll_event_callback_timers(timed_callbacks, &event_callbacks_s);
-}
-
#ifdef OC_SERVER
static void
@@ -934,18 +891,6 @@ oc_ri_alloc_client_cb(const char *uri, oc_server_handle_t *server,
}
#endif /* OC_CLIENT */
-OC_PROCESS_THREAD(timed_callback_events, ev, data)
-{
- OC_PROCESS_BEGIN();
- while (1) {
- OC_PROCESS_YIELD();
- if (ev == OC_PROCESS_EVENT_TIMER) {
- check_event_callbacks();
- }
- }
- OC_PROCESS_END();
-}
-
// TODO:
// resource collections
// if method accepted by interface selection
[14/27] incubator-mynewt-core git commit: oic;
use os_events to trigger oc_network_events handling.
Posted by ma...@apache.org.
oic; use os_events to trigger oc_network_events handling.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/9f291c69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9f291c69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9f291c69
Branch: refs/heads/develop
Commit: 9f291c696f3dc3628bf0431379562d414684a809
Parents: 91419fd
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 17 12:46:25 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800
----------------------------------------------------------------------
net/oic/include/oic/oc_network_events.h | 2 --
net/oic/src/api/oc_buffer.c | 1 +
net/oic/src/api/oc_network_events.c | 44 +++++++++++++---------------
net/oic/src/api/oc_ri.c | 2 --
4 files changed, 22 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9f291c69/net/oic/include/oic/oc_network_events.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_network_events.h b/net/oic/include/oic/oc_network_events.h
index d0f5d41..fb557c0 100644
--- a/net/oic/include/oic/oc_network_events.h
+++ b/net/oic/include/oic/oc_network_events.h
@@ -24,8 +24,6 @@
extern "C" {
#endif
-OC_PROCESS_NAME(oc_network_events);
-
typedef struct oc_message_s oc_message_t;
void oc_network_event(oc_message_t *message);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9f291c69/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index 4661529..f5bc70d 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -71,6 +71,7 @@ oc_recv_message(oc_message_t *message)
{
oc_process_post(&message_buffer_handler, oc_events[INBOUND_NETWORK_EVENT],
message);
+ oc_signal_main_loop();
}
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9f291c69/net/oic/src/api/oc_network_events.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_network_events.c b/net/oic/src/api/oc_network_events.c
index 2149bd3..a472d54 100644
--- a/net/oic/src/api/oc_network_events.c
+++ b/net/oic/src/api/oc_network_events.c
@@ -14,44 +14,42 @@
// limitations under the License.
*/
+#include <os/os_eventq.h>
+
#include "oc_network_events.h"
#include "oc_buffer.h"
#include "port/oc_connectivity.h"
#include "port/oc_signal_main_loop.h"
+#include "port/mynewt/adaptor.h"
#include "util/oc_list.h"
OC_LIST(network_events);
+static void oc_network_ev_process(struct os_event *ev);
+static struct os_event oc_network_ev = {
+ .ev_cb = oc_network_ev_process
+};
static void
-oc_process_network_event(void)
+oc_network_ev_process(struct os_event *ev)
{
- oc_network_event_handler_mutex_lock();
- oc_message_t *head = (oc_message_t *)oc_list_pop(network_events);
- while (head != NULL) {
- oc_recv_message(head);
- head = oc_list_pop(network_events);
- }
- oc_network_event_handler_mutex_unlock();
-}
+ struct oc_message_s *head;
-OC_PROCESS(oc_network_events, "");
-OC_PROCESS_THREAD(oc_network_events, ev, data)
-{
- OC_PROCESS_POLLHANDLER(oc_process_network_event());
- OC_PROCESS_BEGIN();
- while (oc_process_is_running(&(oc_network_events))) {
- OC_PROCESS_YIELD();
- }
- OC_PROCESS_END();
+ oc_network_event_handler_mutex_lock();
+ head = (struct oc_message_s *)oc_list_pop(network_events);
+ while (head != NULL) {
+ oc_recv_message(head);
+ head = oc_list_pop(network_events);
+ }
+ oc_network_event_handler_mutex_unlock();
}
void
oc_network_event(oc_message_t *message)
{
- oc_network_event_handler_mutex_lock();
- oc_list_add(network_events, message);
- oc_network_event_handler_mutex_unlock();
+ oc_network_event_handler_mutex_lock();
+ oc_list_add(network_events, message);
+ oc_network_event_handler_mutex_unlock();
- oc_process_poll(&(oc_network_events));
- oc_signal_main_loop();
+ os_eventq_put(oc_evq_get(), &oc_network_ev);
+ oc_signal_main_loop();
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9f291c69/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index c3c2772..09d49f7 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -198,8 +198,6 @@ start_processes(void)
#ifdef OC_SECURITY
oc_process_start(&oc_dtls_handler, NULL);
#endif
-
- oc_process_start(&oc_network_events, NULL);
}
static void
[15/27] incubator-mynewt-core git commit: oic;
remove coap_engine pseudo-process.
Posted by ma...@apache.org.
oic; remove coap_engine pseudo-process.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/91419fda
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/91419fda
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/91419fda
Branch: refs/heads/develop
Commit: 91419fdaa1b49a632e07276f85864b5737cacb70
Parents: 948b380
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 17 10:34:36 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_buffer.c | 8 +++++---
net/oic/src/api/oc_ri.c | 4 +---
net/oic/src/messaging/coap/engine.c | 25 ++++---------------------
net/oic/src/messaging/coap/engine.h | 3 +--
4 files changed, 11 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/91419fda/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index e623221..4661529 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -96,12 +96,14 @@ OC_PROCESS_THREAD(message_buffer_handler, ev, data)
LOG("Inbound network event: encrypted request\n");
oc_process_post(&oc_dtls_handler, oc_events[UDP_TO_DTLS_EVENT], data);
} else {
- LOG("Inbound network event: decrypted request\n");
- oc_process_post(&coap_engine, oc_events[INBOUND_RI_EVENT], data);
+ LOG("Inbound network event: decrypted request\n");
+ coap_receive(data);
+ oc_message_unref(data);
}
#else
LOG("Inbound network event: decrypted request\n");
- oc_process_post(&coap_engine, oc_events[INBOUND_RI_EVENT], data);
+ coap_receive(data);
+ oc_message_unref(data);
#endif
} else if (ev == oc_events[OUTBOUND_NETWORK_EVENT]) {
oc_message_t *message = (oc_message_t *)data;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/91419fda/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 32d9a62..c3c2772 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -192,7 +192,7 @@ static void
start_processes(void)
{
allocate_events();
- oc_process_start(&coap_engine, NULL);
+ coap_engine_init();
oc_process_start(&message_buffer_handler, NULL);
#ifdef OC_SECURITY
@@ -205,8 +205,6 @@ start_processes(void)
static void
stop_processes(void)
{
- oc_process_exit(&coap_engine);
-
#ifdef OC_SECURITY
oc_process_exit(&oc_dtls_handler);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/91419fda/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index 9d8efaa..3fa4d21 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -45,8 +45,6 @@
#include "oc_client_state.h"
#endif
-OC_PROCESS(coap_engine, "CoAP Engine");
-
extern bool oc_ri_invoke_coap_entity_handler(void *request, void *response,
uint8_t *buffer,
uint16_t buffer_size,
@@ -301,24 +299,9 @@ coap_receive(oc_message_t *msg)
/* if(new data) */
return erbium_status_code;
}
-/*---------------------------------------------------------------------------*/
-OC_PROCESS_THREAD(coap_engine, ev, data)
-{
- OC_PROCESS_BEGIN();
-
- coap_init_connection();
-
- while (1) {
- OC_PROCESS_YIELD();
-
- if (ev == oc_events[INBOUND_RI_EVENT]) {
- coap_receive(data);
- oc_message_unref(data);
- }
- }
-
- OC_PROCESS_END();
+void
+coap_engine_init(void)
+{
+ coap_init_connection();
}
-
-/*---------------------------------------------------------------------------*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/91419fda/net/oic/src/messaging/coap/engine.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.h b/net/oic/src/messaging/coap/engine.h
index 067c1d7..a30793f 100644
--- a/net/oic/src/messaging/coap/engine.h
+++ b/net/oic/src/messaging/coap/engine.h
@@ -43,8 +43,7 @@
extern "C" {
#endif
-OC_PROCESS_NAME(coap_engine);
-
+void coap_engine_init(void);
int coap_receive(oc_message_t *message);
#ifdef __cplusplus
[09/27] incubator-mynewt-core git commit: ocf_sample, oicmgr;
no need to poll oci with calls to oc_main_loop().
Posted by ma...@apache.org.
ocf_sample, oicmgr; no need to poll oci with calls to oc_main_loop().
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7f841e0d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7f841e0d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7f841e0d
Branch: refs/heads/develop
Commit: 7f841e0d0efb1442df64b356e1dba52bcded6e46
Parents: f5f9ef5
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 17 18:07:16 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800
----------------------------------------------------------------------
apps/ocf_sample/src/main.c | 40 +++++-----------------------------------
mgmt/oicmgr/src/oicmgr.c | 17 -----------------
2 files changed, 5 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7f841e0d/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index e423863..096b444 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -39,13 +39,7 @@
#define OCF_MAIN_TASK_STACK_SIZE (OS_STACK_ALIGN(512))
static os_stack_t ocf_stack[OCF_MAIN_TASK_STACK_SIZE];
struct os_task ocf_main_task;
-
-/** Auxilliary task for handling events from library packages. */
-#define OCF_AUX_TASK_PRIO (9)
-#define OCF_AUX_TASK_STACK_SIZE (OS_STACK_ALIGN(336))
-struct os_eventq ocf_aux_evq;
-static os_stack_t ocf_aux_stack[OCF_AUX_TASK_STACK_SIZE];
-struct os_task ocf_aux_task;
+struct os_eventq ocf_main_evq;
#if (MYNEWT_VAL(OC_CLIENT) == 1)
static void issue_requests(void);
@@ -230,38 +224,19 @@ oc_handler_t ocf_handler = {
#endif
};
-struct os_sem ocf_main_loop_sem;
-
-void
-oc_signal_main_loop(void)
-{
- os_sem_release(&ocf_main_loop_sem);
-}
-
static void
ocf_main_task_handler(void *arg)
{
- os_sem_init(&ocf_main_loop_sem, 1);
-
#if (MYNEWT_VAL(OC_CLIENT) == 1)
- os_callout_init(&callout, &ocf_aux_evq, stop_observe, NULL);
+ os_callout_init(&callout, &ocf_main_evq, stop_observe, NULL);
#endif
while (1) {
- oc_main_poll();
- os_sem_pend(&ocf_main_loop_sem, OS_TIMEOUT_NEVER);
+ os_eventq_run(&ocf_main_evq);
}
oc_main_shutdown();
}
static void
-ocf_aux_task_handler(void *arg)
-{
- while (1) {
- os_eventq_run(&ocf_aux_evq);
- }
-}
-
-static void
ocf_init_tasks(void)
{
int rc;
@@ -272,17 +247,12 @@ ocf_init_tasks(void)
assert(rc == 0);
/* Initialize eventq */
- os_eventq_init(&ocf_aux_evq);
+ os_eventq_init(&ocf_main_evq);
/* Set the default eventq for packages that lack a dedicated task. */
- os_eventq_dflt_set(&ocf_aux_evq);
+ os_eventq_dflt_set(&ocf_main_evq);
oc_main_init(&ocf_handler);
-
- rc = os_task_init(&ocf_aux_task, "ocf_aux", ocf_aux_task_handler, NULL,
- OCF_AUX_TASK_PRIO, OS_WAIT_FOREVER, ocf_aux_stack,
- OCF_AUX_TASK_STACK_SIZE);
- assert(rc == 0);
}
int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7f841e0d/mgmt/oicmgr/src/oicmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/oicmgr/src/oicmgr.c b/mgmt/oicmgr/src/oicmgr.c
index 4557189..e084caf 100644
--- a/mgmt/oicmgr/src/oicmgr.c
+++ b/mgmt/oicmgr/src/oicmgr.c
@@ -48,7 +48,6 @@ struct omgr_state {
};
static void omgr_event_start(struct os_event *ev);
-static void omgr_process_oc_event(struct os_event *ev);
static struct omgr_state omgr_state = {
.os_event.ev_cb = omgr_event_start,
@@ -219,21 +218,6 @@ static const oc_handler_t omgr_oc_handler = {
.register_resources = omgr_register_resources
};
-void
-oc_signal_main_loop(void)
-{
- struct omgr_state *o = &omgr_state;
-
- assert(o->os_evq); /* Must call mgmt_evq_set() first. */
- os_eventq_put(o->os_evq, &o->os_event);
-}
-
-static void
-omgr_process_oc_event(struct os_event *ev)
-{
- oc_main_poll();
-}
-
static void
omgr_event_start(struct os_event *ev)
{
@@ -241,7 +225,6 @@ omgr_event_start(struct os_event *ev)
oc_main_init((oc_handler_t *)&omgr_oc_handler);
os_eventq_ensure(&o->os_evq, NULL);
- o->os_event.ev_cb = omgr_process_oc_event;
}
int
[19/27] incubator-mynewt-core git commit: oic;
remove oc_process.h/oc_events.h
Posted by ma...@apache.org.
oic; remove oc_process.h/oc_events.h
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3fa41bf8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3fa41bf8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3fa41bf8
Branch: refs/heads/develop
Commit: 3fa41bf85e4ce8e3c17b4c2d56340434b16b5c83
Parents: 7f841e0
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 17 19:50:00 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
net/oic/include/oic/oc_buffer.h | 16 +-
net/oic/include/oic/oc_network_events.h | 3 -
net/oic/src/api/oc_buffer.c | 2 +-
net/oic/src/api/oc_events.h | 42 --
net/oic/src/api/oc_main.c | 6 +-
net/oic/src/api/oc_network_events.c | 1 +
net/oic/src/api/oc_ri.c | 12 -
net/oic/src/messaging/coap/engine.c | 1 -
net/oic/src/port/mynewt/ble_adaptor.c | 1 +
net/oic/src/port/mynewt/serial_adaptor.c | 1 +
net/oic/src/port/oc_connectivity.h | 1 -
net/oic/src/util/oc_process.c | 346 -----------------
net/oic/src/util/oc_process.h | 535 --------------------------
net/oic/src/util/pt/lc-addrlabels.h | 94 -----
net/oic/src/util/pt/lc-switch.h | 87 -----
net/oic/src/util/pt/lc.h | 138 -------
net/oic/src/util/pt/pt-sem.h | 241 ------------
net/oic/src/util/pt/pt.h | 341 ----------------
18 files changed, 12 insertions(+), 1856 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/include/oic/oc_buffer.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_buffer.h b/net/oic/include/oic/oc_buffer.h
index 0bbf8a7..852e427 100644
--- a/net/oic/include/oic/oc_buffer.h
+++ b/net/oic/include/oic/oc_buffer.h
@@ -17,21 +17,17 @@
#ifndef OC_BUFFER_H
#define OC_BUFFER_H
-#include "../../src/port/oc_connectivity.h"
-#include "../../src/util/oc_process.h"
-#include <stdbool.h>
-
#ifdef __cplusplus
extern "C" {
#endif
-OC_PROCESS_NAME(message_buffer_handler);
-oc_message_t *oc_allocate_message(void);
-void oc_message_add_ref(oc_message_t *message);
-void oc_message_unref(oc_message_t *message);
+struct oc_message_s;
+struct oc_message_s *oc_allocate_message(void);
+void oc_message_add_ref(struct oc_message_s *message);
+void oc_message_unref(struct oc_message_s *message);
-void oc_recv_message(oc_message_t *message);
-void oc_send_message(oc_message_t *message);
+void oc_recv_message(struct oc_message_s *message);
+void oc_send_message(struct oc_message_s *message);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/include/oic/oc_network_events.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_network_events.h b/net/oic/include/oic/oc_network_events.h
index fb557c0..61a274c 100644
--- a/net/oic/include/oic/oc_network_events.h
+++ b/net/oic/include/oic/oc_network_events.h
@@ -17,9 +17,6 @@
#ifndef OC_NETWORK_EVENTS_H
#define OC_NETWORK_EVENTS_H
-#include "../../src/port/oc_network_events_mutex.h"
-#include "../../src/util/oc_process.h"
-
#ifdef __cplusplus
extern "C" {
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index e800e08..88c7731 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -27,7 +27,6 @@
#include "config.h"
#include "oc_buffer.h"
-#include "oc_events.h"
#include "port/mynewt/adaptor.h"
@@ -118,6 +117,7 @@ oc_buffer_tx(struct oc_message_s *message)
} else {
#endif
#ifdef OC_SECURITY
+ /* XXX convert this */
if (message->endpoint.flags & SECURED) {
LOG("Outbound network event: forwarding to DTLS\n");
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/api/oc_events.h
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_events.h b/net/oic/src/api/oc_events.h
deleted file mode 100644
index 19de52c..0000000
--- a/net/oic/src/api/oc_events.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- // 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.
- */
-
-#ifndef OC_EVENTS_H
-#define OC_EVENTS_H
-
-#include "util/oc_process.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- INBOUND_NETWORK_EVENT,
- UDP_TO_DTLS_EVENT,
- INIT_DTLS_CONN_EVENT,
- RI_TO_DTLS_EVENT,
- INBOUND_RI_EVENT,
- OUTBOUND_NETWORK_EVENT,
- __NUM_OC_EVENT_TYPES__
-} oc_events_t;
-
-oc_process_event_t oc_events[__NUM_OC_EVENT_TYPES__];
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OC_EVENTS_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/api/oc_main.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_main.c b/net/oic/src/api/oc_main.c
index 8a19243..acf0219 100644
--- a/net/oic/src/api/oc_main.c
+++ b/net/oic/src/api/oc_main.c
@@ -20,8 +20,8 @@
#include "port/oc_assert.h"
#include "port/oc_clock.h"
#include "port/oc_connectivity.h"
-
-#include "util/oc_process.h"
+#include "port/oc_connectivity.h"
+#include "port/oc_network_events_mutex.h"
#include "oc_api.h"
@@ -92,8 +92,6 @@ err:
oc_clock_time_t
oc_main_poll(void)
{
- while (oc_process_run());
-
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/api/oc_network_events.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_network_events.c b/net/oic/src/api/oc_network_events.c
index 4ff00d2..fd5ba38 100644
--- a/net/oic/src/api/oc_network_events.c
+++ b/net/oic/src/api/oc_network_events.c
@@ -20,6 +20,7 @@
#include "oc_buffer.h"
#include "port/oc_connectivity.h"
#include "port/oc_signal_main_loop.h"
+#include "port/oc_network_events_mutex.h"
#include "port/mynewt/adaptor.h"
#include "util/oc_list.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 7903682..bcb605a 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -22,7 +22,6 @@
#include "util/oc_list.h"
#include "util/oc_memb.h"
-#include "util/oc_process.h"
#include "messaging/coap/constants.h"
#include "messaging/coap/engine.h"
@@ -35,7 +34,6 @@
#include "oc_buffer.h"
#include "oc_core_res.h"
#include "oc_discovery.h"
-#include "oc_events.h"
#include "oc_network_events.h"
#include "oc_ri.h"
#include "oc_uuid.h"
@@ -180,18 +178,8 @@ oc_ri_get_query_value(const char *query, int query_len, const char *key,
}
static void
-allocate_events(void)
-{
- int i = 0;
- for (i = 0; i < __NUM_OC_EVENT_TYPES__; i++) {
- oc_events[i] = oc_process_alloc_event();
- }
-}
-
-static void
start_processes(void)
{
- allocate_events();
coap_engine_init();
#ifdef OC_SECURITY
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index 3fa4d21..fc7477c 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -37,7 +37,6 @@
#include <string.h>
/* OIC Stack headers */
-#include "api/oc_events.h"
#include "oc_buffer.h"
#include "oc_ri.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index 6963249..18ff7ad 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -23,6 +23,7 @@
#include <os/os.h>
#include <string.h>
#include "oc_buffer.h"
+#include "port/oc_connectivity.h"
#include "../oc_log.h"
#include "adaptor.h"
#include "host/ble_hs.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
index e1d20c0..ef8f4b0 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -24,6 +24,7 @@
#include <os/os.h>
#include <shell/shell.h>
#include "oc_buffer.h"
+#include "port/oc_connectivity.h"
#include "../oc_log.h"
#include "adaptor.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index a292f16..1380442 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -20,7 +20,6 @@
#include "mynewt/config.h"
#include "oic/oc_network_events.h"
#include "oc_log.h"
-#include "../util/oc_process.h"
#include <stdint.h>
#ifdef __cplusplus
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/util/oc_process.c
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_process.c b/net/oic/src/util/oc_process.c
deleted file mode 100644
index 47c3282..0000000
--- a/net/oic/src/util/oc_process.c
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * Copyright (c) 2016 Intel Corporation
- *
- * Copyright (c) 2005, Swedish Institute of Computer Science
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- */
-
-#include "oc_process.h"
-#include "oc_buffer.h"
-#include <stdio.h>
-
-/*
- * Pointer to the currently running process structure.
- */
-struct oc_process *oc_process_list = NULL;
-struct oc_process *oc_process_current = NULL;
-
-static oc_process_event_t lastevent;
-
-/*
- * Structure used for keeping the queue of active events.
- */
-struct event_data
-{
- oc_process_event_t ev;
- oc_process_data_t data;
- struct oc_process *p;
-};
-
-static oc_process_num_events_t nevents, fevent;
-static struct event_data events[OC_PROCESS_CONF_NUMEVENTS];
-
-#if OC_PROCESS_CONF_STATS
-oc_process_num_events_t process_maxevents;
-#endif
-
-static volatile unsigned char poll_requested;
-
-#define OC_PROCESS_STATE_NONE 0
-#define OC_PROCESS_STATE_RUNNING 1
-#define OC_PROCESS_STATE_CALLED 2
-
-static void call_process(struct oc_process *p, oc_process_event_t ev,
- oc_process_data_t data);
-
-/*---------------------------------------------------------------------------*/
-oc_process_event_t
-oc_process_alloc_event(void)
-{
- return lastevent++;
-}
-/*---------------------------------------------------------------------------*/
-void
-oc_process_start(struct oc_process *p, oc_process_data_t data)
-{
- struct oc_process *q;
-
- /* First make sure that we don't try to start a process that is
- already running. */
- for (q = oc_process_list; q != p && q != NULL; q = q->next)
- ;
-
- /* If we found the process on the process list, we bail out. */
- if (q == p) {
- return;
- }
- /* Put on the procs list.*/
- p->next = oc_process_list;
- oc_process_list = p;
- p->state = OC_PROCESS_STATE_RUNNING;
- PT_INIT(&p->pt);
-
- /* Post a synchronous initialization event to the process. */
- oc_process_post_synch(p, OC_PROCESS_EVENT_INIT, data);
-}
-/*---------------------------------------------------------------------------*/
-static void
-exit_process(struct oc_process *p, struct oc_process *fromprocess)
-{
- register struct oc_process *q;
- struct oc_process *old_current = oc_process_current;
-
- /* Make sure the process is in the process list before we try to
- exit it. */
- for (q = oc_process_list; q != p && q != NULL; q = q->next)
- ;
- if (q == NULL) {
- return;
- }
-
- if (oc_process_is_running(p)) {
- /* Process was running */
- p->state = OC_PROCESS_STATE_NONE;
-
- /*
- * Post a synchronous event to all processes to inform them that
- * this process is about to exit. This will allow services to
- * deallocate state associated with this process.
- */
- for (q = oc_process_list; q != NULL; q = q->next) {
- if (p != q) {
- call_process(q, OC_PROCESS_EVENT_EXITED, (oc_process_data_t)p);
- }
- }
-
- if (p->thread != NULL && p != fromprocess) {
- /* Post the exit event to the process that is about to exit. */
- oc_process_current = p;
- p->thread(&p->pt, OC_PROCESS_EVENT_EXIT, NULL);
- }
- }
-
- if (p == oc_process_list) {
- oc_process_list = oc_process_list->next;
- } else {
- for (q = oc_process_list; q != NULL; q = q->next) {
- if (q->next == p) {
- q->next = p->next;
- break;
- }
- }
- }
-
- oc_process_current = old_current;
-}
-/*---------------------------------------------------------------------------*/
-static void
-call_process(struct oc_process *p, oc_process_event_t ev,
- oc_process_data_t data)
-{
- int ret;
-
- if ((p->state & OC_PROCESS_STATE_RUNNING) && p->thread != NULL) {
- oc_process_current = p;
- p->state = OC_PROCESS_STATE_CALLED;
- ret = p->thread(&p->pt, ev, data);
- if (ret == PT_EXITED || ret == PT_ENDED || ev == OC_PROCESS_EVENT_EXIT) {
- exit_process(p, p);
- } else {
- p->state = OC_PROCESS_STATE_RUNNING;
- }
- }
-}
-/*---------------------------------------------------------------------------*/
-void
-oc_process_exit(struct oc_process *p)
-{
- exit_process(p, OC_PROCESS_CURRENT());
-}
-/*---------------------------------------------------------------------------*/
-void
-oc_process_init(void)
-{
- lastevent = OC_PROCESS_EVENT_MAX;
-
- nevents = fevent = 0;
-#if OC_PROCESS_CONF_STATS
- process_maxevents = 0;
-#endif /* OC_PROCESS_CONF_STATS */
-
- oc_process_current = oc_process_list = NULL;
-}
-/*---------------------------------------------------------------------------*/
-/*
- * Call each process' poll handler.
- */
-/*---------------------------------------------------------------------------*/
-static void
-do_poll(void)
-{
- struct oc_process *p;
-
- poll_requested = 0;
- /* Call the processes that needs to be polled. */
- for (p = oc_process_list; p != NULL; p = p->next) {
- if (p->needspoll) {
- p->state = OC_PROCESS_STATE_RUNNING;
- p->needspoll = 0;
- call_process(p, OC_PROCESS_EVENT_POLL, NULL);
- }
- }
-}
-/*---------------------------------------------------------------------------*/
-/*
- * Process the next event in the event queue and deliver it to
- * listening processes.
- */
-/*---------------------------------------------------------------------------*/
-static void
-do_event(void)
-{
- static oc_process_event_t ev;
- static oc_process_data_t data;
- static struct oc_process *receiver;
- static struct oc_process *p;
-
- /*
- * If there are any events in the queue, take the first one and walk
- * through the list of processes to see if the event should be
- * delivered to any of them. If so, we call the event handler
- * function for the process. We only process one event at a time and
- * call the poll handlers inbetween.
- */
-
- if (nevents > 0) {
-
- /* There are events that we should deliver. */
- ev = events[fevent].ev;
-
- data = events[fevent].data;
- receiver = events[fevent].p;
-
- /* Since we have seen the new event, we move pointer upwards
- and decrease the number of events. */
- fevent = (fevent + 1) % OC_PROCESS_CONF_NUMEVENTS;
- --nevents;
-
- /* If this is a broadcast event, we deliver it to all events, in
- order of their priority. */
- if (receiver == OC_PROCESS_BROADCAST) {
- for (p = oc_process_list; p != NULL; p = p->next) {
-
- /* If we have been requested to poll a process, we do this in
- between processing the broadcast event. */
- if (poll_requested) {
- do_poll();
- }
- call_process(p, ev, data);
- }
- } else {
- /* This is not a broadcast event, so we deliver it to the
- specified process. */
- /* If the event was an INIT event, we should also update the
- state of the process. */
- if (ev == OC_PROCESS_EVENT_INIT) {
- receiver->state = OC_PROCESS_STATE_RUNNING;
- }
-
- /* Make sure that the process actually is running. */
- call_process(receiver, ev, data);
- }
- }
-}
-/*---------------------------------------------------------------------------*/
-int
-oc_process_run(void)
-{
- /* Process poll events. */
- if (poll_requested) {
- do_poll();
- }
-
- /* Process one event from the queue */
- do_event();
-
- return nevents + poll_requested;
-}
-/*---------------------------------------------------------------------------*/
-int
-oc_process_nevents(void)
-{
- return nevents + poll_requested;
-}
-/*---------------------------------------------------------------------------*/
-int
-oc_process_post(struct oc_process *p, oc_process_event_t ev,
- oc_process_data_t data)
-{
- static oc_process_num_events_t snum;
-
- if (nevents == OC_PROCESS_CONF_NUMEVENTS) {
- oc_message_unref(data);
- return OC_PROCESS_ERR_FULL;
- }
-
- snum =
- (oc_process_num_events_t)(fevent + nevents) % OC_PROCESS_CONF_NUMEVENTS;
- events[snum].ev = ev;
- events[snum].data = data;
- events[snum].p = p;
- ++nevents;
-
-#if OC_PROCESS_CONF_STATS
- if (nevents > process_maxevents) {
- process_maxevents = nevents;
- }
-#endif /* OC_PROCESS_CONF_STATS */
-
- return OC_PROCESS_ERR_OK;
-}
-/*---------------------------------------------------------------------------*/
-void
-oc_process_post_synch(struct oc_process *p, oc_process_event_t ev,
- oc_process_data_t data)
-{
- struct oc_process *caller = oc_process_current;
-
- call_process(p, ev, data);
- oc_process_current = caller;
-}
-/*---------------------------------------------------------------------------*/
-void
-oc_process_poll(struct oc_process *p)
-{
- if (p != NULL) {
- if (p->state == OC_PROCESS_STATE_RUNNING ||
- p->state == OC_PROCESS_STATE_CALLED) {
- p->needspoll = 1;
- poll_requested = 1;
- }
- }
-}
-/*---------------------------------------------------------------------------*/
-int
-oc_process_is_running(struct oc_process *p)
-{
- return p->state != OC_PROCESS_STATE_NONE;
-}
-/*---------------------------------------------------------------------------*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/util/oc_process.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_process.h b/net/oic/src/util/oc_process.h
deleted file mode 100644
index b81e217..0000000
--- a/net/oic/src/util/oc_process.h
+++ /dev/null
@@ -1,535 +0,0 @@
-/*
- * Copyright (c) 2016 Intel Corporation
- *
- * Copyright (c) 2005, Swedish Institute of Computer Science
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- */
-
-/**
- * \defgroup process Contiki processes
- *
- * A process in Contiki consists of a single \ref pt "protothread".
- *
- * @{
- */
-
-#ifndef OC_PROCESS_H
-#define OC_PROCESS_H
-#include "pt/pt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef NULL
-#define NULL 0
-#endif /* NULL */
-
-typedef unsigned char oc_process_event_t;
-typedef void *oc_process_data_t;
-typedef unsigned char oc_process_num_events_t;
-
-/**
- * \name Return values
- * @{
- */
-
-/**
- * \brief Return value indicating that an operation was successful.
- *
- * This value is returned to indicate that an operation
- * was successful.
- */
-#define OC_PROCESS_ERR_OK 0
-/**
- * \brief Return value indicating that the event queue was full.
- *
- * This value is returned from process_post() to indicate
- * that the event queue was full and that an event could
- * not be posted.
- */
-#define OC_PROCESS_ERR_FULL 1
-/* @} */
-
-#define OC_PROCESS_NONE NULL
-
-#ifndef OC_PROCESS_CONF_NUMEVENTS
-#define OC_PROCESS_CONF_NUMEVENTS 10
-#endif /* OC_PROCESS_CONF_NUMEVENTS */
-
-#define OC_PROCESS_EVENT_NONE 0x80
-#define OC_PROCESS_EVENT_INIT 0x81
-#define OC_PROCESS_EVENT_POLL 0x82
-#define OC_PROCESS_EVENT_EXIT 0x83
-#define OC_PROCESS_EVENT_SERVICE_REMOVED 0x84
-#define OC_PROCESS_EVENT_CONTINUE 0x85
-#define OC_PROCESS_EVENT_MSG 0x86
-#define OC_PROCESS_EVENT_EXITED 0x87
-#define OC_PROCESS_EVENT_TIMER 0x88
-#define OC_PROCESS_EVENT_COM 0x89
-#define OC_PROCESS_EVENT_MAX 0x8a
-
-#define OC_PROCESS_BROADCAST NULL
-#define OC_PROCESS_ZOMBIE ((struct oc_process *)0x1)
-
-/**
- * \name Process protothread functions
- * @{
- */
-
-/**
- * Define the beginning of a process.
- *
- * This macro defines the beginning of a process, and must always
- * appear in a OC_PROCESS_THREAD() definition. The OC_PROCESS_END() macro
- * must come at the end of the process.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_BEGIN() PT_BEGIN(process_pt)
-
-/**
- * Define the end of a process.
- *
- * This macro defines the end of a process. It must appear in a
- * OC_PROCESS_THREAD() definition and must always be included. The
- * process exits when the OC_PROCESS_END() macro is reached.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_END() PT_END(process_pt)
-
-/**
- * Wait for an event to be posted to the process.
- *
- * This macro blocks the currently running process until the process
- * receives an event.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_WAIT_EVENT() OC_PROCESS_YIELD()
-
-/**
- * Wait for an event to be posted to the process, with an extra
- * condition.
- *
- * This macro is similar to OC_PROCESS_WAIT_EVENT() in that it blocks the
- * currently running process until the process receives an event. But
- * OC_PROCESS_WAIT_EVENT_UNTIL() takes an extra condition which must be
- * true for the process to continue.
- *
- * \param c The condition that must be true for the process to continue.
- * \sa PT_WAIT_UNTIL()
- *
- * \hideinitializer
- */
-#define OC_PROCESS_WAIT_EVENT_UNTIL(c) OC_PROCESS_YIELD_UNTIL(c)
-
-/**
- * Yield the currently running process.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_YIELD() PT_YIELD(process_pt)
-
-/**
- * Yield the currently running process until a condition occurs.
- *
- * This macro is different from OC_PROCESS_WAIT_UNTIL() in that
- * OC_PROCESS_YIELD_UNTIL() is guaranteed to always yield at least
- * once. This ensures that the process does not end up in an infinite
- * loop and monopolizing the CPU.
- *
- * \param c The condition to wait for.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_YIELD_UNTIL(c) PT_YIELD_UNTIL(process_pt, c)
-
-/**
- * Wait for a condition to occur.
- *
- * This macro does not guarantee that the process yields, and should
- * therefore be used with care. In most cases, OC_PROCESS_WAIT_EVENT(),
- * OC_PROCESS_WAIT_EVENT_UNTIL(), OC_PROCESS_YIELD() or
- * OC_PROCESS_YIELD_UNTIL() should be used instead.
- *
- * \param c The condition to wait for.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_WAIT_UNTIL(c) PT_WAIT_UNTIL(process_pt, c)
-#define OC_PROCESS_WAIT_WHILE(c) PT_WAIT_WHILE(process_pt, c)
-
-/**
- * Exit the currently running process.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_EXIT() PT_EXIT(process_pt)
-
-/**
- * Spawn a protothread from the process.
- *
- * \param pt The protothread state (struct pt) for the new protothread
- * \param thread The call to the protothread function.
- * \sa PT_SPAWN()
- *
- * \hideinitializer
- */
-#define OC_PROCESS_PT_SPAWN(pt, thread) PT_SPAWN(process_pt, pt, thread)
-
-/**
- * Yield the process for a short while.
- *
- * This macro yields the currently running process for a short while,
- * thus letting other processes run before the process continues.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_PAUSE() \
- do { \
- process_post(OC_PROCESS_CURRENT(), OC_PROCESS_EVENT_CONTINUE, NULL); \
- OC_PROCESS_WAIT_EVENT_UNTIL(ev == OC_PROCESS_EVENT_CONTINUE); \
- } while (0)
-
-/** @} end of protothread functions */
-
-/**
- * \name Poll and exit handlers
- * @{
- */
-/**
- * Specify an action when a process is polled.
- *
- * \note This declaration must come immediately before the
- * OC_PROCESS_BEGIN() macro.
- *
- * \param handler The action to be performed.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_POLLHANDLER(handler) \
- if (ev == OC_PROCESS_EVENT_POLL) { \
- handler; \
- }
-
-/**
- * Specify an action when a process exits.
- *
- * \note This declaration must come immediately before the
- * OC_PROCESS_BEGIN() macro.
- *
- * \param handler The action to be performed.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_EXITHANDLER(handler) \
- if (ev == OC_PROCESS_EVENT_EXIT) { \
- handler; \
- }
-
-/** @} */
-
-/**
- * \name Process declaration and definition
- * @{
- */
-
-/**
- * Define the body of a process.
- *
- * This macro is used to define the body (protothread) of a
- * process. The process is called whenever an event occurs in the
- * system, A process always start with the OC_PROCESS_BEGIN() macro and
- * end with the OC_PROCESS_END() macro.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_THREAD(name, ev, data) \
- static PT_THREAD(process_thread_##name( \
- struct pt *process_pt, oc_process_event_t ev, oc_process_data_t data))
-
-/**
- * Declare the name of a process.
- *
- * This macro is typically used in header files to declare the name of
- * a process that is implemented in the C file.
- *
- * \hideinitializer
- */
-#define OC_PROCESS_NAME(name) extern struct oc_process name
-
-/**
- * Declare a process.
- *
- * This macro declares a process. The process has two names: the
- * variable of the process structure, which is used by the C program,
- * and a human readable string name, which is used when debugging.
- * A configuration option allows removal of the readable name to save RAM.
- *
- * \param name The variable name of the process structure.
- * \param strname The string representation of the process' name.
- *
- * \hideinitializer
- */
-#if OC_PROCESS_CONF_NO_OC_PROCESS_NAMES
-#define OC_PROCESS(name, strname) \
- OC_PROCESS_THREAD(name, ev, data); \
- struct oc_process name = { NULL, process_thread_##name }
-#else
-#define OC_PROCESS(name, strname) \
- OC_PROCESS_THREAD(name, ev, data); \
- struct oc_process name = { NULL, strname, process_thread_##name }
-#endif
-
-/** @} */
-
-struct oc_process
-{
- struct oc_process *next;
-#if OC_PROCESS_CONF_NO_OC_PROCESS_NAMES
-#define OC_PROCESS_NAME_STRING(process) ""
-#else
- const char *name;
-#define OC_PROCESS_NAME_STRING(process) (process)->name
-#endif
- PT_THREAD((*thread)(struct pt *, oc_process_event_t, oc_process_data_t));
- struct pt pt;
- unsigned char state, needspoll;
-};
-
-/**
- * \name Functions called from application programs
- * @{
- */
-
-/**
- * Start a process.
- *
- * \param p A pointer to a process structure.
- *
- * \param data An argument pointer that can be passed to the new
- * process
- *
- */
-void oc_process_start(struct oc_process *p, oc_process_data_t data);
-
-/**
- * Post an asynchronous event.
- *
- * This function posts an asynchronous event to one or more
- * processes. The handing of the event is deferred until the target
- * process is scheduled by the kernel. An event can be broadcast to
- * all processes, in which case all processes in the system will be
- * scheduled to handle the event.
- *
- * \param ev The event to be posted.
- *
- * \param data The auxiliary data to be sent with the event
- *
- * \param p The process to which the event should be posted, or
- * OC_PROCESS_BROADCAST if the event should be posted to all processes.
- *
- * \retval OC_PROCESS_ERR_OK The event could be posted.
- *
- * \retval OC_PROCESS_ERR_FULL The event queue was full and the event could
- * not be posted.
- */
-int oc_process_post(struct oc_process *p, oc_process_event_t ev,
- oc_process_data_t data);
-
-/**
- * Post a synchronous event to a process.
- *
- * \param p A pointer to the process' process structure.
- *
- * \param ev The event to be posted.
- *
- * \param data A pointer to additional data that is posted together
- * with the event.
- */
-void oc_process_post_synch(struct oc_process *p, oc_process_event_t ev,
- oc_process_data_t data);
-
-/**
- * \brief Cause a process to exit
- * \param p The process that is to be exited
- *
- * This function causes a process to exit. The process can
- * either be the currently executing process, or another
- * process that is currently running.
- *
- * \sa OC_PROCESS_CURRENT()
- */
-void oc_process_exit(struct oc_process *p);
-
-/**
- * Get a pointer to the currently running process.
- *
- * This macro get a pointer to the currently running
- * process. Typically, this macro is used to post an event to the
- * current process with process_post().
- *
- * \hideinitializer
- */
-#define OC_PROCESS_CURRENT() oc_process_current
-extern struct oc_process *oc_process_current;
-
-/**
- * Switch context to another process
- *
- * This function switch context to the specified process and executes
- * the code as if run by that process. Typical use of this function is
- * to switch context in services, called by other processes. Each
- * OC_PROCESS_CONTEXT_BEGIN() must be followed by the
- * OC_PROCESS_CONTEXT_END() macro to end the context switch.
- *
- * Example:
- \code
- OC_PROCESS_CONTEXT_BEGIN(&test_process);
- etimer_set(&timer, CLOCK_SECOND);
- OC_PROCESS_CONTEXT_END(&test_process);
- \endcode
- *
- * \param p The process to use as context
- *
- * \sa OC_PROCESS_CONTEXT_END()
- * \sa OC_PROCESS_CURRENT()
- */
-#define OC_PROCESS_CONTEXT_BEGIN(p) \
- { \
- struct oc_process *tmp_current = OC_PROCESS_CURRENT(); \
- oc_process_current = p
-
-/**
- * End a context switch
- *
- * This function ends a context switch and changes back to the
- * previous process.
- *
- * \param p The process used in the context switch
- *
- * \sa OC_PROCESS_CONTEXT_START()
- */
-#define OC_PROCESS_CONTEXT_END(p) \
- oc_process_current = tmp_current; \
- }
-
-/**
- * \brief Allocate a global event number.
- * \return The allocated event number
- *
- * In Contiki, event numbers above 128 are global and may
- * be posted from one process to another. This function
- * allocates one such event number.
- *
- * \note There currently is no way to deallocate an allocated event
- * number.
- */
-oc_process_event_t oc_process_alloc_event(void);
-
-/** @} */
-
-/**
- * \name Functions called from device drivers
- * @{
- */
-
-/**
- * Request a process to be polled.
- *
- * This function typically is called from an interrupt handler to
- * cause a process to be polled.
- *
- * \param p A pointer to the process' process structure.
- */
-void oc_process_poll(struct oc_process *p);
-
-/** @} */
-
-/**
- * \name Functions called by the system and boot-up code
- * @{
- */
-
-/**
- * \brief Initialize the process module.
- *
- * This function initializes the process module and should
- * be called by the system boot-up code.
- */
-void oc_process_init(void);
-
-/**
- * Run the system once - call poll handlers and process one event.
- *
- * This function should be called repeatedly from the main() program
- * to actually run the Contiki system. It calls the necessary poll
- * handlers, and processes one event. The function returns the number
- * of events that are waiting in the event queue so that the caller
- * may choose to put the CPU to sleep when there are no pending
- * events.
- *
- * \return The number of events that are currently waiting in the
- * event queue.
- */
-int oc_process_run(void);
-
-/**
- * Check if a process is running.
- *
- * This function checks if a specific process is running.
- *
- * \param p The process.
- * \retval Non-zero if the process is running.
- * \retval Zero if the process is not running.
- */
-int oc_process_is_running(struct oc_process *p);
-
-/**
- * Number of events waiting to be processed.
- *
- * \return The number of events that are currently waiting to be
- * processed.
- */
-int oc_process_nevents(void);
-
-/** @} */
-
-extern struct oc_process *oc_process_list;
-
-#define OC_PROCESS_LIST() oc_process_list
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OC_PROCESS_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/util/pt/lc-addrlabels.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/pt/lc-addrlabels.h b/net/oic/src/util/pt/lc-addrlabels.h
deleted file mode 100644
index 68a043e..0000000
--- a/net/oic/src/util/pt/lc-addrlabels.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-/**
- * \addtogroup lc
- * @{
- */
-
-/**
- * \file
- * Implementation of local continuations based on the "Labels as
- * values" feature of gcc
- * \author
- * Adam Dunkels <ad...@sics.se>
- *
- * This implementation of local continuations is based on a special
- * feature of the GCC C compiler called "labels as values". This
- * feature allows assigning pointers with the address of the code
- * corresponding to a particular C label.
- *
- * For more information, see the GCC documentation:
- * http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
- *
- * Thanks to dividuum for finding the nice local scope label
- * implementation.
- */
-
-#ifndef LC_ADDRLABELS_H_
-#define LC_ADDRLABELS_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** \hideinitializer */
-typedef void *lc_t;
-
-#define LC_INIT(s) s = NULL
-
-#define LC_RESUME(s) \
- do { \
- if (s != NULL) { \
- goto *s; \
- } \
- } while (0)
-
-#define LC_SET(s) \
- do { \
- ({ \
- __label__ resume; \
- resume: \
- (s) = &&resume; \
- }); \
- } while (0)
-
-#define LC_END(s)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LC_ADDRLABELS_H_ */
-/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/util/pt/lc-switch.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/pt/lc-switch.h b/net/oic/src/util/pt/lc-switch.h
deleted file mode 100644
index 7521c25..0000000
--- a/net/oic/src/util/pt/lc-switch.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-/**
- * \addtogroup lc
- * @{
- */
-
-/**
- * \file
- * Implementation of local continuations based on switch() statement
- * \author Adam Dunkels <ad...@sics.se>
- *
- * This implementation of local continuations uses the C switch()
- * statement to resume execution of a function somewhere inside the
- * function's body. The implementation is based on the fact that
- * switch() statements are able to jump directly into the bodies of
- * control structures such as if() or while() statements.
- *
- * This implementation borrows heavily from Simon Tatham's coroutines
- * implementation in C:
- * http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
- */
-
-#ifndef LC_SWITCH_H_
-#define LC_SWITCH_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* WARNING! lc implementation using switch() does not work if an
- LC_SET() is done within another switch() statement! */
-
-/** \hideinitializer */
-typedef unsigned short lc_t;
-
-#define LC_INIT(s) s = 0;
-
-#define LC_RESUME(s) \
- switch (s) { \
- case 0:
-
-#define LC_SET(s) \
- s = __LINE__; \
- case __LINE__:
-
-#define LC_END(s) }
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LC_SWITCH_H_ */
-
-/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/util/pt/lc.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/pt/lc.h b/net/oic/src/util/pt/lc.h
deleted file mode 100644
index 1d2c254..0000000
--- a/net/oic/src/util/pt/lc.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-/**
- * \addtogroup pt
- * @{
- */
-
-/**
- * \defgroup lc Local continuations
- * @{
- *
- * Local continuations form the basis for implementing protothreads. A
- * local continuation can be <i>set</i> in a specific function to
- * capture the state of the function. After a local continuation has
- * been set can be <i>resumed</i> in order to restore the state of the
- * function at the point where the local continuation was set.
- *
- *
- */
-
-/**
- * \file core/sys/lc.h
- * Local continuations
- * \author
- * Adam Dunkels <ad...@sics.se>
- *
- */
-
-#ifdef DOXYGEN
-/**
- * Initialize a local continuation.
- *
- * This operation initializes the local continuation, thereby
- * unsetting any previously set continuation state.
- *
- * \hideinitializer
- */
-#define LC_INIT(lc)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Set a local continuation.
- *
- * The set operation saves the state of the function at the point
- * where the operation is executed. As far as the set operation is
- * concerned, the state of the function does <b>not</b> include the
- * call-stack or local (automatic) variables, but only the program
- * counter and such CPU registers that needs to be saved.
- *
- * \hideinitializer
- */
-#define LC_SET(lc)
-
-/**
- * Resume a local continuation.
- *
- * The resume operation resumes a previously set local continuation, thus
- * restoring the state in which the function was when the local
- * continuation was set. If the local continuation has not been
- * previously set, the resume operation does nothing.
- *
- * \hideinitializer
- */
-#define LC_RESUME(lc)
-
-/**
- * Mark the end of local continuation usage.
- *
- * The end operation signifies that local continuations should not be
- * used any more in the function. This operation is not needed for
- * most implementations of local continuation, but is required by a
- * few implementations.
- *
- * \hideinitializer
- */
-#define LC_END(lc)
-
-/**
- * \var typedef lc_t;
- *
- * The local continuation type.
- *
- * \hideinitializer
- */
-#endif /* DOXYGEN */
-
-#ifndef LC_H_
-#define LC_H_
-
-#ifdef LC_CONF_INCLUDE
-#include LC_CONF_INCLUDE
-#else /* LC_CONF_INCLUDE */
-#include "lc-switch.h"
-#endif /* LC_CONF_INCLUDE */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LC_H_ */
-
-/** @} */
-/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/util/pt/pt-sem.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/pt/pt-sem.h b/net/oic/src/util/pt/pt-sem.h
deleted file mode 100644
index ad87c0d..0000000
--- a/net/oic/src/util/pt/pt-sem.h
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-/**
- * \addtogroup pt
- * @{
- */
-
-/**
- * \defgroup ptsem Protothread semaphores
- * @{
- *
- * This module implements counting semaphores on top of
- * protothreads. Semaphores are a synchronization primitive that
- * provide two operations: "wait" and "signal". The "wait" operation
- * checks the semaphore counter and blocks the thread if the counter
- * is zero. The "signal" operation increases the semaphore counter but
- * does not block. If another thread has blocked waiting for the
- * semaphore that is signaled, the blocked thread will become
- * runnable again.
- *
- * Semaphores can be used to implement other, more structured,
- * synchronization primitives such as monitors and message
- * queues/bounded buffers (see below).
- *
- * The following example shows how the producer-consumer problem, also
- * known as the bounded buffer problem, can be solved using
- * protothreads and semaphores. Notes on the program follow after the
- * example.
- *
- \code
-#include "pt-sem.h"
-
-#define NUM_ITEMS 32
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BUFSIZE 8
-
-static struct pt_sem mutex, full, empty;
-
-PT_THREAD(producer(struct pt *pt))
-{
- static int produced;
-
- PT_BEGIN(pt);
-
- for(produced = 0; produced < NUM_ITEMS; ++produced) {
-
- PT_SEM_WAIT(pt, &full);
-
- PT_SEM_WAIT(pt, &mutex);
- add_to_buffer(produce_item());
- PT_SEM_SIGNAL(pt, &mutex);
-
- PT_SEM_SIGNAL(pt, &empty);
- }
-
- PT_END(pt);
-}
-
-PT_THREAD(consumer(struct pt *pt))
-{
- static int consumed;
-
- PT_BEGIN(pt);
-
- for(consumed = 0; consumed < NUM_ITEMS; ++consumed) {
-
- PT_SEM_WAIT(pt, &empty);
-
- PT_SEM_WAIT(pt, &mutex);
- consume_item(get_from_buffer());
- PT_SEM_SIGNAL(pt, &mutex);
-
- PT_SEM_SIGNAL(pt, &full);
- }
-
- PT_END(pt);
-}
-
-PT_THREAD(driver_thread(struct pt *pt))
-{
- static struct pt pt_producer, pt_consumer;
-
- PT_BEGIN(pt);
-
- PT_SEM_INIT(&empty, 0);
- PT_SEM_INIT(&full, BUFSIZE);
- PT_SEM_INIT(&mutex, 1);
-
- PT_INIT(&pt_producer);
- PT_INIT(&pt_consumer);
-
- PT_WAIT_THREAD(pt, producer(&pt_producer) &
- consumer(&pt_consumer));
-
- PT_END(pt);
-}
- \endcode
- *
- * The program uses three protothreads: one protothread that
- * implements the consumer, one thread that implements the producer,
- * and one protothread that drives the two other protothreads. The
- * program uses three semaphores: "full", "empty" and "mutex". The
- * "mutex" semaphore is used to provide mutual exclusion for the
- * buffer, the "empty" semaphore is used to block the consumer is the
- * buffer is empty, and the "full" semaphore is used to block the
- * producer is the buffer is full.
- *
- * The "driver_thread" holds two protothread state variables,
- * "pt_producer" and "pt_consumer". It is important to note that both
- * these variables are declared as <i>static</i>. If the static
- * keyword is not used, both variables are stored on the stack. Since
- * protothreads do not store the stack, these variables may be
- * overwritten during a protothread wait operation. Similarly, both
- * the "consumer" and "producer" protothreads declare their local
- * variables as static, to avoid them being stored on the stack.
- *
- *
- */
-
-/**
- * \file
- * Counting semaphores implemented on protothreads
- * \author
- * Adam Dunkels <ad...@sics.se>
- *
- */
-
-#ifndef PT_SEM_H_
-#define PT_SEM_H_
-
-#include "pt.h"
-
-struct pt_sem
-{
- unsigned int head, tail;
-};
-
-#define PT_SEM_COUNT(s) ((s)->head - (s)->tail)
-
-/**
- * Initialize a semaphore
- *
- * This macro initializes a semaphore with a value for the
- * counter. Internally, the semaphores use an "unsigned int" to
- * represent the counter, and therefore the "count" argument should be
- * within range of an unsigned int.
- *
- * \param s (struct pt_sem *) A pointer to the pt_sem struct
- * representing the semaphore
- *
- * \param c (unsigned int) The initial count of the semaphore.
- * \hideinitializer
- */
-#define PT_SEM_INIT(s, c) \
- do { \
- (s)->tail = 0; \
- (s)->head = (c); \
- } while (0)
-
-/**
- * Wait for a semaphore
- *
- * This macro carries out the "wait" operation on the semaphore. The
- * wait operation causes the protothread to block while the counter is
- * zero. When the counter reaches a value larger than zero, the
- * protothread will continue.
- *
- * \param pt (struct pt *) A pointer to the protothread (struct pt) in
- * which the operation is executed.
- *
- * \param s (struct pt_sem *) A pointer to the pt_sem struct
- * representing the semaphore
- *
- * \hideinitializer
- */
-#define PT_SEM_WAIT(pt, s) \
- do { \
- PT_WAIT_UNTIL(pt, PT_SEM_COUNT(s) > 0); \
- ++(s)->tail; \
- } while (0)
-
-/**
- * Signal a semaphore
- *
- * This macro carries out the "signal" operation on the semaphore. The
- * signal operation increments the counter inside the semaphore, which
- * eventually will cause waiting protothreads to continue executing.
- *
- * \param pt (struct pt *) A pointer to the protothread (struct pt) in
- * which the operation is executed.
- *
- * \param s (struct pt_sem *) A pointer to the pt_sem struct
- * representing the semaphore
- *
- * \hideinitializer
- */
-#define PT_SEM_SIGNAL(pt, s) (++(s)->head)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* PT_SEM_H_ */
-
-/** @} */
-/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fa41bf8/net/oic/src/util/pt/pt.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/pt/pt.h b/net/oic/src/util/pt/pt.h
deleted file mode 100644
index 43d1ab7..0000000
--- a/net/oic/src/util/pt/pt.h
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-/**
- * \addtogroup pt
- * @{
- */
-
-/**
- * \file
- * Protothreads implementation.
- * \author
- * Adam Dunkels <ad...@sics.se>
- *
- */
-
-#ifndef PT_H_
-#define PT_H_
-
-#include "lc.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct pt
-{
- lc_t lc;
-};
-
-#define PT_WAITING 0
-#define PT_YIELDED 1
-#define PT_EXITED 2
-#define PT_ENDED 3
-
-/**
- * \name Initialization
- * @{
- */
-
-/**
- * Initialize a protothread.
- *
- * Initializes a protothread. Initialization must be done prior to
- * starting to execute the protothread.
- *
- * \param pt A pointer to the protothread control structure.
- *
- * \sa PT_SPAWN()
- *
- * \hideinitializer
- */
-#define PT_INIT(pt) LC_INIT((pt)->lc)
-
-/** @} */
-
-/**
- * \name Declaration and definition
- * @{
- */
-
-/**
- * Declaration of a protothread.
- *
- * This macro is used to declare a protothread. All protothreads must
- * be declared with this macro.
- *
- * \param name_args The name and arguments of the C function
- * implementing the protothread.
- *
- * \hideinitializer
- */
-#define PT_THREAD(name_args) char name_args
-
-/**
- * Declare the start of a protothread inside the C function
- * implementing the protothread.
- *
- * This macro is used to declare the starting point of a
- * protothread. It should be placed at the start of the function in
- * which the protothread runs. All C statements above the PT_BEGIN()
- * invokation will be executed each time the protothread is scheduled.
- *
- * \param pt A pointer to the protothread control structure.
- *
- * \hideinitializer
- */
-#define PT_BEGIN(pt) \
- { \
- char PT_YIELD_FLAG = 1; \
- if (PT_YIELD_FLAG) { \
- ; \
- } \
- LC_RESUME((pt)->lc)
-
-/**
- * Declare the end of a protothread.
- *
- * This macro is used for declaring that a protothread ends. It must
- * always be used together with a matching PT_BEGIN() macro.
- *
- * \param pt A pointer to the protothread control structure.
- *
- * \hideinitializer
- */
-#define PT_END(pt) \
- LC_END((pt)->lc); \
- PT_YIELD_FLAG = 0; \
- PT_INIT(pt); \
- return PT_ENDED; \
- }
-
-/** @} */
-
-/**
- * \name Blocked wait
- * @{
- */
-
-/**
- * Block and wait until condition is true.
- *
- * This macro blocks the protothread until the specified condition is
- * true.
- *
- * \param pt A pointer to the protothread control structure.
- * \param condition The condition.
- *
- * \hideinitializer
- */
-#define PT_WAIT_UNTIL(pt, condition) \
- do { \
- LC_SET((pt)->lc); \
- if (!(condition)) { \
- return PT_WAITING; \
- } \
- } while (0)
-
-/**
- * Block and wait while condition is true.
- *
- * This function blocks and waits while condition is true. See
- * PT_WAIT_UNTIL().
- *
- * \param pt A pointer to the protothread control structure.
- * \param cond The condition.
- *
- * \hideinitializer
- */
-#define PT_WAIT_WHILE(pt, cond) PT_WAIT_UNTIL((pt), !(cond))
-
-/** @} */
-
-/**
- * \name Hierarchical protothreads
- * @{
- */
-
-/**
- * Block and wait until a child protothread completes.
- *
- * This macro schedules a child protothread. The current protothread
- * will block until the child protothread completes.
- *
- * \note The child protothread must be manually initialized with the
- * PT_INIT() function before this function is used.
- *
- * \param pt A pointer to the protothread control structure.
- * \param thread The child protothread with arguments
- *
- * \sa PT_SPAWN()
- *
- * \hideinitializer
- */
-#define PT_WAIT_THREAD(pt, thread) PT_WAIT_WHILE((pt), PT_SCHEDULE(thread))
-
-/**
- * Spawn a child protothread and wait until it exits.
- *
- * This macro spawns a child protothread and waits until it exits. The
- * macro can only be used within a protothread.
- *
- * \param pt A pointer to the protothread control structure.
- * \param child A pointer to the child protothread's control structure.
- * \param thread The child protothread with arguments
- *
- * \hideinitializer
- */
-#define PT_SPAWN(pt, child, thread) \
- do { \
- PT_INIT((child)); \
- PT_WAIT_THREAD((pt), (thread)); \
- } while (0)
-
-/** @} */
-
-/**
- * \name Exiting and restarting
- * @{
- */
-
-/**
- * Restart the protothread.
- *
- * This macro will block and cause the running protothread to restart
- * its execution at the place of the PT_BEGIN() call.
- *
- * \param pt A pointer to the protothread control structure.
- *
- * \hideinitializer
- */
-#define PT_RESTART(pt) \
- do { \
- PT_INIT(pt); \
- return PT_WAITING; \
- } while (0)
-
-/**
- * Exit the protothread.
- *
- * This macro causes the protothread to exit. If the protothread was
- * spawned by another protothread, the parent protothread will become
- * unblocked and can continue to run.
- *
- * \param pt A pointer to the protothread control structure.
- *
- * \hideinitializer
- */
-#define PT_EXIT(pt) \
- do { \
- PT_INIT(pt); \
- return PT_EXITED; \
- } while (0)
-
-/** @} */
-
-/**
- * \name Calling a protothread
- * @{
- */
-
-/**
- * Schedule a protothread.
- *
- * This function schedules a protothread. The return value of the
- * function is non-zero if the protothread is running or zero if the
- * protothread has exited.
- *
- * \param f The call to the C function implementing the protothread to
- * be scheduled
- *
- * \hideinitializer
- */
-#define PT_SCHEDULE(f) ((f) < PT_EXITED)
-
-/** @} */
-
-/**
- * \name Yielding from a protothread
- * @{
- */
-
-/**
- * Yield from the current protothread.
- *
- * This function will yield the protothread, thereby allowing other
- * processing to take place in the system.
- *
- * \param pt A pointer to the protothread control structure.
- *
- * \hideinitializer
- */
-#define PT_YIELD(pt) \
- do { \
- PT_YIELD_FLAG = 0; \
- LC_SET((pt)->lc); \
- if (PT_YIELD_FLAG == 0) { \
- return PT_YIELDED; \
- } \
- } while (0)
-
-/**
- * \brief Yield from the protothread until a condition occurs.
- * \param pt A pointer to the protothread control structure.
- * \param cond The condition.
- *
- * This function will yield the protothread, until the
- * specified condition evaluates to true.
- *
- *
- * \hideinitializer
- */
-#define PT_YIELD_UNTIL(pt, cond) \
- do { \
- PT_YIELD_FLAG = 0; \
- LC_SET((pt)->lc); \
- if ((PT_YIELD_FLAG == 0) || !(cond)) { \
- return PT_YIELDED; \
- } \
- } while (0)
-
-/** @} */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* PT_H_ */
-
-/** @} */
[11/27] incubator-mynewt-core git commit: oci;
oc_main_poll() does not expect you to call into it periodically.
Posted by ma...@apache.org.
oci; oc_main_poll() does not expect you to call into it periodically.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/6e25f3f3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6e25f3f3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6e25f3f3
Branch: refs/heads/develop
Commit: 6e25f3f34d6f844ea1bb4151c71618f4e0aef845
Parents: 7c67f1c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 16 16:57:32 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800
----------------------------------------------------------------------
apps/ocf_sample/src/main.c | 12 ++----------
mgmt/oicmgr/src/oicmgr.c | 13 +------------
2 files changed, 3 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e25f3f3/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index 0e8ebe4..e423863 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -247,16 +247,8 @@ ocf_main_task_handler(void *arg)
os_callout_init(&callout, &ocf_aux_evq, stop_observe, NULL);
#endif
while (1) {
- uint32_t ticks;
- oc_clock_time_t next_event;
- next_event = oc_main_poll();
- ticks = oc_clock_time();
- if (next_event == 0) {
- ticks = OS_TIMEOUT_NEVER;
- } else {
- ticks = next_event - ticks;
- }
- os_sem_pend(&ocf_main_loop_sem, ticks);
+ oc_main_poll();
+ os_sem_pend(&ocf_main_loop_sem, OS_TIMEOUT_NEVER);
}
oc_main_shutdown();
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e25f3f3/mgmt/oicmgr/src/oicmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/oicmgr/src/oicmgr.c b/mgmt/oicmgr/src/oicmgr.c
index 0e631ef..4557189 100644
--- a/mgmt/oicmgr/src/oicmgr.c
+++ b/mgmt/oicmgr/src/oicmgr.c
@@ -43,7 +43,6 @@ struct omgr_cbuf {
struct omgr_state {
struct os_eventq *os_evq;
struct os_event os_event;
- struct os_callout os_oc_timer;
struct os_task os_task;
struct omgr_cbuf os_cbuf; /* CBOR buffer for NMGR task */
};
@@ -232,15 +231,7 @@ oc_signal_main_loop(void)
static void
omgr_process_oc_event(struct os_event *ev)
{
- struct omgr_state *o = &omgr_state;
- os_time_t next_event;
-
- next_event = oc_main_poll();
- if (next_event) {
- os_callout_reset(&o->os_oc_timer, next_event - os_time_get());
- } else {
- os_callout_stop(&o->os_oc_timer);
- }
+ oc_main_poll();
}
static void
@@ -251,8 +242,6 @@ omgr_event_start(struct os_event *ev)
oc_main_init((oc_handler_t *)&omgr_oc_handler);
os_eventq_ensure(&o->os_evq, NULL);
o->os_event.ev_cb = omgr_process_oc_event;
- os_callout_init(&o->os_oc_timer, mgmt_evq_get(), omgr_process_oc_event,
- NULL);
}
int
[03/27] incubator-mynewt-core git commit: oic;
remove add_periodic_observer, use os_callout instead.
Posted by ma...@apache.org.
oic; remove add_periodic_observer, use os_callout instead.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/297c35d1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/297c35d1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/297c35d1
Branch: refs/heads/develop
Commit: 297c35d16a21780a8feb3fdf0ea2cbbb1c6bf58b
Parents: b34779a
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 15 18:21:21 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:47 2016 -0800
----------------------------------------------------------------------
net/oic/include/oic/oc_ri.h | 1 +
net/oic/src/api/oc_ri.c | 89 ++++++++++------------------------------
2 files changed, 22 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/297c35d1/net/oic/include/oic/oc_ri.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_ri.h b/net/oic/include/oic/oc_ri.h
index c49b7be..30a706c 100644
--- a/net/oic/include/oic/oc_ri.h
+++ b/net/oic/include/oic/oc_ri.h
@@ -124,6 +124,7 @@ typedef struct oc_resource_s
oc_request_handler_t put_handler;
oc_request_handler_t post_handler;
oc_request_handler_t delete_handler;
+ struct os_callout callout;
uint16_t observe_period_seconds;
uint8_t num_observers;
} oc_resource_t;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/297c35d1/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 4d8c597..2ae8a61 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -49,6 +49,8 @@
OC_LIST(app_resources);
OC_LIST(observe_callbacks);
OC_MEMB(app_resources_s, oc_resource_t, MAX_APP_RESOURCES);
+
+static void periodic_observe_handler(struct os_event *ev);
#endif /* OC_SERVER */
#ifdef OC_CLIENT
@@ -270,7 +272,14 @@ oc_ri_shutdown(void)
oc_resource_t *
oc_ri_alloc_resource(void)
{
- return oc_memb_alloc(&app_resources_s);
+ struct oc_resource_s *resource;
+
+ resource = oc_memb_alloc(&app_resources_s);
+ if (resource) {
+ os_callout_init(&resource->callout, oc_evq_get(),
+ periodic_observe_handler, resource);
+ }
+ return resource;
}
void
@@ -334,73 +343,20 @@ check_event_callbacks(void)
}
#ifdef OC_SERVER
-static oc_event_callback_retval_t
-periodic_observe_handler(void *data)
-{
- oc_resource_t *resource = (oc_resource_t *)data;
-
- if (coap_notify_observers(resource, NULL, NULL)) {
- return CONTINUE;
- }
-
- return DONE;
-}
-
-static oc_event_callback_t *
-get_periodic_observe_callback(oc_resource_t *resource)
-{
- oc_event_callback_t *event_cb;
- bool found = false;
-
- for (event_cb = (oc_event_callback_t *)oc_list_head(observe_callbacks);
- event_cb; event_cb = event_cb->next) {
- if (resource == event_cb->data) {
- found = true;
- break;
- }
- }
-
- if (found) {
- return event_cb;
- }
-
- return NULL;
-}
static void
-remove_periodic_observe_callback(oc_resource_t *resource)
+periodic_observe_handler(struct os_event *ev)
{
- oc_event_callback_t *event_cb = get_periodic_observe_callback(resource);
-
- if (event_cb) {
- oc_etimer_stop(&event_cb->timer);
- oc_list_remove(observe_callbacks, event_cb);
- oc_memb_free(&event_callbacks_s, event_cb);
- }
-}
+ struct oc_resource_s *resource;
-static bool
-add_periodic_observe_callback(oc_resource_t *resource)
-{
- oc_event_callback_t *event_cb = get_periodic_observe_callback(resource);
+ resource = ev->ev_arg;
- if (!event_cb) {
- event_cb = (oc_event_callback_t *)oc_memb_alloc(&event_callbacks_s);
-
- if (!event_cb)
- return false;
-
- event_cb->data = resource;
- event_cb->callback = periodic_observe_handler;
- OC_PROCESS_CONTEXT_BEGIN(&timed_callback_events);
- oc_etimer_set(&event_cb->timer,
- resource->observe_period_seconds * OC_CLOCK_SECOND);
- OC_PROCESS_CONTEXT_END(&timed_callback_events);
- oc_list_add(observe_callbacks, event_cb);
- }
-
- return true;
+ if (coap_notify_observers(resource, NULL, NULL)) {
+ os_callout_reset(&resource->callout,
+ resource->observe_period_seconds * OS_TICKS_PER_SEC);
+ }
}
+
#endif
oc_interface_mask_t
@@ -694,11 +650,8 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
*/
bool set_observe_option = true;
if (cur_resource->properties & OC_PERIODIC) {
- if (!add_periodic_observe_callback(cur_resource)) {
- set_observe_option = false;
- coap_remove_observer_by_token(endpoint, packet->token,
- packet->token_len);
- }
+ os_callout_reset(&cur_resource->callout,
+ resource->observe_period_seconds * OC_CLOCK_SECOND);
}
if (set_observe_option) {
@@ -715,7 +668,7 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
if (coap_observe_handler(request, response, cur_resource, endpoint) >
0) {
if (cur_resource->properties & OC_PERIODIC) {
- remove_periodic_observe_callback(cur_resource);
+ os_callout_stop(&cur_resource->callout);
}
}
}
[05/27] incubator-mynewt-core git commit: oic;
use os_events for controlling when to run oc_etimer.
Posted by ma...@apache.org.
oic; use os_events for controlling when to run oc_etimer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a400a8d9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a400a8d9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a400a8d9
Branch: refs/heads/develop
Commit: a400a8d973bcf8158d6e4552b4e14451696f3ea6
Parents: a0ba348
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 15 10:48:34 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:47 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_ri.c | 4 +-
net/oic/src/port/mynewt/adaptor.h | 17 +-
net/oic/src/util/oc_etimer.c | 287 ++++++++++++++-------------------
net/oic/src/util/oc_etimer.h | 77 +--------
4 files changed, 139 insertions(+), 246 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a400a8d9/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 8de9c81..64dccb2 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -194,7 +194,7 @@ static void
start_processes(void)
{
allocate_events();
- oc_process_start(&oc_etimer_process, NULL);
+ oc_etimer_init();
oc_process_start(&timed_callback_events, NULL);
oc_process_start(&coap_engine, NULL);
oc_process_start(&message_buffer_handler, NULL);
@@ -209,7 +209,7 @@ start_processes(void)
static void
stop_processes(void)
{
- oc_process_exit(&oc_etimer_process);
+ oc_etimer_deinit();
oc_process_exit(&timed_callback_events);
oc_process_exit(&coap_engine);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a400a8d9/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
index 259691c..e9062e0 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -27,28 +27,29 @@ extern "C" {
struct os_eventq *oc_evq_get(void);
void oc_evq_set(struct os_eventq *evq);
+struct oc_message_s;
#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
int oc_connectivity_init_ip(void);
void oc_connectivity_shutdown_ip(void);
-void oc_send_buffer_ip(oc_message_t *message);
-void oc_send_buffer_ip_mcast(oc_message_t *message);
-oc_message_t *oc_attempt_rx_ip(void);
+void oc_send_buffer_ip(struct oc_message_s *message);
+void oc_send_buffer_ip_mcast(struct oc_message_s *message);
+struct oc_message_s *oc_attempt_rx_ip(void);
#endif
#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
int oc_connectivity_init_gatt(void);
void oc_connectivity_shutdown_gatt(void);
-void oc_send_buffer_gatt(oc_message_t *message);
-void oc_send_buffer_gatt_mcast(oc_message_t *message);
-oc_message_t *oc_attempt_rx_gatt(void);
+void oc_send_buffer_gatt(struct oc_message_s *message);
+void oc_send_buffer_gatt_mcast(struct oc_message_s *message);
+struct oc_message_s *oc_attempt_rx_gatt(void);
#endif
#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
int oc_connectivity_init_serial(void);
void oc_connectivity_shutdown_serial(void);
-void oc_send_buffer_serial(oc_message_t *message);
-oc_message_t *oc_attempt_rx_serial(void);
+void oc_send_buffer_serial(struct oc_message_s *message);
+struct oc_message_s *oc_attempt_rx_serial(void);
#endif
#ifdef __cplusplus
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a400a8d9/net/oic/src/util/oc_etimer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_etimer.c b/net/oic/src/util/oc_etimer.c
index bf56f49..138d251 100644
--- a/net/oic/src/util/oc_etimer.c
+++ b/net/oic/src/util/oc_etimer.c
@@ -34,230 +34,191 @@
*
*/
+#include <os/os_eventq.h>
+
#include "oc_etimer.h"
#include "oc_process.h"
+#include "port/mynewt/adaptor.h"
+
+static void oc_etimer_process(struct os_event *);
+
+static struct os_event etimer_ev = {
+ .ev_cb = oc_etimer_process
+};
static struct oc_etimer *timerlist;
static oc_clock_time_t next_expiration;
-OC_PROCESS(oc_etimer_process, "Event timer");
/*---------------------------------------------------------------------------*/
static void
update_time(void)
{
- oc_clock_time_t tdist;
- oc_clock_time_t now;
- struct oc_etimer *t;
-
- if (timerlist == NULL) {
- next_expiration = 0;
- } else {
- now = oc_clock_time();
- t = timerlist;
- /* Must calculate distance to next time into account due to wraps */
- tdist = t->timer.start + t->timer.interval - now;
- for (t = t->next; t != NULL; t = t->next) {
- if (t->timer.start + t->timer.interval - now < tdist) {
- tdist = t->timer.start + t->timer.interval - now;
- }
- }
- next_expiration = now + tdist;
- }
-}
-/*---------------------------------------------------------------------------*/
-OC_PROCESS_THREAD(oc_etimer_process, ev, data)
-{
- struct oc_etimer *t, *u;
-
- OC_PROCESS_BEGIN();
-
- timerlist = NULL;
-
- while (1) {
- OC_PROCESS_YIELD();
-
- if (ev == OC_PROCESS_EVENT_EXITED) {
- struct oc_process *p = data;
-
- while (timerlist != NULL && timerlist->p == p) {
- timerlist = timerlist->next;
- }
-
- if (timerlist != NULL) {
+ oc_clock_time_t tdist;
+ oc_clock_time_t now;
+ struct oc_etimer *t;
+
+ if (timerlist == NULL) {
+ next_expiration = 0;
+ } else {
+ now = oc_clock_time();
t = timerlist;
- while (t->next != NULL) {
- if (t->next->p == p) {
- t->next = t->next->next;
- } else
- t = t->next;
- }
- }
- continue;
- } else if (ev != OC_PROCESS_EVENT_POLL) {
- continue;
- }
-
- again:
-
- u = NULL;
-
- for (t = timerlist; t != NULL; t = t->next) {
- if (oc_timer_expired(&t->timer)) {
- if (oc_process_post(t->p, OC_PROCESS_EVENT_TIMER, t) ==
- OC_PROCESS_ERR_OK) {
-
- /* Reset the process ID of the event timer, to signal that the
- etimer has expired. This is later checked in the
- oc_etimer_expired() function. */
- t->p = OC_PROCESS_NONE;
- if (u != NULL) {
- u->next = t->next;
- } else {
- timerlist = t->next;
- }
- t->next = NULL;
- update_time();
- goto again;
- } else {
- oc_etimer_request_poll();
+ /* Must calculate distance to next time into account due to wraps */
+ tdist = t->timer.start + t->timer.interval - now;
+ for (t = t->next; t != NULL; t = t->next) {
+ if (t->timer.start + t->timer.interval - now < tdist) {
+ tdist = t->timer.start + t->timer.interval - now;
+ }
}
- }
- u = t;
+ next_expiration = now + tdist;
}
- }
-
- OC_PROCESS_END();
}
/*---------------------------------------------------------------------------*/
oc_clock_time_t
oc_etimer_request_poll(void)
{
- oc_process_poll(&oc_etimer_process);
- return oc_etimer_next_expiration_time();
+ oc_etimer_sched();
+ return oc_etimer_next_expiration_time();
}
/*---------------------------------------------------------------------------*/
static void
add_timer(struct oc_etimer *timer)
{
- struct oc_etimer *t;
-
- oc_etimer_request_poll();
-
- if (timer->p != OC_PROCESS_NONE) {
- for (t = timerlist; t != NULL; t = t->next) {
- if (t == timer) {
- /* Timer already on list, bail out. */
- timer->p = OC_PROCESS_CURRENT();
- update_time();
- return;
- }
+ struct oc_etimer *t;
+
+ oc_etimer_request_poll();
+
+ if (timer->p != OC_PROCESS_NONE) {
+ for (t = timerlist; t != NULL; t = t->next) {
+ if (t == timer) {
+ /* Timer already on list, bail out. */
+ timer->p = OC_PROCESS_CURRENT();
+ update_time();
+ return;
+ }
+ }
}
- }
- /* Timer not on list. */
- timer->p = OC_PROCESS_CURRENT();
- timer->next = timerlist;
- timerlist = timer;
+ /* Timer not on list. */
+ timer->p = OC_PROCESS_CURRENT();
+ timer->next = timerlist;
+ timerlist = timer;
- update_time();
+ update_time();
}
/*---------------------------------------------------------------------------*/
void
oc_etimer_set(struct oc_etimer *et, oc_clock_time_t interval)
{
- oc_timer_set(&et->timer, interval);
- add_timer(et);
-}
-/*---------------------------------------------------------------------------*/
-void
-oc_etimer_reset_with_new_interval(struct oc_etimer *et,
- oc_clock_time_t interval)
-{
- oc_timer_reset(&et->timer);
- et->timer.interval = interval;
- add_timer(et);
-}
-/*---------------------------------------------------------------------------*/
-void
-oc_etimer_reset(struct oc_etimer *et)
-{
- oc_timer_reset(&et->timer);
- add_timer(et);
+ oc_timer_set(&et->timer, interval);
+ add_timer(et);
}
/*---------------------------------------------------------------------------*/
void
oc_etimer_restart(struct oc_etimer *et)
{
- oc_timer_restart(&et->timer);
- add_timer(et);
+ oc_timer_restart(&et->timer);
+ add_timer(et);
}
/*---------------------------------------------------------------------------*/
-void
-oc_etimer_adjust(struct oc_etimer *et, int timediff)
+int
+oc_etimer_expired(struct oc_etimer *et)
{
- et->timer.start += timediff;
- update_time();
+ return et->p == OC_PROCESS_NONE;
}
/*---------------------------------------------------------------------------*/
int
-oc_etimer_expired(struct oc_etimer *et)
+oc_etimer_pending(void)
{
- return et->p == OC_PROCESS_NONE;
+ return timerlist != NULL;
}
/*---------------------------------------------------------------------------*/
oc_clock_time_t
-oc_etimer_expiration_time(struct oc_etimer *et)
+oc_etimer_next_expiration_time(void)
{
- return et->timer.start + et->timer.interval;
+ return oc_etimer_pending() ? next_expiration : 0;
}
/*---------------------------------------------------------------------------*/
-oc_clock_time_t
-oc_etimer_start_time(struct oc_etimer *et)
+void
+oc_etimer_stop(struct oc_etimer *et)
{
- return et->timer.start;
+ struct oc_etimer *t;
+
+ /* First check if et is the first event timer on the list. */
+ if (et == timerlist) {
+ timerlist = timerlist->next;
+ update_time();
+ } else {
+ /* Else walk through the list and try to find the item before the
+ et timer. */
+ for (t = timerlist; t != NULL && t->next != et; t = t->next)
+ ;
+
+ if (t != NULL) {
+ /* We've found the item before the event timer that we are about
+ to remove. We point the items next pointer to the event after
+ the removed item. */
+ t->next = et->next;
+
+ update_time();
+ }
+ }
+
+ /* Remove the next pointer from the item to be removed. */
+ et->next = NULL;
+ /* Set the timer as expired */
+ et->p = OC_PROCESS_NONE;
}
-/*---------------------------------------------------------------------------*/
-int
-oc_etimer_pending(void)
+
+void
+oc_etimer_init(void)
{
- return timerlist != NULL;
+ timerlist = NULL;
}
-/*---------------------------------------------------------------------------*/
-oc_clock_time_t
-oc_etimer_next_expiration_time(void)
+
+void
+oc_etimer_deinit(void)
{
- return oc_etimer_pending() ? next_expiration : 0;
+ timerlist = NULL;
}
-/*---------------------------------------------------------------------------*/
+
void
-oc_etimer_stop(struct oc_etimer *et)
+oc_etimer_sched(void)
{
- struct oc_etimer *t;
+ os_eventq_put(oc_evq_get(), &etimer_ev);
+}
- /* First check if et is the first event timer on the list. */
- if (et == timerlist) {
- timerlist = timerlist->next;
- update_time();
- } else {
- /* Else walk through the list and try to find the item before the
- et timer. */
- for (t = timerlist; t != NULL && t->next != et; t = t->next)
- ;
+static void
+oc_etimer_process(struct os_event *ev)
+{
+ struct oc_etimer *t, *u;
- if (t != NULL) {
- /* We've found the item before the event timer that we are about
- to remove. We point the items next pointer to the event after
- the removed item. */
- t->next = et->next;
+again:
+ u = NULL;
- update_time();
+ for (t = timerlist; t != NULL; t = t->next) {
+ if (oc_timer_expired(&t->timer)) {
+ if (oc_process_post(t->p, OC_PROCESS_EVENT_TIMER, t) ==
+ OC_PROCESS_ERR_OK) {
+
+ /* Reset the process ID of the event timer, to signal that the
+ etimer has expired. This is later checked in the
+ oc_etimer_expired() function. */
+ t->p = OC_PROCESS_NONE;
+ if (u != NULL) {
+ u->next = t->next;
+ } else {
+ timerlist = t->next;
+ }
+ t->next = NULL;
+ update_time();
+ goto again;
+ } else {
+ oc_etimer_request_poll();
+ }
+ }
+ u = t;
}
- }
-
- /* Remove the next pointer from the item to be removed. */
- et->next = NULL;
- /* Set the timer as expired */
- et->p = OC_PROCESS_NONE;
}
+
/*---------------------------------------------------------------------------*/
/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a400a8d9/net/oic/src/util/oc_etimer.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_etimer.h b/net/oic/src/util/oc_etimer.h
index 703b557..4ef58e5 100644
--- a/net/oic/src/util/oc_etimer.h
+++ b/net/oic/src/util/oc_etimer.h
@@ -95,37 +95,6 @@ struct oc_etimer
void oc_etimer_set(struct oc_etimer *et, oc_clock_time_t interval);
/**
- * \brief Reset an event timer with the same interval as was
- * previously set.
- * \param et A pointer to the event timer.
- *
- * This function resets the event timer with the same
- * interval that was given to the event timer with the
- * oc_etimer_set() function. The start point of the interval
- * is the exact time that the event timer last
- * expired. Therefore, this function will cause the timer
- * to be stable over time, unlike the oc_etimer_restart()
- * function.
- *
- * \sa oc_etimer_restart()
- */
-void oc_etimer_reset(struct oc_etimer *et);
-
-/**
- * \brief Reset an event timer with a new interval.
- * \param et A pointer to the event timer.
- * \param interval The interval before the timer expires.
- *
- * This function very similar to oc_etimer_reset. Opposed to
- * oc_etimer_reset it is possible to change the timout.
- * This allows accurate, non-periodic timers without drift.
- *
- * \sa oc_etimer_reset()
- */
-void oc_etimer_reset_with_new_interval(struct oc_etimer *et,
- oc_clock_time_t interval);
-
-/**
* \brief Restart an event timer from the current point in time
* \param et A pointer to the event timer.
*
@@ -143,47 +112,6 @@ void oc_etimer_reset_with_new_interval(struct oc_etimer *et,
void oc_etimer_restart(struct oc_etimer *et);
/**
- * \brief Adjust the expiration time for an event timer
- * \param et A pointer to the event timer.
- * \param td The time difference to adjust the expiration time with.
- *
- * This function is used to adjust the time the event
- * timer will expire. It can be used to synchronize
- * periodic timers without the need to restart the timer
- * or change the timer interval.
- *
- * \note This function should only be used for small
- * adjustments. For large adjustments use oc_etimer_set()
- * instead.
- *
- * \note A periodic timer will drift unless the
- * oc_etimer_reset() function is used.
- *
- * \sa oc_etimer_set()
- * \sa oc_etimer_reset()
- */
-void oc_etimer_adjust(struct oc_etimer *et, int td);
-
-/**
- * \brief Get the expiration time for the event timer.
- * \param et A pointer to the event timer
- * \return The expiration time for the event timer.
- *
- * This function returns the expiration time for an event timer.
- */
-oc_clock_time_t oc_etimer_expiration_time(struct oc_etimer *et);
-
-/**
- * \brief Get the start time for the event timer.
- * \param et A pointer to the event timer
- * \return The start time for the event timer.
- *
- * This function returns the start time (when the timer
- * was last set) for an event timer.
- */
-oc_clock_time_t oc_etimer_start_time(struct oc_etimer *et);
-
-/**
* \brief Check if an event timer has expired.
* \param et A pointer to the event timer
* \return Non-zero if the timer has expired, zero otherwise.
@@ -245,7 +173,10 @@ oc_clock_time_t oc_etimer_next_expiration_time(void);
/** @} */
-OC_PROCESS_NAME(oc_etimer_process);
+void oc_etimer_init(void);
+void oc_etimer_deinit(void);
+void oc_etimer_sched(void);
+
#ifdef __cplusplus
}
#endif
[25/27] incubator-mynewt-core git commit: oic;
fix use-after-free when using IP together with other transports.
Message was getting freed by IP before it is delivered to others.
Posted by ma...@apache.org.
oic; fix use-after-free when using IP together with other transports.
Message was getting freed by IP before it is delivered to others.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/bdc5c120
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/bdc5c120
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/bdc5c120
Branch: refs/heads/develop
Commit: bdc5c1202a542877c2d80a69101dab4392a3a4df
Parents: 408077e
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 21 16:47:28 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
net/oic/src/port/mynewt/adaptor.c | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bdc5c120/net/oic/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.c b/net/oic/src/port/mynewt/adaptor.c
index ea33f58..40785c2 100644
--- a/net/oic/src/port/mynewt/adaptor.c
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -94,6 +94,7 @@ oc_send_buffer(oc_message_t *message)
void oc_send_multicast_message(oc_message_t *message)
{
+ oc_message_add_ref(message);
/* send on all the transports. Don't forget to reference the message
* so it doesn't get deleted */
@@ -113,6 +114,8 @@ void oc_send_multicast_message(oc_message_t *message)
oc_message_add_ref(message);
oc_send_buffer_serial(message);
#endif
+
+ oc_message_unref(message);
}
void
[12/27] incubator-mynewt-core git commit: oic; using os_callout() now;
remove oc_etimer.
Posted by ma...@apache.org.
oic; using os_callout() now; remove oc_etimer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7c67f1c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7c67f1c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7c67f1c2
Branch: refs/heads/develop
Commit: 7c67f1c2e0a51f2f270f35988f2a72957dcbb8b0
Parents: cf8db8f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 16 16:18:06 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800
----------------------------------------------------------------------
net/oic/include/oic/oc_api.h | 4 -
net/oic/include/oic/oc_ri.h | 13 --
net/oic/src/api/oc_main.c | 9 +-
net/oic/src/api/oc_ri.c | 18 +--
net/oic/src/messaging/coap/observe.h | 1 -
net/oic/src/util/oc_etimer.c | 224 ------------------------------
net/oic/src/util/oc_etimer.h | 186 -------------------------
net/oic/src/util/oc_timer.c | 131 -----------------
net/oic/src/util/oc_timer.h | 96 -------------
9 files changed, 7 insertions(+), 675 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c67f1c2/net/oic/include/oic/oc_api.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_api.h b/net/oic/include/oic/oc_api.h
index 83e91f7..f0c6346 100644
--- a/net/oic/include/oic/oc_api.h
+++ b/net/oic/include/oic/oc_api.h
@@ -138,10 +138,6 @@ bool oc_stop_observe(const char *uri, oc_server_handle_t *server);
/** Common operations */
-void oc_set_delayed_callback(void *cb_data, oc_trigger_t callback,
- uint16_t seconds);
-void oc_remove_delayed_callback(void *cb_data, oc_trigger_t callback);
-
/** API for setting handlers for interrupts */
#define oc_signal_interrupt_handler(name) \
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c67f1c2/net/oic/include/oic/oc_ri.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_ri.h b/net/oic/include/oic/oc_ri.h
index 30a706c..79e57e6 100644
--- a/net/oic/include/oic/oc_ri.h
+++ b/net/oic/include/oic/oc_ri.h
@@ -21,7 +21,6 @@
#include "oc_rep.h"
#include "oc_uuid.h"
#include "../../src/port/oc_connectivity.h"
-#include "../../src/util/oc_etimer.h"
#ifdef __cplusplus
extern "C" {
@@ -129,18 +128,6 @@ typedef struct oc_resource_s
uint8_t num_observers;
} oc_resource_t;
-typedef enum { DONE = 0, CONTINUE } oc_event_callback_retval_t;
-
-typedef oc_event_callback_retval_t (*oc_trigger_t)(void *);
-
-typedef struct oc_event_callback_s
-{
- struct oc_event_callback_s *next;
- struct oc_etimer timer;
- oc_trigger_t callback;
- void *data;
-} oc_event_callback_t;
-
void oc_ri_init(void);
void oc_ri_shutdown(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c67f1c2/net/oic/src/api/oc_main.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_main.c b/net/oic/src/api/oc_main.c
index 9086b4e..8a19243 100644
--- a/net/oic/src/api/oc_main.c
+++ b/net/oic/src/api/oc_main.c
@@ -21,7 +21,6 @@
#include "port/oc_clock.h"
#include "port/oc_connectivity.h"
-#include "util/oc_etimer.h"
#include "util/oc_process.h"
#include "oc_api.h"
@@ -93,11 +92,9 @@ err:
oc_clock_time_t
oc_main_poll(void)
{
- oc_clock_time_t ticks_until_next_event = oc_etimer_request_poll();
- while (oc_process_run()) {
- ticks_until_next_event = oc_etimer_request_poll();
- }
- return ticks_until_next_event;
+ while (oc_process_run());
+
+ return 0;
}
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c67f1c2/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 7d08b82..32d9a62 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -20,7 +20,6 @@
#include <os/os_callout.h>
-#include "util/oc_etimer.h"
#include "util/oc_list.h"
#include "util/oc_memb.h"
#include "util/oc_process.h"
@@ -30,6 +29,7 @@
#include "messaging/coap/oc_coap.h"
#include "port/oc_random.h"
+#include "port/oc_clock.h"
#include "port/mynewt/adaptor.h"
#include "oc_buffer.h"
@@ -192,7 +192,6 @@ static void
start_processes(void)
{
allocate_events();
- oc_etimer_init();
oc_process_start(&coap_engine, NULL);
oc_process_start(&message_buffer_handler, NULL);
@@ -206,7 +205,6 @@ start_processes(void)
static void
stop_processes(void)
{
- oc_etimer_deinit();
oc_process_exit(&coap_engine);
#ifdef OC_SECURITY
@@ -235,7 +233,6 @@ void
oc_ri_init(void)
{
oc_random_init(0); // Fix: allow user to seed RNG.
- oc_clock_init();
set_mpro_status_codes();
#ifdef OC_SERVER
@@ -608,7 +605,7 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
bool set_observe_option = true;
if (cur_resource->properties & OC_PERIODIC) {
os_callout_reset(&cur_resource->callout,
- resource->observe_period_seconds * OC_CLOCK_SECOND);
+ resource->observe_period_seconds * OS_TICKS_PER_SEC);
}
if (set_observe_option) {
@@ -705,13 +702,6 @@ oc_ri_remove_client_cb_by_mid(uint16_t mid)
free_client_cb(cb);
}
-oc_event_callback_retval_t
-oc_ri_remove_client_cb(void *data)
-{
- free_client_cb(data);
- return DONE;
-}
-
bool
oc_ri_send_rst(oc_endpoint_t *endpoint, uint8_t *token, uint8_t token_len,
uint16_t mid)
@@ -789,7 +779,7 @@ oc_ri_invoke_client_cb(void *response, oc_endpoint_t *endpoint)
if (cb->discovery) {
if (oc_ri_process_discovery_payload(payload, payload_len, cb->handler,
endpoint) == OC_STOP_DISCOVERY) {
- oc_ri_remove_client_cb(cb);
+ free_client_cb(cb);
}
} else {
uint16_t err =
@@ -855,7 +845,7 @@ oc_ri_remove_cb(struct os_event *ev)
cb = ev->ev_arg;
- oc_ri_remove_client_cb(cb);
+ free_client_cb(cb);
}
oc_client_cb_t *
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c67f1c2/net/oic/src/messaging/coap/observe.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.h b/net/oic/src/messaging/coap/observe.h
index 20c207e..b1eadc2 100644
--- a/net/oic/src/messaging/coap/observe.h
+++ b/net/oic/src/messaging/coap/observe.h
@@ -61,7 +61,6 @@ typedef struct coap_observer
int32_t obs_counter;
- struct oc_etimer retrans_timer;
uint8_t retrans_counter;
} coap_observer_t;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c67f1c2/net/oic/src/util/oc_etimer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_etimer.c b/net/oic/src/util/oc_etimer.c
deleted file mode 100644
index 138d251..0000000
--- a/net/oic/src/util/oc_etimer.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright (c) 2016 Intel Corporation
- *
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-#include <os/os_eventq.h>
-
-#include "oc_etimer.h"
-#include "oc_process.h"
-#include "port/mynewt/adaptor.h"
-
-static void oc_etimer_process(struct os_event *);
-
-static struct os_event etimer_ev = {
- .ev_cb = oc_etimer_process
-};
-
-static struct oc_etimer *timerlist;
-static oc_clock_time_t next_expiration;
-
-/*---------------------------------------------------------------------------*/
-static void
-update_time(void)
-{
- oc_clock_time_t tdist;
- oc_clock_time_t now;
- struct oc_etimer *t;
-
- if (timerlist == NULL) {
- next_expiration = 0;
- } else {
- now = oc_clock_time();
- t = timerlist;
- /* Must calculate distance to next time into account due to wraps */
- tdist = t->timer.start + t->timer.interval - now;
- for (t = t->next; t != NULL; t = t->next) {
- if (t->timer.start + t->timer.interval - now < tdist) {
- tdist = t->timer.start + t->timer.interval - now;
- }
- }
- next_expiration = now + tdist;
- }
-}
-/*---------------------------------------------------------------------------*/
-oc_clock_time_t
-oc_etimer_request_poll(void)
-{
- oc_etimer_sched();
- return oc_etimer_next_expiration_time();
-}
-/*---------------------------------------------------------------------------*/
-static void
-add_timer(struct oc_etimer *timer)
-{
- struct oc_etimer *t;
-
- oc_etimer_request_poll();
-
- if (timer->p != OC_PROCESS_NONE) {
- for (t = timerlist; t != NULL; t = t->next) {
- if (t == timer) {
- /* Timer already on list, bail out. */
- timer->p = OC_PROCESS_CURRENT();
- update_time();
- return;
- }
- }
- }
-
- /* Timer not on list. */
- timer->p = OC_PROCESS_CURRENT();
- timer->next = timerlist;
- timerlist = timer;
-
- update_time();
-}
-/*---------------------------------------------------------------------------*/
-void
-oc_etimer_set(struct oc_etimer *et, oc_clock_time_t interval)
-{
- oc_timer_set(&et->timer, interval);
- add_timer(et);
-}
-/*---------------------------------------------------------------------------*/
-void
-oc_etimer_restart(struct oc_etimer *et)
-{
- oc_timer_restart(&et->timer);
- add_timer(et);
-}
-/*---------------------------------------------------------------------------*/
-int
-oc_etimer_expired(struct oc_etimer *et)
-{
- return et->p == OC_PROCESS_NONE;
-}
-/*---------------------------------------------------------------------------*/
-int
-oc_etimer_pending(void)
-{
- return timerlist != NULL;
-}
-/*---------------------------------------------------------------------------*/
-oc_clock_time_t
-oc_etimer_next_expiration_time(void)
-{
- return oc_etimer_pending() ? next_expiration : 0;
-}
-/*---------------------------------------------------------------------------*/
-void
-oc_etimer_stop(struct oc_etimer *et)
-{
- struct oc_etimer *t;
-
- /* First check if et is the first event timer on the list. */
- if (et == timerlist) {
- timerlist = timerlist->next;
- update_time();
- } else {
- /* Else walk through the list and try to find the item before the
- et timer. */
- for (t = timerlist; t != NULL && t->next != et; t = t->next)
- ;
-
- if (t != NULL) {
- /* We've found the item before the event timer that we are about
- to remove. We point the items next pointer to the event after
- the removed item. */
- t->next = et->next;
-
- update_time();
- }
- }
-
- /* Remove the next pointer from the item to be removed. */
- et->next = NULL;
- /* Set the timer as expired */
- et->p = OC_PROCESS_NONE;
-}
-
-void
-oc_etimer_init(void)
-{
- timerlist = NULL;
-}
-
-void
-oc_etimer_deinit(void)
-{
- timerlist = NULL;
-}
-
-void
-oc_etimer_sched(void)
-{
- os_eventq_put(oc_evq_get(), &etimer_ev);
-}
-
-static void
-oc_etimer_process(struct os_event *ev)
-{
- struct oc_etimer *t, *u;
-
-again:
- u = NULL;
-
- for (t = timerlist; t != NULL; t = t->next) {
- if (oc_timer_expired(&t->timer)) {
- if (oc_process_post(t->p, OC_PROCESS_EVENT_TIMER, t) ==
- OC_PROCESS_ERR_OK) {
-
- /* Reset the process ID of the event timer, to signal that the
- etimer has expired. This is later checked in the
- oc_etimer_expired() function. */
- t->p = OC_PROCESS_NONE;
- if (u != NULL) {
- u->next = t->next;
- } else {
- timerlist = t->next;
- }
- t->next = NULL;
- update_time();
- goto again;
- } else {
- oc_etimer_request_poll();
- }
- }
- u = t;
- }
-}
-
-/*---------------------------------------------------------------------------*/
-/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c67f1c2/net/oic/src/util/oc_etimer.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_etimer.h b/net/oic/src/util/oc_etimer.h
deleted file mode 100644
index 4ef58e5..0000000
--- a/net/oic/src/util/oc_etimer.h
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (c) 2016 Intel Corporation
- *
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-/**
- * \defgroup etimer Event timers
- *
- * Event timers provides a way to generate timed events. An event
- * timer will post an event to the process that set the timer when the
- * event timer expires.
- *
- * An event timer is declared as a \c struct \c etimer and all access
- * to the event timer is made by a pointer to the declared event
- * timer.
- *
- * \sa \ref timer "Simple timer library"
- * \sa \ref clock "Clock library" (used by the timer library)
- *
- * @{
- */
-
-#ifndef OC_ETIMER_H
-#define OC_ETIMER_H
-
-#include "oc_process.h"
-#include "oc_timer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * A timer.
- *
- * This structure is used for declaring a timer. The timer must be set
- * with oc_etimer_set() before it can be used.
- *
- * \hideinitializer
- */
-struct oc_etimer
-{
- struct oc_timer timer;
- struct oc_etimer *next;
- struct oc_process *p;
-};
-
-/**
- * \name Functions called from application programs
- * @{
- */
-
-/**
- * \brief Set an event timer.
- * \param et A pointer to the event timer
- * \param interval The interval before the timer expires.
- *
- * This function is used to set an event timer for a time
- * sometime in the future. When the event timer expires,
- * the event PROCESS_EVENT_TIMER will be posted to the
- * process that called the oc_etimer_set() function.
- *
- */
-void oc_etimer_set(struct oc_etimer *et, oc_clock_time_t interval);
-
-/**
- * \brief Restart an event timer from the current point in time
- * \param et A pointer to the event timer.
- *
- * This function restarts the event timer with the same
- * interval that was given to the oc_etimer_set()
- * function. The event timer will start at the current
- * time.
- *
- * \note A periodic timer will drift if this function is
- * used to reset it. For periodic timers, use the
- * oc_etimer_reset() function instead.
- *
- * \sa oc_etimer_reset()
- */
-void oc_etimer_restart(struct oc_etimer *et);
-
-/**
- * \brief Check if an event timer has expired.
- * \param et A pointer to the event timer
- * \return Non-zero if the timer has expired, zero otherwise.
- *
- * This function tests if an event timer has expired and
- * returns true or false depending on its status.
- */
-int oc_etimer_expired(struct oc_etimer *et);
-
-/**
- * \brief Stop a pending event timer.
- * \param et A pointer to the pending event timer.
- *
- * This function stops an event timer that has previously
- * been set with oc_etimer_set() or oc_etimer_reset(). After
- * this function has been called, the event timer will not
- * emit any event when it expires.
- *
- */
-void oc_etimer_stop(struct oc_etimer *et);
-
-/** @} */
-
-/**
- * \name Functions called from timer interrupts, by the system
- * @{
- */
-
-/**
- * \brief Make the event timer aware that the clock has changed
- *
- * This function is used to inform the event timer module
- * that the system clock has been updated. Typically, this
- * function would be called from the timer interrupt
- * handler when the clock has ticked.
- */
-oc_clock_time_t oc_etimer_request_poll(void);
-
-/**
- * \brief Check if there are any non-expired event timers.
- * \return True if there are active event timers, false if there are
- * no active timers.
- *
- * This function checks if there are any active event
- * timers that have not expired.
- */
-int oc_etimer_pending(void);
-
-/**
- * \brief Get next event timer expiration time.
- * \return Next expiration time of all pending event timers.
- * If there are no pending event timers this function
- * returns 0.
- *
- * This functions returns next expiration time of all
- * pending event timers.
- */
-oc_clock_time_t oc_etimer_next_expiration_time(void);
-
-/** @} */
-
-void oc_etimer_init(void);
-void oc_etimer_deinit(void);
-void oc_etimer_sched(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OC_ETIMER_H */
-/** @} */
-/** @} */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c67f1c2/net/oic/src/util/oc_timer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_timer.c b/net/oic/src/util/oc_timer.c
deleted file mode 100644
index 5372f0b..0000000
--- a/net/oic/src/util/oc_timer.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-#include "oc_timer.h"
-
-/*---------------------------------------------------------------------------*/
-/**
- * Set a timer.
- *
- * This function is used to set a timer for a time sometime in the
- * future. The function oc_timer_expired() will evaluate to true after
- * the timer has expired.
- *
- * \param t A pointer to the timer
- * \param interval The interval before the timer expires.
- *
- */
-void
-oc_timer_set(struct oc_timer *t, oc_clock_time_t interval)
-{
- t->interval = interval;
- t->start = oc_clock_time();
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Reset the timer with the same interval.
- *
- * This function resets the timer with the same interval that was
- * given to the oc_timer_set() function. The start point of the interval
- * is the exact time that the timer last expired. Therefore, this
- * function will cause the timer to be stable over time, unlike the
- * oc_timer_restart() function.
- *
- * \note Must not be executed before timer expired
- *
- * \param t A pointer to the timer.
- * \sa oc_timer_restart()
- */
-void
-oc_timer_reset(struct oc_timer *t)
-{
- t->start += t->interval;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Restart the timer from the current point in time
- *
- * This function restarts a timer with the same interval that was
- * given to the oc_timer_set() function. The timer will start at the
- * current time.
- *
- * \note A periodic timer will drift if this function is used to reset
- * it. For preioric timers, use the oc_timer_reset() function instead.
- *
- * \param t A pointer to the timer.
- *
- * \sa oc_timer_reset()
- */
-void
-oc_timer_restart(struct oc_timer *t)
-{
- t->start = oc_clock_time();
-}
-/*---------------------------------------------------------------------------*/
-/**
- * Check if a timer has expired.
- *
- * This function tests if a timer has expired and returns true or
- * false depending on its status.
- *
- * \param t A pointer to the timer
- *
- * \return Non-zero if the timer has expired, zero otherwise.
- *
- */
-int
-oc_timer_expired(struct oc_timer *t)
-{
- /* Note: Can not return diff >= t->interval so we add 1 to diff and return
- t->interval < diff - required to avoid an internal error in mspgcc. */
- oc_clock_time_t diff = (oc_clock_time() - t->start) + 1;
- return t->interval < diff;
-}
-/*---------------------------------------------------------------------------*/
-/**
- * The time until the timer expires
- *
- * This function returns the time until the timer expires.
- *
- * \param t A pointer to the timer
- *
- * \return The time until the timer expires
- *
- */
-oc_clock_time_t
-oc_timer_remaining(struct oc_timer *t)
-{
- return t->start + t->interval - oc_clock_time();
-}
-/*---------------------------------------------------------------------------*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7c67f1c2/net/oic/src/util/oc_timer.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_timer.h b/net/oic/src/util/oc_timer.h
deleted file mode 100644
index fd6c826..0000000
--- a/net/oic/src/util/oc_timer.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-/**
- * \defgroup timer Timer library
- *
- * The Contiki kernel does not provide support for timed
- * events. Rather, an application that wants to use timers needs to
- * explicitly use the timer library.
- *
- * The timer library provides functions for setting, resetting and
- * restarting timers, and for checking if a timer has expired. An
- * application must "manually" check if its timers have expired; this
- * is not done automatically.
- *
- * A timer is declared as a \c struct \c timer and all access to the
- * timer is made by a pointer to the declared timer.
- *
- * \note The timer library is not able to post events when a timer
- * expires. The \ref etimer "Event timers" should be used for this
- * purpose.
- *
- * \note The timer library uses the \ref clock "Clock library" to
- * measure time. Intervals should be specified in the format used by
- * the clock library.
- *
- * \sa \ref etimer "Event timers"
- *
- * @{
- */
-
-#ifndef OC_TIMER_H
-#define OC_TIMER_H
-
-#include "../port/oc_clock.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * A timer.
- *
- * This structure is used for declaring a timer. The timer must be set
- * with timer_set() before it can be used.
- *
- * \hideinitializer
- */
-struct oc_timer
-{
- oc_clock_time_t start;
- oc_clock_time_t interval;
-};
-
-void oc_timer_set(struct oc_timer *t, oc_clock_time_t interval);
-void oc_timer_reset(struct oc_timer *t);
-void oc_timer_restart(struct oc_timer *t);
-int oc_timer_expired(struct oc_timer *t);
-oc_clock_time_t oc_timer_remaining(struct oc_timer *t);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OC_TIMER_H */
[21/27] incubator-mynewt-core git commit: oic coap;
using wrong local variable to set retransmit timer.
Posted by ma...@apache.org.
oic coap; using wrong local variable to set retransmit timer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/0f55f211
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0f55f211
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0f55f211
Branch: refs/heads/develop
Commit: 0f55f2111b771c119766e3d37d98d34b81a17ef0
Parents: 97b87d9
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 21 11:31:54 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_ri.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0f55f211/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index bcb605a..67e708f 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -586,7 +586,7 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
bool set_observe_option = true;
if (cur_resource->properties & OC_PERIODIC) {
os_callout_reset(&cur_resource->callout,
- resource->observe_period_seconds * OS_TICKS_PER_SEC);
+ cur_resource->observe_period_seconds * OS_TICKS_PER_SEC);
}
if (set_observe_option) {
[18/27] incubator-mynewt-core git commit: os_mempool.h;
fixes to whitespaces.
Posted by ma...@apache.org.
os_mempool.h; fixes to whitespaces.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/e6179b5d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e6179b5d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e6179b5d
Branch: refs/heads/develop
Commit: e6179b5d2f52c7ca0058cf2f107fcbe8415fe164
Parents: 3fa41bf
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Nov 18 10:20:07 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
kernel/os/include/os/os_mempool.h | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e6179b5d/kernel/os/include/os/os_mempool.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_mempool.h b/kernel/os/include/os/os_mempool.h
index 4ada94f..d6aa237 100644
--- a/kernel/os/include/os/os_mempool.h
+++ b/kernel/os/include/os/os_mempool.h
@@ -6,7 +6,7 @@
* to you 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,
@@ -27,11 +27,11 @@
extern "C" {
#endif
-/*
- * A memory block structure. This simply contains a pointer to the free list
- * chain and is only used when the block is on the free list. When the block
- * has been removed from the free list the entire memory block is usable by the
- * caller.
+/*
+ * A memory block structure. This simply contains a pointer to the free list
+ * chain and is only used when the block is on the free list. When the block
+ * has been removed from the free list the entire memory block is usable by the
+ * caller.
*/
struct os_memblock {
SLIST_ENTRY(os_memblock) mb_next;
@@ -62,19 +62,19 @@ struct os_mempool_info {
char omi_name[OS_MEMPOOL_INFO_NAME_LEN];
};
-struct os_mempool *os_mempool_info_get_next(struct os_mempool *,
+struct os_mempool *os_mempool_info_get_next(struct os_mempool *,
struct os_mempool_info *);
-/*
- * To calculate size of the memory buffer needed for the pool. NOTE: This size
- * is NOT in bytes! The size is the number of os_membuf_t elements required for
+/*
+ * To calculate size of the memory buffer needed for the pool. NOTE: This size
+ * is NOT in bytes! The size is the number of os_membuf_t elements required for
* the memory pool.
*/
#if (OS_CFG_ALIGNMENT == OS_CFG_ALIGN_4)
#define OS_MEMPOOL_SIZE(n,blksize) ((((blksize) + 3) / 4) * (n))
typedef uint32_t os_membuf_t;
#else
-#define OS_MEMPOOL_SIZE(n,blksize) ((((blksize) + 7) / 8) * (n))
+#define OS_MEMPOOL_SIZE(n,blksize) ((((blksize) + 7) / 8) * (n))
typedef uint64_t os_membuf_t;
#endif
@@ -83,7 +83,7 @@ typedef uint64_t os_membuf_t;
(sizeof (os_membuf_t) * OS_MEMPOOL_SIZE((n), (blksize)))
/* Initialize a memory pool */
-os_error_t os_mempool_init(struct os_mempool *mp, int blocks, int block_size,
+os_error_t os_mempool_init(struct os_mempool *mp, int blocks, int block_size,
void *membuf, char *name);
/* Checks if a memory block was allocated from the specified mempool. */
[23/27] incubator-mynewt-core git commit: oic;
use os_mempool for coap observers. Fix use-after-free error.
Posted by ma...@apache.org.
oic; use os_mempool for coap observers. Fix use-after-free error.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/408077eb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/408077eb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/408077eb
Branch: refs/heads/develop
Commit: 408077eb74a8cd0a9cf5cc376e432cb4de6a2b66
Parents: f861cf8
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 21 15:12:46 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
net/oic/src/messaging/coap/engine.c | 1 +
net/oic/src/messaging/coap/observe.c | 401 ++++++++++++++++--------------
net/oic/src/messaging/coap/observe.h | 2 +
3 files changed, 212 insertions(+), 192 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/408077eb/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index a17ebd6..1145447 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -306,5 +306,6 @@ coap_engine_init(void)
coap_transaction_init();
#ifdef OC_SERVER
coap_separate_init();
+ coap_observe_init();
#endif
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/408077eb/net/oic/src/messaging/coap/observe.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.c b/net/oic/src/messaging/coap/observe.c
index 4bd1d96..c16823a 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -35,11 +35,14 @@
#ifdef OC_SERVER
-#include "observe.h"
-#include "util/oc_memb.h"
#include <stdio.h>
#include <string.h>
+#include <os/os_mempool.h>
+
+#include "observe.h"
+#include "util/oc_memb.h"
+
#include "oc_coap.h"
#include "oc_rep.h"
#include "oc_ri.h"
@@ -47,7 +50,10 @@
uint64_t observe_counter = 3;
/*---------------------------------------------------------------------------*/
OC_LIST(observers_list);
-OC_MEMB(observers_memb, coap_observer_t, COAP_MAX_OBSERVERS);
+
+static struct os_mempool coap_observers;
+static uint8_t coap_observer_area[OS_MEMPOOL_BYTES(COAP_MAX_OBSERVERS,
+ sizeof(coap_observer_t))];
/*---------------------------------------------------------------------------*/
/*- Internal API ------------------------------------------------------------*/
@@ -57,32 +63,32 @@ add_observer(oc_resource_t *resource, oc_endpoint_t *endpoint,
const uint8_t *token, size_t token_len, const char *uri,
int uri_len)
{
- /* Remove existing observe relationship, if any. */
- int dup = coap_remove_observer_by_uri(endpoint, uri);
+ /* Remove existing observe relationship, if any. */
+ int dup = coap_remove_observer_by_uri(endpoint, uri);
- coap_observer_t *o = oc_memb_alloc(&observers_memb);
+ coap_observer_t *o = os_memblock_get(&coap_observers);
- if (o) {
- int max = sizeof(o->url) - 1;
- if (max > uri_len) {
- max = uri_len;
+ if (o) {
+ int max = sizeof(o->url) - 1;
+ if (max > uri_len) {
+ max = uri_len;
+ }
+ memcpy(o->url, uri, max);
+ o->url[max] = 0;
+ memcpy(&o->endpoint, endpoint, sizeof(oc_endpoint_t));
+ o->token_len = token_len;
+ memcpy(o->token, token, token_len);
+ o->last_mid = 0;
+ o->obs_counter = observe_counter;
+ o->resource = resource;
+ resource->num_observers++;
+ LOG("Adding observer (%u/%u) for /%s [0x%02X%02X]\n",
+ oc_list_length(observers_list) + 1, COAP_MAX_OBSERVERS, o->url,
+ o->token[0], o->token[1]);
+ oc_list_add(observers_list, o);
+ return dup;
}
- memcpy(o->url, uri, max);
- o->url[max] = 0;
- memcpy(&o->endpoint, endpoint, sizeof(oc_endpoint_t));
- o->token_len = token_len;
- memcpy(o->token, token, token_len);
- o->last_mid = 0;
- o->obs_counter = observe_counter;
- o->resource = resource;
- resource->num_observers++;
- LOG("Adding observer (%u/%u) for /%s [0x%02X%02X]\n",
- oc_list_length(observers_list) + 1, COAP_MAX_OBSERVERS, o->url,
- o->token[0], o->token[1]);
- oc_list_add(observers_list, o);
- return dup;
- }
- return -1;
+ return -1;
}
/*---------------------------------------------------------------------------*/
/*- Removal -----------------------------------------------------------------*/
@@ -90,97 +96,99 @@ add_observer(oc_resource_t *resource, oc_endpoint_t *endpoint,
void
coap_remove_observer(coap_observer_t *o)
{
- LOG("Removing observer for /%s [0x%02X%02X]\n", o->url, o->token[0],
+ LOG("Removing observer for /%s [0x%02X%02X]\n", o->url, o->token[0],
o->token[1]);
- oc_memb_free(&observers_memb, o);
- oc_list_remove(observers_list, o);
+ oc_list_remove(observers_list, o);
+ os_memblock_put(&coap_observers, o);
}
/*---------------------------------------------------------------------------*/
int
coap_remove_observer_by_client(oc_endpoint_t *endpoint)
{
- int removed = 0;
- coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list), *next;
+ int removed = 0;
+ coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list),
+ *next;
- LOG("Unregistering observers for client at: ");
- LOGipaddr(*endpoint);
+ LOG("Unregistering observers for client at: ");
+ LOGipaddr(*endpoint);
- while (obs) {
- next = obs->next;
- if (memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0) {
- obs->resource->num_observers--;
- coap_remove_observer(obs);
- removed++;
+ while (obs) {
+ next = obs->next;
+ if (memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0) {
+ obs->resource->num_observers--;
+ coap_remove_observer(obs);
+ removed++;
+ }
+ obs = next;
}
- obs = next;
- }
- LOG("Removed %d observers\n", removed);
- return removed;
+ LOG("Removed %d observers\n", removed);
+ return removed;
}
/*---------------------------------------------------------------------------*/
int
coap_remove_observer_by_token(oc_endpoint_t *endpoint, uint8_t *token,
size_t token_len)
{
- int removed = 0;
- coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list);
- LOG("Unregistering observers for request token 0x%02X%02X\n", token[0],
+ int removed = 0;
+ coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list);
+ LOG("Unregistering observers for request token 0x%02X%02X\n", token[0],
token[1]);
- while (obs) {
- if (memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0 &&
- obs->token_len == token_len &&
- memcmp(obs->token, token, token_len) == 0) {
- obs->resource->num_observers--;
- coap_remove_observer(obs);
- removed++;
- break;
+ while (obs) {
+ if (memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0 &&
+ obs->token_len == token_len &&
+ memcmp(obs->token, token, token_len) == 0) {
+ obs->resource->num_observers--;
+ coap_remove_observer(obs);
+ removed++;
+ break;
+ }
+ obs = obs->next;
}
- obs = obs->next;
- }
- LOG("Removed %d observers\n", removed);
- return removed;
+ LOG("Removed %d observers\n", removed);
+ return removed;
}
/*---------------------------------------------------------------------------*/
int
coap_remove_observer_by_uri(oc_endpoint_t *endpoint, const char *uri)
{
- LOG("Unregistering observers for resource uri /%s", uri);
- int removed = 0;
- coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list), *next;
+ LOG("Unregistering observers for resource uri /%s", uri);
+ int removed = 0;
+ coap_observer_t *obs = (coap_observer_t *)oc_list_head(observers_list),
+ *next;
- while (obs) {
- next = obs->next;
- if (((memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0)) &&
- (obs->url == uri || memcmp(obs->url, uri, strlen(obs->url)) == 0)) {
- obs->resource->num_observers--;
- coap_remove_observer(obs);
- removed++;
+ while (obs) {
+ next = obs->next;
+ if (((memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0)) &&
+ (obs->url == uri || memcmp(obs->url, uri, strlen(obs->url)) == 0)) {
+ obs->resource->num_observers--;
+ coap_remove_observer(obs);
+ removed++;
+ }
+ obs = next;
}
- obs = next;
- }
- LOG("Removed %d observers\n", removed);
- return removed;
+ LOG("Removed %d observers\n", removed);
+ return removed;
}
/*---------------------------------------------------------------------------*/
int
coap_remove_observer_by_mid(oc_endpoint_t *endpoint, uint16_t mid)
{
- int removed = 0;
- coap_observer_t *obs = NULL;
- LOG("Unregistering observers for request MID %u\n", mid);
+ int removed = 0;
+ coap_observer_t *obs = NULL;
+ LOG("Unregistering observers for request MID %u\n", mid);
- for (obs = (coap_observer_t *)oc_list_head(observers_list); obs != NULL;
- obs = obs->next) {
- if (memcmp(&obs->endpoint, endpoint, sizeof(*endpoint)) == 0 &&
- obs->last_mid == mid) {
- obs->resource->num_observers--;
- coap_remove_observer(obs);
- removed++;
- break;
+ for (obs = (coap_observer_t *)oc_list_head(observers_list); obs != NULL;
+ obs = obs->next) {
+ if (memcmp(&obs->endpoint, endpoint, sizeof(*endpoint)) == 0 &&
+ obs->last_mid == mid) {
+ obs->resource->num_observers--;
+ coap_remove_observer(obs);
+ removed++;
+ break;
+ }
}
- }
- LOG("Removed %d observers\n", removed);
- return removed;
+ LOG("Removed %d observers\n", removed);
+ return removed;
}
/*---------------------------------------------------------------------------*/
/*- Notification ------------------------------------------------------------*/
@@ -190,130 +198,139 @@ coap_notify_observers(oc_resource_t *resource,
oc_response_buffer_t *response_buf,
oc_endpoint_t *endpoint)
{
- int num_observers = 0;
- if (resource) {
- if (!resource->num_observers) {
- LOG("coap_notify_observers: no observers; returning\n");
- return 0;
+ int num_observers = 0;
+ if (resource) {
+ if (!resource->num_observers) {
+ LOG("coap_notify_observers: no observers; returning\n");
+ return 0;
+ }
+ num_observers = resource->num_observers;
}
- num_observers = resource->num_observers;
- }
- uint8_t buffer[COAP_MAX_BLOCK_SIZE];
- oc_request_t request = {};
- oc_response_t response = {};
- response.separate_response = 0;
- oc_response_buffer_t response_buffer;
- if (!response_buf && resource && (resource->properties & OC_PERIODIC)) {
- LOG("coap_notify_observers: Issue GET request to resource\n");
- /* performing GET on the resource */
- response_buffer.buffer = buffer;
- response_buffer.buffer_size = COAP_MAX_BLOCK_SIZE;
- response_buffer.block_offset = NULL;
- response.response_buffer = &response_buffer;
- request.resource = resource;
- request.response = &response;
- request.request_payload = NULL;
- oc_rep_new(buffer, COAP_MAX_BLOCK_SIZE);
- resource->get_handler(&request, resource->default_interface);
- response_buf = &response_buffer;
- if (response_buf->code == OC_IGNORE) {
- LOG("coap_notify_observers: Resource ignored request\n");
- return num_observers;
+ uint8_t buffer[COAP_MAX_BLOCK_SIZE];
+ oc_request_t request = {};
+ oc_response_t response = {};
+ response.separate_response = 0;
+ oc_response_buffer_t response_buffer;
+ if (!response_buf && resource && (resource->properties & OC_PERIODIC)) {
+ LOG("coap_notify_observers: Issue GET request to resource\n");
+ /* performing GET on the resource */
+ response_buffer.buffer = buffer;
+ response_buffer.buffer_size = COAP_MAX_BLOCK_SIZE;
+ response_buffer.block_offset = NULL;
+ response.response_buffer = &response_buffer;
+ request.resource = resource;
+ request.response = &response;
+ request.request_payload = NULL;
+ oc_rep_new(buffer, COAP_MAX_BLOCK_SIZE);
+ resource->get_handler(&request, resource->default_interface);
+ response_buf = &response_buffer;
+ if (response_buf->code == OC_IGNORE) {
+ LOG("coap_notify_observers: Resource ignored request\n");
+ return num_observers;
+ }
}
- }
- coap_observer_t *obs = NULL;
- /* iterate over observers */
- for (obs = (coap_observer_t *)oc_list_head(observers_list);
- obs && ((resource && obs->resource == resource) ||
- (endpoint &&
- memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0));
- obs = obs->next) {
- num_observers = obs->resource->num_observers;
- if (response.separate_response != NULL &&
- response_buf->code == oc_status_code(OC_STATUS_OK)) {
- coap_packet_t req[1];
- /*
- req->block1_num = 0;
- req->block1_size = 0;
- req->block2_num = 0;
- req->block2_size = 0;
- */
- coap_init_message(req, COAP_TYPE_NON, CONTENT_2_05, 0);
- memcpy(req->token, obs->token, obs->token_len);
- req->token_len = obs->token_len;
- LOG("Resource is SLOW; creating separate response\n");
- if (coap_separate_accept(req, response.separate_response, &obs->endpoint,
- 0) == 1)
- response.separate_response->active = 1;
- } else {
- LOG("coap_notify_observers: notifying observer\n");
- coap_transaction_t *transaction = NULL;
- if (response_buf && (transaction = coap_new_transaction(
- coap_get_mid(), &obs->endpoint))) {
- memcpy(transaction->message->data + COAP_MAX_HEADER_SIZE,
- response_buf->buffer, response_buf->response_length);
+ coap_observer_t *obs = NULL;
+ /* iterate over observers */
+ for (obs = (coap_observer_t *)oc_list_head(observers_list);
+ obs && ((resource && obs->resource == resource) ||
+ (endpoint &&
+ memcmp(&obs->endpoint, endpoint, sizeof(oc_endpoint_t)) == 0));
+ obs = obs->next) {
+ num_observers = obs->resource->num_observers;
+ if (response.separate_response != NULL &&
+ response_buf->code == oc_status_code(OC_STATUS_OK)) {
+ coap_packet_t req[1];
+ /*
+ req->block1_num = 0;
+ req->block1_size = 0;
+ req->block2_num = 0;
+ req->block2_size = 0;
+ */
+ coap_init_message(req, COAP_TYPE_NON, CONTENT_2_05, 0);
+ memcpy(req->token, obs->token, obs->token_len);
+ req->token_len = obs->token_len;
+ LOG("Resource is SLOW; creating separate response\n");
+ if (coap_separate_accept(req, response.separate_response,
+ &obs->endpoint, 0) == 1) {
+ response.separate_response->active = 1;
+ }
+ } else {
+ LOG("coap_notify_observers: notifying observer\n");
+ coap_transaction_t *transaction = NULL;
+ if (response_buf && (transaction = coap_new_transaction(
+ coap_get_mid(), &obs->endpoint))) {
+ memcpy(transaction->message->data + COAP_MAX_HEADER_SIZE,
+ response_buf->buffer, response_buf->response_length);
- /* update last MID for RST matching */
- obs->last_mid = transaction->mid;
+ /* update last MID for RST matching */
+ obs->last_mid = transaction->mid;
- /* prepare response */
- /* build notification */
- coap_packet_t notification
- [1]; /* this way the packet can be treated as pointer as usual */
- coap_init_message(notification, COAP_TYPE_NON, CONTENT_2_05, 0);
+ /* prepare response */
+ /* build notification */
+ coap_packet_t notification[1];
+ /* this way the packet can be treated as pointer as usual */
+ coap_init_message(notification, COAP_TYPE_NON, CONTENT_2_05, 0);
- notification->mid = transaction->mid;
- if (obs->obs_counter % COAP_OBSERVE_REFRESH_INTERVAL == 0) {
- LOG("coap_observe_notify: forcing CON notification to check for "
- "client liveness\n");
- notification->type = COAP_TYPE_CON;
- }
- coap_set_payload(notification, response_buf->buffer,
- response_buf->response_length);
- coap_set_status_code(notification, response_buf->code);
- if (notification->code < BAD_REQUEST_4_00 &&
- obs->resource->num_observers) {
- coap_set_header_observe(notification, (obs->obs_counter)++);
- observe_counter++;
- } else {
- coap_set_header_observe(notification, 1);
- }
- coap_set_token(notification, obs->token, obs->token_len);
+ notification->mid = transaction->mid;
+ if (obs->obs_counter % COAP_OBSERVE_REFRESH_INTERVAL == 0) {
+ LOG("coap_observe_notify: forcing CON notification to "
+ "check for client liveness\n");
+ notification->type = COAP_TYPE_CON;
+ }
+ coap_set_payload(notification, response_buf->buffer,
+ response_buf->response_length);
+ coap_set_status_code(notification, response_buf->code);
+ if (notification->code < BAD_REQUEST_4_00 &&
+ obs->resource->num_observers) {
+ coap_set_header_observe(notification, (obs->obs_counter)++);
+ observe_counter++;
+ } else {
+ coap_set_header_observe(notification, 1);
+ }
+ coap_set_token(notification, obs->token, obs->token_len);
- transaction->message->length =
- coap_serialize_message(notification, transaction->message->data);
+ transaction->message->length =
+ coap_serialize_message(notification,
+ transaction->message->data);
- coap_send_transaction(transaction);
- }
+ coap_send_transaction(transaction);
+ }
+ }
}
- }
- return num_observers;
+ return num_observers;
}
/*---------------------------------------------------------------------------*/
int
coap_observe_handler(void *request, void *response, oc_resource_t *resource,
oc_endpoint_t *endpoint)
{
- coap_packet_t *const coap_req = (coap_packet_t *)request;
- coap_packet_t *const coap_res = (coap_packet_t *)response;
- int dup = -1;
- if (coap_req->code == COAP_GET &&
+ coap_packet_t *const coap_req = (coap_packet_t *)request;
+ coap_packet_t *const coap_res = (coap_packet_t *)response;
+ int dup = -1;
+ if (coap_req->code == COAP_GET &&
coap_res->code < 128) { /* GET request and response without error code */
- if (IS_OPTION(coap_req, COAP_OPTION_OBSERVE)) {
- if (coap_req->observe == 0) {
- dup =
- add_observer(resource, endpoint, coap_req->token, coap_req->token_len,
- coap_req->uri_path, coap_req->uri_path_len);
- } else if (coap_req->observe == 1) {
- /* remove client if it is currently observe */
- dup = coap_remove_observer_by_token(endpoint, coap_req->token,
- coap_req->token_len);
- }
+ if (IS_OPTION(coap_req, COAP_OPTION_OBSERVE)) {
+ if (coap_req->observe == 0) {
+ dup =
+ add_observer(resource, endpoint, coap_req->token,
+ coap_req->token_len, coap_req->uri_path,
+ coap_req->uri_path_len);
+ } else if (coap_req->observe == 1) {
+ /* remove client if it is currently observe */
+ dup = coap_remove_observer_by_token(endpoint, coap_req->token,
+ coap_req->token_len);
+ }
+ }
}
- }
- return dup;
+ return dup;
}
/*---------------------------------------------------------------------------*/
+void
+coap_observe_init(void)
+{
+ os_mempool_init(&coap_observers, COAP_MAX_OBSERVERS,
+ sizeof(coap_observer_t), coap_observer_area, "coap_obs");
+}
#endif /* OC_SERVER */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/408077eb/net/oic/src/messaging/coap/observe.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.h b/net/oic/src/messaging/coap/observe.h
index b1eadc2..095f21e 100644
--- a/net/oic/src/messaging/coap/observe.h
+++ b/net/oic/src/messaging/coap/observe.h
@@ -80,6 +80,8 @@ int coap_notify_observers(oc_resource_t *resource,
int coap_observe_handler(void *request, void *response, oc_resource_t *resource,
oc_endpoint_t *endpoint);
+void coap_observe_init(void);
+
#ifdef __cplusplus
}
#endif
[06/27] incubator-mynewt-core git commit: oic;
redo oc_network_ev_process.
Posted by ma...@apache.org.
oic; redo oc_network_ev_process.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ea0326a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ea0326a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ea0326a6
Branch: refs/heads/develop
Commit: ea0326a65f97ad59fa6d1da92a9de2ae4b722f22
Parents: e31f405
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 17 17:57:40 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_network_events.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ea0326a6/net/oic/src/api/oc_network_events.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_network_events.c b/net/oic/src/api/oc_network_events.c
index a472d54..508bab9 100644
--- a/net/oic/src/api/oc_network_events.c
+++ b/net/oic/src/api/oc_network_events.c
@@ -35,10 +35,12 @@ oc_network_ev_process(struct os_event *ev)
struct oc_message_s *head;
oc_network_event_handler_mutex_lock();
- head = (struct oc_message_s *)oc_list_pop(network_events);
- while (head != NULL) {
- oc_recv_message(head);
+ while (1) {
head = oc_list_pop(network_events);
+ if (!head) {
+ break;
+ }
+ oc_recv_message(head);
}
oc_network_event_handler_mutex_unlock();
}
[07/27] incubator-mynewt-core git commit: oic;
remove unnecessary call to oc_main_loop_signal().
Posted by ma...@apache.org.
oic; remove unnecessary call to oc_main_loop_signal().
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/f5f9ef53
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f5f9ef53
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f5f9ef53
Branch: refs/heads/develop
Commit: f5f9ef53e044f8bdf297540a419ae6452763f04b
Parents: ea0326a
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 17 18:06:44 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_network_events.c | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5f9ef53/net/oic/src/api/oc_network_events.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_network_events.c b/net/oic/src/api/oc_network_events.c
index 508bab9..4ff00d2 100644
--- a/net/oic/src/api/oc_network_events.c
+++ b/net/oic/src/api/oc_network_events.c
@@ -53,5 +53,4 @@ oc_network_event(oc_message_t *message)
oc_network_event_handler_mutex_unlock();
os_eventq_put(oc_evq_get(), &oc_network_ev);
- oc_signal_main_loop();
}
[10/27] incubator-mynewt-core git commit: oic;
use os_events for trigger processing incoming/outgoing data.
Posted by ma...@apache.org.
oic; use os_events for trigger processing incoming/outgoing data.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/e31f4054
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e31f4054
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e31f4054
Branch: refs/heads/develop
Commit: e31f405466a445e8c38e5dcac40655cd58edcda6
Parents: 9f291c6
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Nov 17 17:52:48 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_buffer.c | 185 ++++++++++++++++++++++++---------------
net/oic/src/api/oc_ri.c | 3 -
2 files changed, 114 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e31f4054/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index f5bc70d..e800e08 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
*/
+#include <os/os_eventq.h>
#include "messaging/coap/engine.h"
#include "port/oc_signal_main_loop.h"
@@ -28,114 +29,156 @@
#include "oc_buffer.h"
#include "oc_events.h"
-OC_PROCESS(message_buffer_handler, "OC Message Buffer Handler");
+#include "port/mynewt/adaptor.h"
+
OC_MEMB(oc_buffers_s, oc_message_t, (MAX_NUM_CONCURRENT_REQUESTS * 2));
+static void oc_buffer_handler(struct os_event *);
+
+static struct oc_message_s *oc_buffer_inq;
+static struct oc_message_s *oc_buffer_outq;
+static struct os_event oc_buffer_ev = {
+ .ev_cb = oc_buffer_handler
+};
+
oc_message_t *
oc_allocate_message(void)
{
- oc_message_t *message = (oc_message_t *)oc_memb_alloc(&oc_buffers_s);
- if (message) {
- message->length = 0;
- message->next = 0;
- message->ref_count = 1;
- LOG("buffer: Allocated TX/RX buffer; num free: %d\n",
- oc_memb_numfree(&oc_buffers_s));
- } else
- LOG("buffer: No free TX/RX buffers!\n");
- return message;
+ oc_message_t *message = (oc_message_t *)oc_memb_alloc(&oc_buffers_s);
+
+ if (message) {
+ message->length = 0;
+ message->next = 0;
+ message->ref_count = 1;
+ LOG("buffer: Allocated TX/RX buffer; num free: %d\n",
+ oc_memb_numfree(&oc_buffers_s));
+ } else {
+ LOG("buffer: No free TX/RX buffers!\n");
+ }
+ return message;
}
void
oc_message_add_ref(oc_message_t *message)
{
- if (message)
- message->ref_count++;
+ if (message) {
+ message->ref_count++;
+ }
}
void
oc_message_unref(oc_message_t *message)
{
- if (message) {
- message->ref_count--;
- if (message->ref_count == 0) {
- oc_memb_free(&oc_buffers_s, message);
- LOG("buffer: freed TX/RX buffer; num free: %d\n",
- oc_memb_numfree(&oc_buffers_s));
+ if (message) {
+ message->ref_count--;
+ if (message->ref_count == 0) {
+ oc_memb_free(&oc_buffers_s, message);
+ LOG("buffer: freed TX/RX buffer; num free: %d\n",
+ oc_memb_numfree(&oc_buffers_s));
+ }
+ }
+}
+
+static void
+oc_queue_msg(struct oc_message_s **head, struct oc_message_s *msg)
+{
+ struct oc_message_s *tmp;
+
+ msg->next = NULL; /* oc_message_s has been oc_list once, clear next */
+ if (!*head) {
+ *head = msg;
+ } else {
+ for (tmp = *head; tmp->next; tmp = tmp->next);
+ tmp->next = msg;
}
- }
}
void
oc_recv_message(oc_message_t *message)
{
- oc_process_post(&message_buffer_handler, oc_events[INBOUND_NETWORK_EVENT],
- message);
- oc_signal_main_loop();
+ oc_queue_msg(&oc_buffer_inq, message);
+ os_eventq_put(oc_evq_get(), &oc_buffer_ev);
}
void
oc_send_message(oc_message_t *message)
{
- oc_process_post(&message_buffer_handler, oc_events[OUTBOUND_NETWORK_EVENT],
- message);
-
- oc_signal_main_loop();
+ oc_queue_msg(&oc_buffer_outq, message);
+ os_eventq_put(oc_evq_get(), &oc_buffer_ev);
}
-OC_PROCESS_THREAD(message_buffer_handler, ev, data)
+static void
+oc_buffer_tx(struct oc_message_s *message)
{
- OC_PROCESS_BEGIN();
- LOG("Started buffer handler process\n");
- while (1) {
- OC_PROCESS_YIELD();
-
- if (ev == oc_events[INBOUND_NETWORK_EVENT]) {
-#ifdef OC_SECURITY
- uint8_t b = (uint8_t)((oc_message_t *)data)->data[0];
- if (b > 19 && b < 64) {
- LOG("Inbound network event: encrypted request\n");
- oc_process_post(&oc_dtls_handler, oc_events[UDP_TO_DTLS_EVENT], data);
- } else {
- LOG("Inbound network event: decrypted request\n");
- coap_receive(data);
- oc_message_unref(data);
- }
-#else
- LOG("Inbound network event: decrypted request\n");
- coap_receive(data);
- oc_message_unref(data);
-#endif
- } else if (ev == oc_events[OUTBOUND_NETWORK_EVENT]) {
- oc_message_t *message = (oc_message_t *)data;
-
#ifdef OC_CLIENT
- if (message->endpoint.flags & MULTICAST) {
+ if (message->endpoint.flags & MULTICAST) {
LOG("Outbound network event: multicast request\n");
oc_send_multicast_message(message);
oc_message_unref(message);
- } else
+ } else {
#endif
#ifdef OC_SECURITY
if (message->endpoint.flags & SECURED) {
- LOG("Outbound network event: forwarding to DTLS\n");
-
- if (!oc_sec_dtls_connected(&message->endpoint)) {
- LOG("Posting INIT_DTLS_CONN_EVENT\n");
- oc_process_post(&oc_dtls_handler, oc_events[INIT_DTLS_CONN_EVENT],
- data);
- } else {
- LOG("Posting RI_TO_DTLS_EVENT\n");
- oc_process_post(&oc_dtls_handler, oc_events[RI_TO_DTLS_EVENT], data);
+ LOG("Outbound network event: forwarding to DTLS\n");
+
+ if (!oc_sec_dtls_connected(&message->endpoint)) {
+ LOG("Posting INIT_DTLS_CONN_EVENT\n");
+ oc_process_post(&oc_dtls_handler,
+ oc_events[INIT_DTLS_CONN_EVENT], msg);
+ } else {
+ LOG("Posting RI_TO_DTLS_EVENT\n");
+ oc_process_post(&oc_dtls_handler,
+ oc_events[RI_TO_DTLS_EVENT], msg);
+ }
+ } else
+#endif
+ {
+ LOG("Outbound network event: unicast message\n");
+ oc_send_buffer(message);
+ oc_message_unref(message);
}
- } else
+#ifdef OC_CLIENT
+ }
#endif
- {
- LOG("Outbound network event: unicast message\n");
- oc_send_buffer(message);
- oc_message_unref(message);
- }
+}
+
+static void
+oc_buffer_rx(struct oc_message_s *msg)
+{
+#ifdef OC_SECURITY
+ uint8_t b = (uint8_t)(msg->data[0];
+ if (b > 19 && b < 64) {
+ LOG("Inbound network event: encrypted request\n");
+ oc_process_post(&oc_dtls_handler, oc_events[UDP_TO_DTLS_EVENT], msg);
+ } else {
+ LOG("Inbound network event: decrypted request\n");
+ coap_receive(msg);
+ oc_message_unref(msg);
+ }
+#else
+ LOG("Inbound network event: decrypted request\n");
+ coap_receive(msg);
+ oc_message_unref(msg);
+#endif
+}
+
+static void
+oc_buffer_handler(struct os_event *ev)
+{
+ struct oc_message_s *msg;
+
+ while (oc_buffer_outq || oc_buffer_inq) {
+ msg = oc_buffer_outq;
+ if (msg) {
+ oc_buffer_outq = msg->next;
+ msg->next = NULL;
+ oc_buffer_tx(msg);
+ }
+ msg = oc_buffer_inq;
+ if (msg) {
+ oc_buffer_inq = msg->next;
+ msg->next = NULL;
+ oc_buffer_rx(msg);
+ }
}
- }
- OC_PROCESS_END();
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e31f4054/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 09d49f7..7903682 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -193,7 +193,6 @@ start_processes(void)
{
allocate_events();
coap_engine_init();
- oc_process_start(&message_buffer_handler, NULL);
#ifdef OC_SECURITY
oc_process_start(&oc_dtls_handler, NULL);
@@ -206,8 +205,6 @@ stop_processes(void)
#ifdef OC_SECURITY
oc_process_exit(&oc_dtls_handler);
#endif
-
- oc_process_exit(&message_buffer_handler);
}
#ifdef OC_SERVER
[17/27] incubator-mynewt-core git commit: oic;
use os_mempool for oc_buffer.
Posted by ma...@apache.org.
oic; use os_mempool for oc_buffer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/502f4101
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/502f4101
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/502f4101
Branch: refs/heads/develop
Commit: 502f410120be704235e044acc04eb9b7407c6cd8
Parents: bdc5c12
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 21 16:50:16 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_buffer.c | 26 ++++++++++++++++++--------
net/oic/src/api/oc_priv.h | 1 +
net/oic/src/api/oc_ri.c | 1 +
3 files changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/502f4101/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index 88c7731..b7201d7 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -13,13 +13,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
*/
+#include <stdint.h>
+#include <stdio.h>
+
#include <os/os_eventq.h>
+#include <os/os_mempool.h>
#include "messaging/coap/engine.h"
#include "port/oc_signal_main_loop.h"
-#include "util/oc_memb.h"
-#include <stdint.h>
-#include <stdio.h>
#ifdef OC_SECURITY
#include "security/oc_dtls.h"
@@ -30,7 +31,9 @@
#include "port/mynewt/adaptor.h"
-OC_MEMB(oc_buffers_s, oc_message_t, (MAX_NUM_CONCURRENT_REQUESTS * 2));
+static struct os_mempool oc_buffers;
+static uint8_t oc_buffer_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS * 2,
+ sizeof(oc_message_t))];
static void oc_buffer_handler(struct os_event *);
@@ -40,17 +43,24 @@ static struct os_event oc_buffer_ev = {
.ev_cb = oc_buffer_handler
};
+void
+oc_buffer_init(void)
+{
+ os_mempool_init(&oc_buffers, MAX_NUM_CONCURRENT_REQUESTS * 2,
+ sizeof(oc_message_t), oc_buffer_area, "oc_bufs");
+}
+
oc_message_t *
oc_allocate_message(void)
{
- oc_message_t *message = (oc_message_t *)oc_memb_alloc(&oc_buffers_s);
+ oc_message_t *message = (oc_message_t *)os_memblock_get(&oc_buffers);
if (message) {
message->length = 0;
message->next = 0;
message->ref_count = 1;
LOG("buffer: Allocated TX/RX buffer; num free: %d\n",
- oc_memb_numfree(&oc_buffers_s));
+ oc_buffers.mp_num_free);
} else {
LOG("buffer: No free TX/RX buffers!\n");
}
@@ -71,9 +81,9 @@ oc_message_unref(oc_message_t *message)
if (message) {
message->ref_count--;
if (message->ref_count == 0) {
- oc_memb_free(&oc_buffers_s, message);
+ os_memblock_put(&oc_buffers, message);
LOG("buffer: freed TX/RX buffer; num free: %d\n",
- oc_memb_numfree(&oc_buffers_s));
+ oc_buffers.mp_num_free);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/502f4101/net/oic/src/api/oc_priv.h
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_priv.h b/net/oic/src/api/oc_priv.h
index 3131d34..a521303 100644
--- a/net/oic/src/api/oc_priv.h
+++ b/net/oic/src/api/oc_priv.h
@@ -20,5 +20,6 @@
#define __OC_OC_PRIV_H__
void oc_rep_init(void);
+void oc_buffer_init(void);
#endif /* __OC_OC_PRIV_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/502f4101/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 326cdeb..8fd4f8d 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -226,6 +226,7 @@ oc_ri_init(void)
oc_list_init(client_cbs);
#endif
oc_rep_init();
+ oc_buffer_init();
start_processes();
oc_create_discovery_resource();
[26/27] incubator-mynewt-core git commit: oic;
use os_mempools for coap transactions.
Posted by ma...@apache.org.
oic; use os_mempools for coap transactions.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c0126fa4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c0126fa4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c0126fa4
Branch: refs/heads/develop
Commit: c0126fa4a7d3bcf5a64cd36ca9de2c2c77150579
Parents: 0f55f21
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 21 12:29:23 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
net/oic/src/messaging/coap/engine.c | 1 +
net/oic/src/messaging/coap/transactions.c | 74 +++++++++++++++-----------
net/oic/src/messaging/coap/transactions.h | 2 +
3 files changed, 46 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c0126fa4/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index fc7477c..cff4505 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -303,4 +303,5 @@ void
coap_engine_init(void)
{
coap_init_connection();
+ coap_transaction_init();
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c0126fa4/net/oic/src/messaging/coap/transactions.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.c b/net/oic/src/messaging/coap/transactions.c
index dc4ac6b..4c9df87 100644
--- a/net/oic/src/messaging/coap/transactions.c
+++ b/net/oic/src/messaging/coap/transactions.c
@@ -34,6 +34,7 @@
#include <stddef.h>
#include <os/os_callout.h>
+#include <os/os_mempool.h>
#include "transactions.h"
#include "observe.h"
@@ -51,40 +52,50 @@
#include "port/mynewt/adaptor.h"
-/*---------------------------------------------------------------------------*/
-OC_MEMB(transactions_memb, coap_transaction_t, COAP_MAX_OPEN_TRANSACTIONS);
+static struct os_mempool oc_transaction_memb;
+static uint8_t oc_transaction_area[OS_MEMPOOL_BYTES(COAP_MAX_OPEN_TRANSACTIONS,
+ sizeof(coap_transaction_t))];
+
OC_LIST(transactions_list);
static void coap_transaction_retrans(struct os_event *ev);
+void
+coap_transaction_init(void)
+{
+ os_mempool_init(&oc_transaction_memb, COAP_MAX_OPEN_TRANSACTIONS,
+ sizeof(coap_transaction_t), oc_transaction_area, "coap_tran");
+}
+
coap_transaction_t *
coap_new_transaction(uint16_t mid, oc_endpoint_t *endpoint)
{
- coap_transaction_t *t = oc_memb_alloc(&transactions_memb);
- if (t) {
- oc_message_t *message = oc_allocate_message();
- if (message) {
- LOG("Created new transaction %d %d\n", mid, (int) message->length);
- t->mid = mid;
- t->retrans_counter = 0;
-
- t->message = message;
-
- /* save client address */
- memcpy(&t->message->endpoint, endpoint, sizeof(oc_endpoint_t));
-
- os_callout_init(&t->retrans_timer, oc_evq_get(),
- coap_transaction_retrans, t);
- oc_list_add(
- transactions_list,
- t); /* list itself makes sure same element is not added twice */
- } else {
- oc_memb_free(&transactions_memb, t);
- t = NULL;
+ coap_transaction_t *t;
+
+ t = os_memblock_get(&oc_transaction_memb);
+ if (t) {
+ oc_message_t *message = oc_allocate_message();
+ if (message) {
+ LOG("Created new transaction %d %d\n", mid, (int) message->length);
+ t->mid = mid;
+ t->retrans_counter = 0;
+
+ t->message = message;
+
+ /* save client address */
+ memcpy(&t->message->endpoint, endpoint, sizeof(oc_endpoint_t));
+
+ os_callout_init(&t->retrans_timer, oc_evq_get(),
+ coap_transaction_retrans, t);
+ /* list itself makes sure same element is not added twice */
+ oc_list_add(transactions_list, t);
+ } else {
+ os_memblock_put(&oc_transaction_memb, t);
+ t = NULL;
+ }
}
- }
- return t;
+ return t;
}
/*---------------------------------------------------------------------------*/
@@ -156,15 +167,16 @@ coap_send_transaction(coap_transaction_t *t)
void
coap_clear_transaction(coap_transaction_t *t)
{
- if (t) {
- LOG("Freeing transaction %u: %p\n", t->mid, t);
+ if (t) {
+ LOG("Freeing transaction %u: %p\n", t->mid, t);
- os_callout_stop(&t->retrans_timer);
- oc_message_unref(t->message);
- oc_list_remove(transactions_list, t);
- oc_memb_free(&transactions_memb, t);
+ os_callout_stop(&t->retrans_timer);
+ oc_message_unref(t->message);
+ oc_list_remove(transactions_list, t);
+ os_memblock_put(&oc_transaction_memb, t);
}
}
+
coap_transaction_t *
coap_get_transaction_by_mid(uint16_t mid)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c0126fa4/net/oic/src/messaging/coap/transactions.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.h b/net/oic/src/messaging/coap/transactions.h
index d4b1946..266f2fd 100644
--- a/net/oic/src/messaging/coap/transactions.h
+++ b/net/oic/src/messaging/coap/transactions.h
@@ -76,6 +76,8 @@ coap_transaction_t *coap_get_transaction_by_mid(uint16_t mid);
void coap_check_transactions(void);
+void coap_transaction_init(void);
+
#ifdef __cplusplus
}
#endif
[04/27] incubator-mynewt-core git commit: oic;
remove oc_set_delayed_cb(), use os_callout instead.
Posted by ma...@apache.org.
oic; remove oc_set_delayed_cb(), use os_callout instead.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b34779ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b34779ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b34779ad
Branch: refs/heads/develop
Commit: b34779adc188221e65284e367d78d14e63f0f4a2
Parents: a400a8d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 15 16:09:58 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:47 2016 -0800
----------------------------------------------------------------------
apps/ocf_sample/src/main.c | 15 ++++----
apps/ocf_sample/syscfg.yml | 22 ++++++++++++
net/oic/include/oic/oc_client_state.h | 34 +++++++++---------
net/oic/include/oic/oc_ri.h | 14 --------
net/oic/src/api/oc_client_api.c | 6 ++--
net/oic/src/api/oc_ri.c | 56 ++++++++++--------------------
net/oic/src/api/oc_server_api.c | 15 ++------
7 files changed, 72 insertions(+), 90 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b34779ad/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index 2d7c93c..0e8ebe4 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -118,6 +118,7 @@ register_resources(void)
static char light_1[MAX_URI_LENGTH];
static oc_server_handle_t light_server;
static bool light_state = false;
+static struct os_callout callout;
static void
set_device_custom_property(void *data)
@@ -125,12 +126,11 @@ set_device_custom_property(void *data)
oc_set_custom_device_property(purpose, "operate mynewt-light");
}
-static oc_event_callback_retval_t
-stop_observe(void *data)
+static void
+stop_observe(struct os_event *ev)
{
PRINT("Stopping OBSERVE\n");
oc_stop_observe(light_1, &light_server);
- return DONE;
}
static void
@@ -191,7 +191,7 @@ discovery(const char *di, const char *uri, oc_string_array_t types,
oc_do_observe(light_1, &light_server, NULL, &observe_light,
LOW_QOS);
- oc_set_delayed_callback(NULL, &stop_observe, 30);
+ os_callout_reset(&callout, 30 * OS_TICKS_PER_SEC);
return OC_STOP_DISCOVERY;
}
}
@@ -243,6 +243,9 @@ ocf_main_task_handler(void *arg)
{
os_sem_init(&ocf_main_loop_sem, 1);
+#if (MYNEWT_VAL(OC_CLIENT) == 1)
+ os_callout_init(&callout, &ocf_aux_evq, stop_observe, NULL);
+#endif
while (1) {
uint32_t ticks;
oc_clock_time_t next_event;
@@ -276,14 +279,14 @@ ocf_init_tasks(void)
OCF_MAIN_TASK_STACK_SIZE);
assert(rc == 0);
- oc_main_init(&ocf_handler);
-
/* Initialize eventq */
os_eventq_init(&ocf_aux_evq);
/* Set the default eventq for packages that lack a dedicated task. */
os_eventq_dflt_set(&ocf_aux_evq);
+ oc_main_init(&ocf_handler);
+
rc = os_task_init(&ocf_aux_task, "ocf_aux", ocf_aux_task_handler, NULL,
OCF_AUX_TASK_PRIO, OS_WAIT_FOREVER, ocf_aux_stack,
OCF_AUX_TASK_STACK_SIZE);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b34779ad/apps/ocf_sample/syscfg.yml
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/syscfg.yml b/apps/ocf_sample/syscfg.yml
new file mode 100644
index 0000000..0943080
--- /dev/null
+++ b/apps/ocf_sample/syscfg.yml
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+syscfg.vals:
+ SHELL_TASK: 1
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b34779ad/net/oic/include/oic/oc_client_state.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_client_state.h b/net/oic/include/oic/oc_client_state.h
index 43c25ac..e844276 100644
--- a/net/oic/include/oic/oc_client_state.h
+++ b/net/oic/include/oic/oc_client_state.h
@@ -51,23 +51,23 @@ typedef oc_discovery_flags_t(oc_discovery_cb_t)(const char *, const char *,
typedef void (*oc_response_handler_t)(oc_client_response_t *);
-typedef struct oc_client_cb_s
-{
- struct oc_client_cb_s *next;
- oc_string_t uri;
- uint8_t token[COAP_TOKEN_LEN];
- uint8_t token_len;
- uint16_t mid;
-
- oc_server_handle_t server;
-
- void *handler;
-
- bool discovery;
- int32_t observe_seq;
- oc_clock_time_t timestamp;
- oc_qos_t qos;
- oc_method_t method;
+typedef struct oc_client_cb_s {
+ struct oc_client_cb_s *next;
+ struct os_callout callout;
+ oc_string_t uri;
+ uint8_t token[COAP_TOKEN_LEN];
+ uint8_t token_len;
+ uint16_t mid;
+
+ oc_server_handle_t server;
+
+ void *handler;
+
+ bool discovery;
+ int32_t observe_seq;
+ oc_clock_time_t timestamp;
+ oc_qos_t qos;
+ oc_method_t method;
} oc_client_cb_t;
bool oc_ri_invoke_client_cb(void *response, oc_endpoint_t *endpoint);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b34779ad/net/oic/include/oic/oc_ri.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_ri.h b/net/oic/include/oic/oc_ri.h
index 693e0c8..c49b7be 100644
--- a/net/oic/include/oic/oc_ri.h
+++ b/net/oic/include/oic/oc_ri.h
@@ -144,20 +144,6 @@ void oc_ri_init(void);
void oc_ri_shutdown(void);
-void oc_ri_add_timed_event_callback_ticks(void *cb_data,
- oc_trigger_t event_callback,
- oc_clock_time_t ticks);
-
-#define oc_ri_add_timed_event_callback_seconds(cb_data, event_callback, \
- seconds) \
- do { \
- oc_ri_add_timed_event_callback_ticks( \
- cb_data, event_callback, (oc_clock_time_t)(seconds * OC_CLOCK_SECOND)); \
- } while (0)
-
-void oc_ri_remove_timed_event_callback(void *cb_data,
- oc_trigger_t event_callback);
-
int oc_status_code(oc_status_t key);
oc_resource_t *oc_ri_get_app_resource_by_uri(const char *uri);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b34779ad/net/oic/src/api/oc_client_api.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_client_api.c b/net/oic/src/api/oc_client_api.c
index bd73da3..8122f17 100644
--- a/net/oic/src/api/oc_client_api.c
+++ b/net/oic/src/api/oc_client_api.c
@@ -92,10 +92,8 @@ prepare_coap_request(oc_client_cb_t *cb, oc_string_t *query)
coap_set_header_uri_query(request, oc_string(*query));
if (cb->observe_seq == -1 && cb->qos == LOW_QOS) {
- extern oc_event_callback_retval_t oc_ri_remove_client_cb(void *data);
-
- oc_set_delayed_callback(cb, &oc_ri_remove_client_cb,
- OC_CLIENT_CB_TIMEOUT_SECS);
+ os_callout_reset(&cb->callout,
+ OC_CLIENT_CB_TIMEOUT_SECS * OS_TICKS_PER_SEC);
}
return true;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b34779ad/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 64dccb2..4d8c597 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -18,6 +18,8 @@
#include <stddef.h>
#include <strings.h>
+#include <os/os_callout.h>
+
#include "util/oc_etimer.h"
#include "util/oc_list.h"
#include "util/oc_memb.h"
@@ -28,6 +30,7 @@
#include "messaging/coap/oc_coap.h"
#include "port/oc_random.h"
+#include "port/mynewt/adaptor.h"
#include "oc_buffer.h"
#include "oc_core_res.h"
@@ -297,39 +300,6 @@ oc_ri_add_resource(oc_resource_t *resource)
}
#endif /* OC_SERVER */
-void
-oc_ri_remove_timed_event_callback(void *cb_data, oc_trigger_t event_callback)
-{
- oc_event_callback_t *event_cb =
- (oc_event_callback_t *)oc_list_head(timed_callbacks);
-
- while (event_cb != NULL) {
- if (event_cb->data == cb_data && event_cb->callback == event_callback) {
- oc_list_remove(timed_callbacks, event_cb);
- oc_memb_free(&event_callbacks_s, event_cb);
- break;
- }
- event_cb = event_cb->next;
- }
-}
-
-void
-oc_ri_add_timed_event_callback_ticks(void *cb_data, oc_trigger_t event_callback,
- oc_clock_time_t ticks)
-{
- oc_event_callback_t *event_cb =
- (oc_event_callback_t *)oc_memb_alloc(&event_callbacks_s);
-
- if (event_cb) {
- event_cb->data = cb_data;
- event_cb->callback = event_callback;
- OC_PROCESS_CONTEXT_BEGIN(&timed_callback_events);
- oc_etimer_set(&event_cb->timer, ticks);
- OC_PROCESS_CONTEXT_END(&timed_callback_events);
- oc_list_add(timed_callbacks, event_cb);
- }
-}
-
static void
poll_event_callback_timers(oc_list_t list, struct oc_memb *cb_pool)
{
@@ -806,9 +776,10 @@ oc_ri_invoke_coap_entity_handler(void *request, void *response, uint8_t *buffer,
static void
free_client_cb(oc_client_cb_t *cb)
{
- oc_free_string(&cb->uri);
- oc_list_remove(client_cbs, cb);
- oc_memb_free(&client_cbs_s, cb);
+ os_callout_stop(&cb->callout);
+ oc_free_string(&cb->uri);
+ oc_list_remove(client_cbs, cb);
+ oc_memb_free(&client_cbs_s, cb);
}
void
@@ -935,7 +906,6 @@ oc_ri_invoke_client_cb(void *response, oc_endpoint_t *endpoint)
for the entirety of OC_CLIENT_CB_TIMEOUT_SECS
*/
if (client_response.observe_option == -1 && !separate && !cb->discovery) {
- oc_ri_remove_timed_event_callback(cb, &oc_ri_remove_client_cb);
free_client_cb(cb);
} else
cb->observe_seq = client_response.observe_option;
@@ -968,6 +938,16 @@ oc_ri_get_client_cb(const char *uri, oc_server_handle_t *server,
return cb;
}
+static void
+oc_ri_remove_cb(struct os_event *ev)
+{
+ struct oc_client_cb_s *cb;
+
+ cb = ev->ev_arg;
+
+ oc_ri_remove_client_cb(cb);
+}
+
oc_client_cb_t *
oc_ri_alloc_client_cb(const char *uri, oc_server_handle_t *server,
oc_method_t method, void *handler, oc_qos_t qos)
@@ -994,6 +974,8 @@ oc_ri_alloc_client_cb(const char *uri, oc_server_handle_t *server,
cb->observe_seq = -1;
memcpy(&cb->server, server, sizeof(oc_server_handle_t));
+ os_callout_init(&cb->callout, oc_evq_get(), oc_ri_remove_cb, cb);
+
oc_list_add(client_cbs, cb);
return cb;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b34779ad/net/oic/src/api/oc_server_api.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_server_api.c b/net/oic/src/api/oc_server_api.c
index 054a91c..48fb680 100644
--- a/net/oic/src/api/oc_server_api.c
+++ b/net/oic/src/api/oc_server_api.c
@@ -13,6 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
*/
+#include <stddef.h>
+
+#include <os/os_callout.h>
#include "messaging/coap/engine.h"
#include "messaging/coap/oc_coap.h"
@@ -79,18 +82,6 @@ oc_ignore_request(oc_request_t *request)
}
void
-oc_set_delayed_callback(void *cb_data, oc_trigger_t callback, uint16_t seconds)
-{
- oc_ri_add_timed_event_callback_seconds(cb_data, callback, seconds);
-}
-
-void
-oc_remove_delayed_callback(void *cb_data, oc_trigger_t callback)
-{
- oc_ri_remove_timed_event_callback(cb_data, callback);
-}
-
-void
oc_process_baseline_interface(oc_resource_t *resource)
{
oc_rep_set_string_array(root, rt, resource->types);
[08/27] incubator-mynewt-core git commit: oic coap;
use os_callout as timer instead of oc_etimer.
Posted by ma...@apache.org.
oic coap; use os_callout as timer instead of oc_etimer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/cf8db8fd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/cf8db8fd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/cf8db8fd
Branch: refs/heads/develop
Commit: cf8db8fd304d8631c162fc6eda93af4068a5fa58
Parents: 7b47dc1
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 16 15:11:49 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800
----------------------------------------------------------------------
net/oic/src/messaging/coap/engine.c | 9 -----
net/oic/src/messaging/coap/engine.h | 2 -
net/oic/src/messaging/coap/transactions.c | 55 +++++++++++---------------
net/oic/src/messaging/coap/transactions.h | 14 +++----
4 files changed, 29 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf8db8fd/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index 0eecabf..9d8efaa 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -302,17 +302,10 @@ coap_receive(oc_message_t *msg)
return erbium_status_code;
}
/*---------------------------------------------------------------------------*/
-void
-coap_init_engine(void)
-{
- coap_register_as_transaction_handler();
-}
-/*---------------------------------------------------------------------------*/
OC_PROCESS_THREAD(coap_engine, ev, data)
{
OC_PROCESS_BEGIN();
- coap_register_as_transaction_handler();
coap_init_connection();
while (1) {
@@ -322,8 +315,6 @@ OC_PROCESS_THREAD(coap_engine, ev, data)
coap_receive(data);
oc_message_unref(data);
- } else if (ev == OC_PROCESS_EVENT_TIMER) {
- coap_check_transactions();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf8db8fd/net/oic/src/messaging/coap/engine.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.h b/net/oic/src/messaging/coap/engine.h
index 781f4f2..067c1d7 100644
--- a/net/oic/src/messaging/coap/engine.h
+++ b/net/oic/src/messaging/coap/engine.h
@@ -45,8 +45,6 @@ extern "C" {
OC_PROCESS_NAME(coap_engine);
-void coap_init_engine(void);
-/*---------------------------------------------------------------------------*/
int coap_receive(oc_message_t *message);
#ifdef __cplusplus
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf8db8fd/net/oic/src/messaging/coap/transactions.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.c b/net/oic/src/messaging/coap/transactions.c
index 8feaa7c..dc4ac6b 100644
--- a/net/oic/src/messaging/coap/transactions.c
+++ b/net/oic/src/messaging/coap/transactions.c
@@ -30,13 +30,16 @@
*
* This file is part of the Contiki operating system.
*/
+#include <string.h>
+#include <stddef.h>
+
+#include <os/os_callout.h>
#include "transactions.h"
#include "observe.h"
#include "oc_buffer.h"
#include "util/oc_list.h"
#include "util/oc_memb.h"
-#include <string.h>
#ifdef OC_CLIENT
#include "oc_client_state.h"
@@ -46,20 +49,13 @@
#include "security/oc_dtls.h"
#endif
+#include "port/mynewt/adaptor.h"
+
/*---------------------------------------------------------------------------*/
OC_MEMB(transactions_memb, coap_transaction_t, COAP_MAX_OPEN_TRANSACTIONS);
OC_LIST(transactions_list);
-static struct oc_process *transaction_handler_process = NULL;
-
-/*---------------------------------------------------------------------------*/
-/*- Internal API ------------------------------------------------------------*/
-/*---------------------------------------------------------------------------*/
-void
-coap_register_as_transaction_handler()
-{
- transaction_handler_process = OC_PROCESS_CURRENT();
-}
+static void coap_transaction_retrans(struct os_event *ev);
coap_transaction_t *
coap_new_transaction(uint16_t mid, oc_endpoint_t *endpoint)
@@ -77,6 +73,8 @@ coap_new_transaction(uint16_t mid, oc_endpoint_t *endpoint)
/* save client address */
memcpy(&t->message->endpoint, endpoint, sizeof(oc_endpoint_t));
+ os_callout_init(&t->retrans_timer, oc_evq_get(),
+ coap_transaction_retrans, t);
oc_list_add(
transactions_list,
t); /* list itself makes sure same element is not added twice */
@@ -108,19 +106,17 @@ coap_send_transaction(coap_transaction_t *t)
LOG("Keeping transaction %u\n", t->mid);
if (t->retrans_counter == 0) {
- t->retrans_timer.timer.interval =
+ t->retrans_tmo =
COAP_RESPONSE_TIMEOUT_TICKS +
(oc_random_rand() %
(oc_clock_time_t)COAP_RESPONSE_TIMEOUT_BACKOFF_MASK);
- LOG("Initial interval " OC_CLK_FMT "\n", t->retrans_timer.timer.interval);
+ LOG("Initial interval " OC_CLK_FMT "\n", t->retrans_tmo);
} else {
- t->retrans_timer.timer.interval <<= 1; /* double */
- LOG("Doubled " OC_CLK_FMT "\n", t->retrans_timer.timer.interval);
+ t->retrans_tmo <<= 1; /* double */
+ LOG("Doubled " OC_CLK_FMT "\n", t->retrans_tmo);
}
- OC_PROCESS_CONTEXT_BEGIN(transaction_handler_process);
- oc_etimer_restart(&t->retrans_timer); /* interval updated above */
- OC_PROCESS_CONTEXT_END(transaction_handler_process);
+ os_callout_reset(&t->retrans_timer, t->retrans_tmo);
coap_send_message(t->message);
@@ -163,7 +159,7 @@ coap_clear_transaction(coap_transaction_t *t)
if (t) {
LOG("Freeing transaction %u: %p\n", t->mid, t);
- oc_etimer_stop(&t->retrans_timer);
+ os_callout_stop(&t->retrans_timer);
oc_message_unref(t->message);
oc_list_remove(transactions_list, t);
oc_memb_free(&transactions_memb, t);
@@ -184,19 +180,12 @@ coap_get_transaction_by_mid(uint16_t mid)
return NULL;
}
-/*---------------------------------------------------------------------------*/
-void
-coap_check_transactions()
+static void
+coap_transaction_retrans(struct os_event *ev)
{
- coap_transaction_t *t = NULL;
-
- for (t = (coap_transaction_t *)oc_list_head(transactions_list); t;
- t = t->next) {
- if (oc_etimer_expired(&t->retrans_timer)) {
- ++(t->retrans_counter);
- LOG("Retransmitting %u (%u)\n", t->mid, t->retrans_counter);
- coap_send_transaction(t);
- }
- }
+ coap_transaction_t *t = ev->ev_arg;
+ ++(t->retrans_counter);
+ LOG("Retransmitting %u (%u)\n", t->mid, t->retrans_counter);
+ coap_send_transaction(t);
}
-/*---------------------------------------------------------------------------*/
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf8db8fd/net/oic/src/messaging/coap/transactions.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.h b/net/oic/src/messaging/coap/transactions.h
index 1bb6c33..d4b1946 100644
--- a/net/oic/src/messaging/coap/transactions.h
+++ b/net/oic/src/messaging/coap/transactions.h
@@ -35,7 +35,6 @@
#define TRANSACTIONS_H
#include "coap.h"
-#include "../../util/oc_etimer.h"
#ifdef __cplusplus
extern "C" {
@@ -47,11 +46,11 @@ extern "C" {
* retransmission time between COAP_RESPONSE_TIMEOUT and
* COAP_RESPONSE_TIMEOUT*COAP_RESPONSE_RANDOM_FACTOR.
*/
-#define COAP_RESPONSE_TIMEOUT_TICKS (OC_CLOCK_SECOND * COAP_RESPONSE_TIMEOUT)
-#define COAP_RESPONSE_TIMEOUT_BACKOFF_MASK \
- (long)((OC_CLOCK_SECOND * COAP_RESPONSE_TIMEOUT * \
- ((float)COAP_RESPONSE_RANDOM_FACTOR - 1.0)) + \
- 0.5) + \
+#define COAP_RESPONSE_TIMEOUT_TICKS (OS_TICKS_PER_SEC * COAP_RESPONSE_TIMEOUT)
+#define COAP_RESPONSE_TIMEOUT_BACKOFF_MASK \
+ (long)((OS_TICKS_PER_SEC * COAP_RESPONSE_TIMEOUT * \
+ ((float)COAP_RESPONSE_RANDOM_FACTOR - 1.0)) + \
+ 0.5) + \
1
/* container for transactions with message buffer and retransmission info */
@@ -60,8 +59,9 @@ typedef struct coap_transaction
struct coap_transaction *next; /* for LIST */
uint16_t mid;
- struct oc_etimer retrans_timer;
uint8_t retrans_counter;
+ uint32_t retrans_tmo;
+ struct os_callout retrans_timer;
oc_message_t *message;
} coap_transaction_t;
[27/27] incubator-mynewt-core git commit: oic;
no need for oc_memb anymore.
Posted by ma...@apache.org.
oic; no need for oc_memb anymore.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7131b026
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7131b026
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7131b026
Branch: refs/heads/develop
Commit: 7131b026faa8806075118abe33d39ae274b669d3
Parents: a2c3b0d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 21 17:15:08 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:50 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_rep.c | 1 -
net/oic/src/messaging/coap/observe.c | 1 -
net/oic/src/messaging/coap/transactions.c | 1 -
net/oic/src/util/oc_memb.c | 111 --------------------
net/oic/src/util/oc_memb.h | 135 -------------------------
5 files changed, 249 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7131b026/net/oic/src/api/oc_rep.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_rep.c b/net/oic/src/api/oc_rep.c
index e1b47bf..3465775 100644
--- a/net/oic/src/api/oc_rep.c
+++ b/net/oic/src/api/oc_rep.c
@@ -21,7 +21,6 @@
#include "config.h"
#include "port/oc_assert.h"
#include "port/oc_log.h"
-#include "util/oc_memb.h"
#include "api/oc_priv.h"
#include <tinycbor/cbor_buf_writer.h>
#include <tinycbor/cbor_buf_reader.h>
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7131b026/net/oic/src/messaging/coap/observe.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.c b/net/oic/src/messaging/coap/observe.c
index c16823a..c67c0a7 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -41,7 +41,6 @@
#include <os/os_mempool.h>
#include "observe.h"
-#include "util/oc_memb.h"
#include "oc_coap.h"
#include "oc_rep.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7131b026/net/oic/src/messaging/coap/transactions.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/transactions.c b/net/oic/src/messaging/coap/transactions.c
index 4c9df87..c05ba63 100644
--- a/net/oic/src/messaging/coap/transactions.c
+++ b/net/oic/src/messaging/coap/transactions.c
@@ -40,7 +40,6 @@
#include "observe.h"
#include "oc_buffer.h"
#include "util/oc_list.h"
-#include "util/oc_memb.h"
#ifdef OC_CLIENT
#include "oc_client_state.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7131b026/net/oic/src/util/oc_memb.c
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_memb.c b/net/oic/src/util/oc_memb.c
deleted file mode 100644
index 31909a9..0000000
--- a/net/oic/src/util/oc_memb.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-#include "oc_memb.h"
-#include <string.h>
-
-/*---------------------------------------------------------------------------*/
-void
-oc_memb_init(struct oc_memb *m)
-{
- memset(m->count, 0, m->num);
- memset(m->mem, 0, (unsigned)m->size * (unsigned)m->num);
-}
-/*---------------------------------------------------------------------------*/
-void *
-oc_memb_alloc(struct oc_memb *m)
-{
- int i;
-
- for (i = 0; i < m->num; ++i) {
- if (m->count[i] == 0) {
- /* If this block was unused, we increase the reference count to
- indicate that it now is used and return a pointer to the
- memory block. */
- ++(m->count[i]);
- return (void *)((char *)m->mem + (i * m->size));
- }
- }
-
- /* No free block was found, so we return NULL to indicate failure to
- allocate block. */
- return NULL;
-}
-/*---------------------------------------------------------------------------*/
-char
-oc_memb_free(struct oc_memb *m, void *ptr)
-{
- int i;
- char *ptr2;
-
- /* Walk through the list of blocks and try to find the block to
- which the pointer "ptr" points to. */
- ptr2 = (char *)m->mem;
- for (i = 0; i < m->num; ++i) {
-
- if (ptr2 == (char *)ptr) {
- /* We've found to block to which "ptr" points so we decrease the
- reference count and return the new value of it. */
- if (m->count[i] > 0) {
- /* Make sure that we don't deallocate free memory. */
- --(m->count[i]);
- }
- return m->count[i];
- }
- ptr2 += m->size;
- }
- return -1;
-}
-/*---------------------------------------------------------------------------*/
-int
-oc_memb_inmemb(struct oc_memb *m, void *ptr)
-{
- return (char *)ptr >= (char *)m->mem &&
- (char *)ptr < (char *)m->mem + (m->num * m->size);
-}
-/*---------------------------------------------------------------------------*/
-int
-oc_memb_numfree(struct oc_memb *m)
-{
- int i;
- int num_free = 0;
-
- for (i = 0; i < m->num; ++i) {
- if (m->count[i] == 0) {
- ++num_free;
- }
- }
-
- return num_free;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7131b026/net/oic/src/util/oc_memb.h
----------------------------------------------------------------------
diff --git a/net/oic/src/util/oc_memb.h b/net/oic/src/util/oc_memb.h
deleted file mode 100644
index 37ecca6..0000000
--- a/net/oic/src/util/oc_memb.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) 2004, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Adam Dunkels <ad...@sics.se>
- *
- */
-
-/**
- * \defgroup memb Memory block management functions
- *
- * The memory block allocation routines provide a simple yet powerful
- * set of functions for managing a set of memory blocks of fixed
- * size. A set of memory blocks is statically declared with the
- * OC_MEMB() macro. Memory blocks are allocated from the declared
- * memory by the oc_memb_alloc() function, and are deallocated with the
- * oc_memb_free() function.
- *
- */
-
-#ifndef OC_MEMB_H
-#define OC_MEMB_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define CC_CONCAT2(s1, s2) s1##s2
-/**
- * A C preprocessing macro for concatenating two preprocessor tokens.
- *
- * We need use two macros (CC_CONCAT and CC_CONCAT2) in order to allow
- * concatenation of two \#defined macros.
- */
-#define CC_CONCAT(s1, s2) CC_CONCAT2(s1, s2)
-
-/**
- * Declare a memory block.
- *
- * This macro is used to statically declare a block of memory that can
- * be used by the block allocation functions. The macro statically
- * declares a C array with a size that matches the specified number of
- * blocks and their individual sizes.
- *
- * Example:
- \code
- MEMB(connections, struct connection, 16);
- \endcode
- *
- * \param name The name of the memory block (later used with
- * oc_memb_init(), oc_memb_alloc() and oc_memb_free()).
- *
- * \param structure The name of the struct that the memory block holds
- *
- * \param num The total number of memory chunks in the block.
- *
- */
-#define OC_MEMB(name, structure, num) \
- static char CC_CONCAT(name, _memb_count)[num]; \
- static structure CC_CONCAT(name, _memb_mem)[num]; \
- static struct oc_memb name = { sizeof(structure), num, \
- CC_CONCAT(name, _memb_count), \
- (void *)CC_CONCAT(name, _memb_mem) }
-
-struct oc_memb
-{
- unsigned short size;
- unsigned short num;
- char *count;
- void *mem;
-};
-
-/**
- * Initialize a memory block that was declared with MEMB().
- *
- * \param m A memory block previously declared with MEMB().
- */
-void oc_memb_init(struct oc_memb *m);
-
-/**
- * Allocate a memory block from a block of memory declared with MEMB().
- *
- * \param m A memory block previously declared with MEMB().
- */
-void *oc_memb_alloc(struct oc_memb *m);
-
-/**
- * Deallocate a memory block from a memory block previously declared
- * with MEMB().
- *
- * \param m m A memory block previously declared with MEMB().
- *
- * \param ptr A pointer to the memory block that is to be deallocated.
- *
- * \return The new reference count for the memory block (should be 0
- * if successfully deallocated) or -1 if the pointer "ptr" did not
- * point to a legal memory block.
- */
-char oc_memb_free(struct oc_memb *m, void *ptr);
-
-int oc_memb_inmemb(struct oc_memb *m, void *ptr);
-
-int oc_memb_numfree(struct oc_memb *m);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OC_MEMB_H */
[02/27] incubator-mynewt-core git commit: oicmgr;
move call to oc_main_init() to take place once OS has started.
Posted by ma...@apache.org.
oicmgr; move call to oc_main_init() to take place once OS has started.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3ff24288
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3ff24288
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3ff24288
Branch: refs/heads/develop
Commit: 3ff24288ec96f33d12085ff59d9784e65790872d
Parents: 297c35d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 15 20:26:31 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:47 2016 -0800
----------------------------------------------------------------------
mgmt/oicmgr/src/oicmgr.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3ff24288/mgmt/oicmgr/src/oicmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/oicmgr/src/oicmgr.c b/mgmt/oicmgr/src/oicmgr.c
index 32562d9..0e631ef 100644
--- a/mgmt/oicmgr/src/oicmgr.c
+++ b/mgmt/oicmgr/src/oicmgr.c
@@ -247,6 +247,8 @@ static void
omgr_event_start(struct os_event *ev)
{
struct omgr_state *o = &omgr_state;
+
+ oc_main_init((oc_handler_t *)&omgr_oc_handler);
os_eventq_ensure(&o->os_evq, NULL);
o->os_event.ev_cb = omgr_process_oc_event;
os_callout_init(&o->os_oc_timer, mgmt_evq_get(), omgr_process_oc_event,
@@ -263,8 +265,6 @@ oicmgr_init(void)
goto err;
}
- oc_main_init((oc_handler_t *)&omgr_oc_handler);
-
return (0);
err:
return (rc);
[20/27] incubator-mynewt-core git commit: oic;
change oc_rep_objects pool to be os_mempool.
Posted by ma...@apache.org.
oic; change oc_rep_objects pool to be os_mempool.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3320d476
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3320d476
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3320d476
Branch: refs/heads/develop
Commit: 3320d47682c873d090cd9b49eac23c19f09673c7
Parents: c0126fa
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 21 14:02:38 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_priv.h | 24 +++++++++
net/oic/src/api/oc_rep.c | 110 +++++++++++++++++++++++------------------
net/oic/src/api/oc_ri.c | 2 +
3 files changed, 89 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3320d476/net/oic/src/api/oc_priv.h
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_priv.h b/net/oic/src/api/oc_priv.h
new file mode 100644
index 0000000..3131d34
--- /dev/null
+++ b/net/oic/src/api/oc_priv.h
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+#ifndef __OC_OC_PRIV_H__
+#define __OC_OC_PRIV_H__
+
+void oc_rep_init(void);
+
+#endif /* __OC_OC_PRIV_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3320d476/net/oic/src/api/oc_rep.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_rep.c b/net/oic/src/api/oc_rep.c
index 0bff401..e1b47bf 100644
--- a/net/oic/src/api/oc_rep.c
+++ b/net/oic/src/api/oc_rep.c
@@ -14,15 +14,22 @@
// limitations under the License.
*/
+#include <stddef.h>
+#include <os/os_mempool.h>
+
#include "oc_rep.h"
#include "config.h"
#include "port/oc_assert.h"
#include "port/oc_log.h"
#include "util/oc_memb.h"
+#include "api/oc_priv.h"
#include <tinycbor/cbor_buf_writer.h>
#include <tinycbor/cbor_buf_reader.h>
-OC_MEMB(rep_objects, oc_rep_t, EST_NUM_REP_OBJECTS);
+static struct os_mempool oc_rep_objects;
+static uint8_t oc_rep_objects_area[OS_MEMPOOL_BYTES(EST_NUM_REP_OBJECTS,
+ sizeof(oc_rep_t))];
+
static const CborEncoder g_empty;
static uint8_t *g_buf;
CborEncoder g_encoder, root_map, links_array;
@@ -32,79 +39,81 @@ struct CborBufWriter g_buf_writer;
void
oc_rep_new(uint8_t *out_payload, int size)
{
- g_err = CborNoError;
- g_buf = out_payload;
- cbor_buf_writer_init(&g_buf_writer, out_payload, size);
- cbor_encoder_init(&g_encoder, &g_buf_writer.enc, 0);
+ g_err = CborNoError;
+ g_buf = out_payload;
+ cbor_buf_writer_init(&g_buf_writer, out_payload, size);
+ cbor_encoder_init(&g_encoder, &g_buf_writer.enc, 0);
}
int
oc_rep_finalize(void)
{
- int size = cbor_buf_writer_buffer_size(&g_buf_writer, g_buf);
- oc_rep_reset();
- if (g_err != CborNoError)
- return -1;
- return size;
+ int size = cbor_buf_writer_buffer_size(&g_buf_writer, g_buf);
+ oc_rep_reset();
+ if (g_err != CborNoError) {
+ return -1;
+ }
+ return size;
}
void
oc_rep_reset(void)
{
- g_encoder = g_empty;
+ g_encoder = g_empty;
}
static oc_rep_t *
_alloc_rep(void)
{
- oc_rep_t *rep = oc_memb_alloc(&rep_objects);
+ oc_rep_t *rep = os_memblock_get(&oc_rep_objects);
#ifdef DEBUG
- oc_assert(rep != NULL);
+ oc_assert(rep != NULL);
#endif
- return rep;
+ return rep;
}
static void
_free_rep(oc_rep_t *rep_value)
{
- oc_memb_free(&rep_objects, rep_value);
+ os_memblock_put(&oc_rep_objects, rep_value);
}
void
oc_free_rep(oc_rep_t *rep)
{
- if (rep == 0)
- return;
- oc_free_rep(rep->next);
- switch (rep->type) {
- case BYTE_STRING_ARRAY:
- case STRING_ARRAY:
- oc_free_string_array(&rep->value_array);
- break;
- case BOOL_ARRAY:
- oc_free_bool_array(&rep->value_array);
- break;
- case DOUBLE_ARRAY:
- oc_free_double_array(&rep->value_array);
- break;
- case INT_ARRAY:
- oc_free_int_array(&rep->value_array);
- break;
- case BYTE_STRING:
- case STRING:
- oc_free_string(&rep->value_string);
- break;
- case OBJECT:
- oc_free_rep(rep->value_object);
- break;
- case OBJECT_ARRAY:
- oc_free_rep(rep->value_object_array);
- break;
- default:
- break;
- }
- oc_free_string(&rep->name);
- _free_rep(rep);
+ if (rep == NULL) {
+ return;
+ }
+ oc_free_rep(rep->next);
+ switch (rep->type) {
+ case BYTE_STRING_ARRAY:
+ case STRING_ARRAY:
+ oc_free_string_array(&rep->value_array);
+ break;
+ case BOOL_ARRAY:
+ oc_free_bool_array(&rep->value_array);
+ break;
+ case DOUBLE_ARRAY:
+ oc_free_double_array(&rep->value_array);
+ break;
+ case INT_ARRAY:
+ oc_free_int_array(&rep->value_array);
+ break;
+ case BYTE_STRING:
+ case STRING:
+ oc_free_string(&rep->value_string);
+ break;
+ case OBJECT:
+ oc_free_rep(rep->value_object);
+ break;
+ case OBJECT_ARRAY:
+ oc_free_rep(rep->value_object_array);
+ break;
+ default:
+ break;
+ }
+ oc_free_string(&rep->name);
+ _free_rep(rep);
}
/*
@@ -306,3 +315,10 @@ oc_parse_rep(const uint8_t *in_payload, uint16_t payload_size,
}
return (uint16_t)err;
}
+
+void
+oc_rep_init(void)
+{
+ os_mempool_init(&oc_rep_objects, EST_NUM_REP_OBJECTS,
+ sizeof(oc_rep_t), oc_rep_objects_area, "oc_rep_o");
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3320d476/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 67e708f..326cdeb 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -37,6 +37,7 @@
#include "oc_network_events.h"
#include "oc_ri.h"
#include "oc_uuid.h"
+#include "oc_priv.h"
#ifdef OC_SECURITY
#include "security/oc_acl.h"
@@ -224,6 +225,7 @@ oc_ri_init(void)
#ifdef OC_CLIENT
oc_list_init(client_cbs);
#endif
+ oc_rep_init();
start_processes();
oc_create_discovery_resource();
[16/27] incubator-mynewt-core git commit: oic;
use os_mempool for oc_client_cbs, and oc_app_resources.
Posted by ma...@apache.org.
oic; use os_mempool for oc_client_cbs, and oc_app_resources.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a2c3b0d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a2c3b0d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a2c3b0d8
Branch: refs/heads/develop
Commit: a2c3b0d8b89a631d69fff5776f92e07298d81693
Parents: 502f410
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 21 17:03:17 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_ri.c | 119 +++++++++++++++++++++++--------------------
1 file changed, 65 insertions(+), 54 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a2c3b0d8/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index 8fd4f8d..9219f7b 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -19,9 +19,9 @@
#include <strings.h>
#include <os/os_callout.h>
+#include <os/os_mempool.h>
#include "util/oc_list.h"
-#include "util/oc_memb.h"
#include "messaging/coap/constants.h"
#include "messaging/coap/engine.h"
@@ -47,7 +47,9 @@
#ifdef OC_SERVER
OC_LIST(app_resources);
OC_LIST(observe_callbacks);
-OC_MEMB(app_resources_s, oc_resource_t, MAX_APP_RESOURCES);
+static struct os_mempool oc_resources;
+static uint8_t oc_resource_area[OS_MEMPOOL_BYTES(MAX_APP_RESOURCES,
+ sizeof(oc_resource_t))];
static void periodic_observe_handler(struct os_event *ev);
#endif /* OC_SERVER */
@@ -55,7 +57,9 @@ static void periodic_observe_handler(struct os_event *ev);
#ifdef OC_CLIENT
#include "oc_client_state.h"
OC_LIST(client_cbs);
-OC_MEMB(client_cbs_s, oc_client_cb_t, MAX_NUM_CONCURRENT_REQUESTS);
+static struct os_mempool oc_client_cbs;
+static uint8_t oc_client_cb_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS,
+ sizeof(oc_client_cb_t))];
#endif /* OC_CLIENT */
// TODO: Define and use a complete set of error codes.
@@ -219,11 +223,15 @@ oc_ri_init(void)
#ifdef OC_SERVER
oc_list_init(app_resources);
+ os_mempool_init(&oc_resources, MAX_APP_RESOURCES, sizeof(oc_resource_t),
+ oc_resource_area, "oc_res");
oc_list_init(observe_callbacks);
#endif
#ifdef OC_CLIENT
oc_list_init(client_cbs);
+ os_mempool_init(&oc_client_cbs, MAX_NUM_CONCURRENT_REQUESTS,
+ sizeof(oc_client_cb_t), oc_client_cb_area, "oc_cl_cbs");
#endif
oc_rep_init();
oc_buffer_init();
@@ -245,7 +253,7 @@ oc_ri_alloc_resource(void)
{
struct oc_resource_s *resource;
- resource = oc_memb_alloc(&app_resources_s);
+ resource = os_memblock_get(&oc_resources);
if (resource) {
os_callout_init(&resource->callout, oc_evq_get(),
periodic_observe_handler, resource);
@@ -256,27 +264,27 @@ oc_ri_alloc_resource(void)
void
oc_ri_delete_resource(oc_resource_t *resource)
{
- oc_memb_free(&app_resources_s, resource);
+ os_memblock_put(&oc_resources, resource);
}
bool
oc_ri_add_resource(oc_resource_t *resource)
{
- bool valid = true;
+ bool valid = true;
- if (!resource->get_handler && !resource->put_handler &&
- !resource->post_handler && !resource->delete_handler)
- valid = false;
-
- if (resource->properties & OC_PERIODIC &&
- resource->observe_period_seconds == 0)
- valid = false;
-
- if (valid) {
- oc_list_add(app_resources, resource);
- }
+ if (!resource->get_handler && !resource->put_handler &&
+ !resource->post_handler && !resource->delete_handler) {
+ valid = false;
+ }
+ if (resource->properties & OC_PERIODIC &&
+ resource->observe_period_seconds == 0) {
+ valid = false;
+ }
+ if (valid) {
+ oc_list_add(app_resources, resource);
+ }
- return valid;
+ return valid;
}
#endif /* OC_SERVER */
@@ -670,7 +678,7 @@ free_client_cb(oc_client_cb_t *cb)
os_callout_stop(&cb->callout);
oc_free_string(&cb->uri);
oc_list_remove(client_cbs, cb);
- oc_memb_free(&client_cbs_s, cb);
+ os_memblock_put(&oc_client_cbs, cb);
}
void
@@ -806,20 +814,21 @@ oc_client_cb_t *
oc_ri_get_client_cb(const char *uri, oc_server_handle_t *server,
oc_method_t method)
{
- oc_client_cb_t *cb = (oc_client_cb_t *)oc_list_head(client_cbs);
-
- while (cb != NULL) {
- if (oc_string_len(cb->uri) == strlen(uri) &&
- strncmp(oc_string(cb->uri), uri, strlen(uri)) == 0 &&
- memcmp(&cb->server.endpoint, &server->endpoint,
- sizeof(oc_endpoint_t)) == 0 &&
- cb->method == method)
- return cb;
+ oc_client_cb_t *cb = (oc_client_cb_t *)oc_list_head(client_cbs);
+
+ while (cb != NULL) {
+ if (oc_string_len(cb->uri) == strlen(uri) &&
+ strncmp(oc_string(cb->uri), uri, strlen(uri)) == 0 &&
+ memcmp(&cb->server.endpoint, &server->endpoint,
+ sizeof(oc_endpoint_t)) == 0 &&
+ cb->method == method) {
+ return cb;
+ }
- cb = cb->next;
- }
+ cb = cb->next;
+ }
- return cb;
+ return cb;
}
static void
@@ -836,32 +845,34 @@ oc_client_cb_t *
oc_ri_alloc_client_cb(const char *uri, oc_server_handle_t *server,
oc_method_t method, void *handler, oc_qos_t qos)
{
- oc_client_cb_t *cb = oc_memb_alloc(&client_cbs_s);
- if (!cb)
- return cb;
+ oc_client_cb_t *cb;
- cb->mid = coap_get_mid();
- oc_new_string(&cb->uri, uri);
- cb->method = method;
- cb->qos = qos;
- cb->handler = handler;
- cb->token_len = 8;
- int i = 0;
- uint16_t r;
- while (i < cb->token_len) {
- r = oc_random_rand();
- memcpy(cb->token + i, &r, sizeof(r));
- i += sizeof(r);
- }
- cb->discovery = false;
- cb->timestamp = oc_clock_time();
- cb->observe_seq = -1;
- memcpy(&cb->server, server, sizeof(oc_server_handle_t));
+ cb = os_memblock_get(&oc_client_cbs);
+ if (!cb) {
+ return NULL;
+ }
+ cb->mid = coap_get_mid();
+ oc_new_string(&cb->uri, uri);
+ cb->method = method;
+ cb->qos = qos;
+ cb->handler = handler;
+ cb->token_len = 8;
+ int i = 0;
+ uint16_t r;
+ while (i < cb->token_len) {
+ r = oc_random_rand();
+ memcpy(cb->token + i, &r, sizeof(r));
+ i += sizeof(r);
+ }
+ cb->discovery = false;
+ cb->timestamp = oc_clock_time();
+ cb->observe_seq = -1;
+ memcpy(&cb->server, server, sizeof(oc_server_handle_t));
- os_callout_init(&cb->callout, oc_evq_get(), oc_ri_remove_cb, cb);
+ os_callout_init(&cb->callout, oc_evq_get(), oc_ri_remove_cb, cb);
- oc_list_add(client_cbs, cb);
- return cb;
+ oc_list_add(client_cbs, cb);
+ return cb;
}
#endif /* OC_CLIENT */
[22/27] incubator-mynewt-core git commit: oic;
change coap_separate to use os_mempools.
Posted by ma...@apache.org.
oic; change coap_separate to use os_mempools.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/f861cf8d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f861cf8d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f861cf8d
Branch: refs/heads/develop
Commit: f861cf8d3f66c6f6777b459756729c592361b441
Parents: 3320d47
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 21 14:47:19 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
net/oic/src/messaging/coap/engine.c | 3 +
net/oic/src/messaging/coap/separate.c | 140 ++++++++++++++++-------------
net/oic/src/messaging/coap/separate.h | 2 +
3 files changed, 81 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f861cf8d/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index cff4505..a17ebd6 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -304,4 +304,7 @@ coap_engine_init(void)
{
coap_init_connection();
coap_transaction_init();
+#ifdef OC_SERVER
+ coap_separate_init();
+#endif
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f861cf8d/net/oic/src/messaging/coap/separate.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.c b/net/oic/src/messaging/coap/separate.c
index 5be01e7..2aad061 100644
--- a/net/oic/src/messaging/coap/separate.c
+++ b/net/oic/src/messaging/coap/separate.c
@@ -35,14 +35,18 @@
#ifdef OC_SERVER
+#include <stdio.h>
+#include <string.h>
+
+#include <os/os_mempool.h>
+
#include "oc_buffer.h"
#include "separate.h"
#include "transactions.h"
-#include "util/oc_memb.h"
-#include <stdio.h>
-#include <string.h>
-OC_MEMB(separate_requests, coap_separate_t, MAX_NUM_CONCURRENT_REQUESTS);
+static struct os_mempool coap_separate_pool;
+static uint8_t coap_separate_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS,
+ sizeof(coap_separate_t))];
/*---------------------------------------------------------------------------*/
/*- Separate Response API ---------------------------------------------------*/
@@ -63,90 +67,98 @@ int
coap_separate_accept(void *request, oc_separate_response_t *separate_response,
oc_endpoint_t *endpoint, int observe)
{
- if (separate_response->active == 0) {
- OC_LIST_STRUCT_INIT(separate_response, requests);
- }
-
- coap_packet_t *const coap_req = (coap_packet_t *)request;
-
- for (coap_separate_t *item = oc_list_head(separate_response->requests);
- item != NULL; item = oc_list_item_next(separate_response->requests)) {
- if (item->token_len == coap_req->token_len &&
- memcmp(item->token, coap_req->token, item->token_len) == 0) {
- return 0;
+ if (separate_response->active == 0) {
+ OC_LIST_STRUCT_INIT(separate_response, requests);
}
- }
- coap_separate_t *separate_store = oc_memb_alloc(&separate_requests);
+ coap_packet_t *const coap_req = (coap_packet_t *)request;
- if (!separate_store)
- return 0;
+ for (coap_separate_t *item = oc_list_head(separate_response->requests);
+ item != NULL; item = oc_list_item_next(separate_response->requests)) {
+ if (item->token_len == coap_req->token_len &&
+ memcmp(item->token, coap_req->token, item->token_len) == 0) {
+ return 0;
+ }
+ }
- oc_list_add(separate_response->requests, separate_store);
+ coap_separate_t *separate_store = os_memblock_get(&coap_separate_pool);
- erbium_status_code = CLEAR_TRANSACTION;
- /* send separate ACK for CON */
- if (coap_req->type == COAP_TYPE_CON) {
- LOG("Sending ACK for separate response\n");
- coap_packet_t ack[1];
- /* ACK with empty code (0) */
- coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->mid);
- if (observe < 2) {
- coap_set_header_observe(ack, observe);
+ if (!separate_store) {
+ return 0;
}
- coap_set_token(ack, coap_req->token, coap_req->token_len);
- oc_message_t *message = oc_allocate_message();
- if (message != NULL) {
- message->endpoint.flags = IP;
- memcpy(&message->endpoint, endpoint, sizeof(oc_endpoint_t));
- message->length = coap_serialize_message(ack, message->data);
- coap_send_message(message);
- } else {
- coap_separate_clear(separate_response, separate_store);
- erbium_status_code = SERVICE_UNAVAILABLE_5_03;
- return 0;
+
+ oc_list_add(separate_response->requests, separate_store);
+
+ erbium_status_code = CLEAR_TRANSACTION;
+ /* send separate ACK for CON */
+ if (coap_req->type == COAP_TYPE_CON) {
+ LOG("Sending ACK for separate response\n");
+ coap_packet_t ack[1];
+ /* ACK with empty code (0) */
+ coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->mid);
+ if (observe < 2) {
+ coap_set_header_observe(ack, observe);
+ }
+ coap_set_token(ack, coap_req->token, coap_req->token_len);
+ oc_message_t *message = oc_allocate_message();
+ if (message != NULL) {
+ message->endpoint.flags = IP;
+ memcpy(&message->endpoint, endpoint, sizeof(oc_endpoint_t));
+ message->length = coap_serialize_message(ack, message->data);
+ coap_send_message(message);
+ } else {
+ coap_separate_clear(separate_response, separate_store);
+ erbium_status_code = SERVICE_UNAVAILABLE_5_03;
+ return 0;
+ }
}
- }
- memcpy(&separate_store->endpoint, endpoint, sizeof(oc_endpoint_t));
+ memcpy(&separate_store->endpoint, endpoint, sizeof(oc_endpoint_t));
- /* store correct response type */
- separate_store->type = COAP_TYPE_NON;
+ /* store correct response type */
+ separate_store->type = COAP_TYPE_NON;
- memcpy(separate_store->token, coap_req->token, coap_req->token_len);
- separate_store->token_len = coap_req->token_len;
+ memcpy(separate_store->token, coap_req->token, coap_req->token_len);
+ separate_store->token_len = coap_req->token_len;
- separate_store->block1_num = coap_req->block1_num;
- separate_store->block1_size = coap_req->block1_size;
+ separate_store->block1_num = coap_req->block1_num;
+ separate_store->block1_size = coap_req->block1_size;
- separate_store->block2_num = coap_req->block2_num;
- separate_store->block2_size =
- coap_req->block2_size > 0 ? MIN(COAP_MAX_BLOCK_SIZE, coap_req->block2_size)
- : COAP_MAX_BLOCK_SIZE;
+ separate_store->block2_num = coap_req->block2_num;
+ separate_store->block2_size =
+ coap_req->block2_size > 0 ?
+ MIN(COAP_MAX_BLOCK_SIZE, coap_req->block2_size) : COAP_MAX_BLOCK_SIZE;
- separate_store->observe = observe;
- return 1;
+ separate_store->observe = observe;
+ return 1;
}
/*----------------------------------------------------------------------------*/
void
coap_separate_resume(void *response, coap_separate_t *separate_store,
uint8_t code, uint16_t mid)
{
- coap_init_message(response, separate_store->type, code, mid);
- if (separate_store->token_len) {
- coap_set_token(response, separate_store->token, separate_store->token_len);
- }
- if (separate_store->block1_size) {
- coap_set_header_block1(response, separate_store->block1_num, 0,
- separate_store->block1_size);
- }
+ coap_init_message(response, separate_store->type, code, mid);
+ if (separate_store->token_len) {
+ coap_set_token(response, separate_store->token,
+ separate_store->token_len);
+ }
+ if (separate_store->block1_size) {
+ coap_set_header_block1(response, separate_store->block1_num, 0,
+ separate_store->block1_size);
+ }
}
/*---------------------------------------------------------------------------*/
void
coap_separate_clear(oc_separate_response_t *separate_response,
coap_separate_t *separate_store)
{
- oc_list_remove(separate_response->requests, separate_store);
- oc_memb_free(&separate_requests, separate_store);
+ oc_list_remove(separate_response->requests, separate_store);
+ os_memblock_put(&coap_separate_pool, separate_store);
}
+void
+coap_separate_init(void)
+{
+ os_mempool_init(&coap_separate_pool, MAX_NUM_CONCURRENT_REQUESTS,
+ sizeof(coap_separate_t), coap_separate_area, "coap_sep");
+}
#endif /* OC_SERVER */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f861cf8d/net/oic/src/messaging/coap/separate.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.h b/net/oic/src/messaging/coap/separate.h
index 7f32da1..9b3379e 100644
--- a/net/oic/src/messaging/coap/separate.h
+++ b/net/oic/src/messaging/coap/separate.h
@@ -72,6 +72,8 @@ void coap_separate_resume(void *response, coap_separate_t *separate_store,
void coap_separate_clear(oc_separate_response_t *separate_response,
coap_separate_t *separate_store);
+void coap_separate_init(void);
+
#ifdef __cplusplus
}
#endif
[24/27] incubator-mynewt-core git commit: oic;
use %zu when printing size_t.
Posted by ma...@apache.org.
oic; use %zu when printing size_t.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/97b87d93
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/97b87d93
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/97b87d93
Branch: refs/heads/develop
Commit: 97b87d93185b1df08976a04d9c46a81b6f886cb9
Parents: e6179b5
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 21 11:27:18 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:49 2016 -0800
----------------------------------------------------------------------
net/oic/src/port/mynewt/serial_adaptor.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/97b87d93/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
index ef8f4b0..be807d3 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -102,7 +102,7 @@ oc_send_buffer_serial(oc_message_t *message)
goto err;
}
- LOG("oc_transport_serial: send buffer %lu\n", message->length);
+ LOG("oc_transport_serial: send buffer %zu\n", message->length);
err:
oc_message_unref(message);
@@ -157,7 +157,7 @@ oc_attempt_rx_serial(void) {
message->endpoint.flags = SERIAL;
message->length = pkt->omp_len;
- LOG("Successfully rx length %lu\n", message->length);
+ LOG("Successfully rx length %zu\n", message->length);
return message;
/* add the addr info to the message */
[13/27] incubator-mynewt-core git commit: cbor;
floating point support optional.
Posted by ma...@apache.org.
cbor; floating point support optional.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/948b380a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/948b380a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/948b380a
Branch: refs/heads/develop
Commit: 948b380ab3e9f7dd4f2baa36d7d239bef1bc262e
Parents: 6e25f3f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 16 16:58:24 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800
----------------------------------------------------------------------
encoding/cborattr/pkg.yml | 2 ++
encoding/cborattr/src/cborattr.c | 10 ++++++++++
encoding/tinycbor/pkg.yml | 1 +
encoding/tinycbor/src/cborencoder.c | 2 ++
encoding/tinycbor/src/cborpretty.c | 5 +++--
encoding/tinycbor/src/cbortojson.c | 5 ++++-
6 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/cborattr/pkg.yml
----------------------------------------------------------------------
diff --git a/encoding/cborattr/pkg.yml b/encoding/cborattr/pkg.yml
index 541ab23..01f5982 100644
--- a/encoding/cborattr/pkg.yml
+++ b/encoding/cborattr/pkg.yml
@@ -25,3 +25,5 @@ pkg.keywords:
pkg.deps:
- "encoding/tinycbor"
+
+pkg.cflags.float_user: -DFLOAT_SUPPORT
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/cborattr/src/cborattr.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/src/cborattr.c b/encoding/cborattr/src/cborattr.c
index 4d04248..a7ca9c0 100644
--- a/encoding/cborattr/src/cborattr.c
+++ b/encoding/cborattr/src/cborattr.c
@@ -46,6 +46,7 @@ valid_attr_type(CborType ct, CborAttrType at) {
if (ct == CborBooleanType) {
return 1;
}
+#if FLOAT_SUPPORT
case CborAttrFloatType:
if (ct == CborFloatType) {
return 1;
@@ -56,6 +57,7 @@ valid_attr_type(CborType ct, CborAttrType at) {
return 1;
}
break;
+#endif
case CborAttrArrayType:
if (ct == CborArrayType) {
return 1;
@@ -66,6 +68,8 @@ valid_attr_type(CborType ct, CborAttrType at) {
return 1;
}
break;
+ default:
+ break;
}
return 0;
}
@@ -89,12 +93,14 @@ cbor_target_address(const struct cbor_attr_t *cursor,
case CborAttrUnsignedIntegerType:
targetaddr = (char *)&cursor->addr.uinteger[offset];
break;
+#if FLOAT_SUPPORT
case CborAttrFloatType:
targetaddr = (char *)&cursor->addr.fval[offset];
break;
case CborAttrDoubleType:
targetaddr = (char *)&cursor->addr.real[offset];
break;
+#endif
case CborAttrByteStringType:
targetaddr = (char *) cursor->addr.bytestring.data;
break;
@@ -145,12 +151,14 @@ cbor_internal_read_object(CborValue *root_value,
case CborAttrBooleanType:
memcpy(lptr, &cursor->dflt.boolean, sizeof(bool));
break;
+#if FLOAT_SUPPORT
case CborAttrFloatType:
memcpy(lptr, &cursor->dflt.fval, sizeof(float));
break;
case CborAttrDoubleType:
memcpy(lptr, &cursor->dflt.real, sizeof(double));
break;
+#endif
default:
break;
}
@@ -215,12 +223,14 @@ cbor_internal_read_object(CborValue *root_value,
case CborAttrUnsignedIntegerType:
g_err |= cbor_value_get_uint64(&cur_value, (long long unsigned int *) lptr);
break;
+#if FLOAT_SUPPORT
case CborAttrFloatType:
g_err |= cbor_value_get_float(&cur_value, (float *) lptr);
break;
case CborAttrDoubleType:
g_err |= cbor_value_get_double(&cur_value, (double *) lptr);
break;
+#endif
case CborAttrByteStringType:
{
size_t len = cursor->len;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/tinycbor/pkg.yml
----------------------------------------------------------------------
diff --git a/encoding/tinycbor/pkg.yml b/encoding/tinycbor/pkg.yml
index acd66c0..f969de8 100644
--- a/encoding/tinycbor/pkg.yml
+++ b/encoding/tinycbor/pkg.yml
@@ -24,3 +24,4 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
pkg.cflags: -DWITHOUT_OPEN_MEMSTREAM -I../include/tinycbor
+pkg.cflags.float_user: -DFLOAT_SUPPORT
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/tinycbor/src/cborencoder.c
----------------------------------------------------------------------
diff --git a/encoding/tinycbor/src/cborencoder.c b/encoding/tinycbor/src/cborencoder.c
index b510662..0bf81b4 100644
--- a/encoding/tinycbor/src/cborencoder.c
+++ b/encoding/tinycbor/src/cborencoder.c
@@ -334,6 +334,7 @@ CborError cbor_encode_simple_value(CborEncoder *encoder, uint8_t value)
return encode_number(encoder, value, SimpleTypesType << MajorTypeShift);
}
+#if FLOAT_SUPPORT
/**
* Appends the floating-point value of type \a fpType and pointed to by \a
* value to the CBOR stream provided by \a encoder. The value of \a fpType must
@@ -361,6 +362,7 @@ CborError cbor_encode_floating_point(CborEncoder *encoder, CborType fpType, cons
++encoder->added;
return append_to_buffer(encoder, buf, size + 1);
}
+#endif
/**
* Appends the CBOR tag \a tag to the CBOR stream provided by \a encoder.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/tinycbor/src/cborpretty.c
----------------------------------------------------------------------
diff --git a/encoding/tinycbor/src/cborpretty.c b/encoding/tinycbor/src/cborpretty.c
index 3587703..b4335a7 100644
--- a/encoding/tinycbor/src/cborpretty.c
+++ b/encoding/tinycbor/src/cborpretty.c
@@ -392,7 +392,7 @@ static CborError value_to_pretty(FILE *out, CborValue *it)
return CborErrorIO;
break;
}
-
+#if FLOAT_SUPPORT
case CborDoubleType: {
const char *suffix;
double val;
@@ -430,8 +430,9 @@ static CborError value_to_pretty(FILE *out, CborValue *it)
return CborErrorIO;
break;
}
-
+#endif
case CborInvalidType:
+ default:
if (fprintf(out, "invalid") < 0)
return CborErrorIO;
return CborErrorUnknownType;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/tinycbor/src/cbortojson.c
----------------------------------------------------------------------
diff --git a/encoding/tinycbor/src/cbortojson.c b/encoding/tinycbor/src/cbortojson.c
index 5efa486..b8e116f 100644
--- a/encoding/tinycbor/src/cbortojson.c
+++ b/encoding/tinycbor/src/cbortojson.c
@@ -594,7 +594,7 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
return CborErrorIO;
break;
}
-
+#if FLOAT_SUPPORT
case CborDoubleType: {
double val;
if (false) {
@@ -634,8 +634,10 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
}
break;
}
+#endif
case CborInvalidType:
+ default:
return CborErrorUnknownType;
}
@@ -643,6 +645,7 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
}
/**
+
* \enum CborToJsonFlags
* The CborToJsonFlags enum contains flags that control the conversion of CBOR to JSON.
*