You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/11/01 17:16:48 UTC
[05/11] incubator-mynewt-core git commit: OIC: Event codes ->
callbacks
OIC: Event codes -> callbacks
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/98c990f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/98c990f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/98c990f1
Branch: refs/heads/develop
Commit: 98c990f14c3a28e496220c7949dd356f7be491a2
Parents: 6c85e72
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Oct 30 14:41:45 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:07:59 2016 -0700
----------------------------------------------------------------------
mgmt/oicmgr/src/oicmgr.c | 93 +++++++++++++++------------
net/oic/src/port/mynewt/adaptor.c | 36 +----------
net/oic/src/port/mynewt/adaptor.h | 4 --
net/oic/src/port/mynewt/ble_adaptor.c | 12 +++-
net/oic/src/port/mynewt/ip_adaptor.c | 16 ++++-
net/oic/src/port/mynewt/serial_adaptor.c | 12 +++-
6 files changed, 89 insertions(+), 84 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/mgmt/oicmgr/src/oicmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/oicmgr/src/oicmgr.c b/mgmt/oicmgr/src/oicmgr.c
index 3011ebd..63b7419 100644
--- a/mgmt/oicmgr/src/oicmgr.c
+++ b/mgmt/oicmgr/src/oicmgr.c
@@ -37,6 +37,7 @@
#define OMGR_OC_EVENT (OS_EVENT_T_PERUSER)
#define OMGR_OC_TIMER (OS_EVENT_T_PERUSER + 1)
+#define OMGR_OC_START (OS_EVENT_T_PERUSER + 2)
#define OICMGR_STACK_SZ OS_STACK_ALIGN(MYNEWT_VAL(OICMGR_STACK_SIZE))
struct omgr_cbuf {
@@ -52,18 +53,33 @@ struct omgr_state {
struct omgr_cbuf os_cbuf; /* CBOR buffer for NMGR task */
};
+static void omgr_event_start(struct os_event *ev);
+static void omgr_event_oc_ev(struct os_event *ev);
+
static struct omgr_state omgr_state = {
- .os_oc_event.ev_type = OMGR_OC_EVENT,
- .os_oc_timer.c_ev.ev_type = OMGR_OC_TIMER,
- .os_oc_timer.c_evq = &omgr_state.os_evq
+ .os_oc_event.ev_cb = omgr_event_oc_ev,
};
-struct os_eventq *g_mgmt_evq = &omgr_state.os_evq;
-static os_stack_t oicmgr_stack[OICMGR_STACK_SZ];
+static struct os_event omgr_ev_start = {
+ .ev_cb = omgr_event_start,
+};
static void omgr_oic_get(oc_request_t *request, oc_interface_mask_t interface);
static void omgr_oic_put(oc_request_t *request, oc_interface_mask_t interface);
+struct os_eventq *
+mgmt_evq_get(void)
+{
+ os_eventq_ensure(&omgr_state.os_evq;, NULL);
+ return &omgr_state.os_evq;
+}
+
+void
+omgr_evq_set(struct os_eventq *evq)
+{
+ os_eventq_designate(&omgr_state.os_evq, evq, NULL);
+}
+
static const struct mgmt_handler *
omgr_oic_find_handler(const char *q, int qlen)
{
@@ -119,11 +135,13 @@ omgr_oic_op(oc_request_t *req, oc_interface_mask_t mask, int isset)
cbor_parser_init(&o->os_cbuf.ob_reader.r, 0, &o->os_cbuf.ob_mj.parser, &o->os_cbuf.ob_mj.it);
/* start generating the CBOR OUTPUT */
- /* this is worth a quick note. We are encoding CBOR within CBOR, so we need
- * to use the same encoder as ocf stack. We are using their global encoder
- * g_encoder which they intialized before this function is called. Byt we can't
- * call their macros here as it won't use the right mape encoder (ob_mj) */
- cbor_encoder_create_map(&g_encoder, &o->os_cbuf.ob_mj.encoder, CborIndefiniteLength);
+ /* this is worth a quick note. We are encoding CBOR within CBOR, so we
+ * need to use the same encoder as ocf stack. We are using their global
+ * encoder g_encoder which they intialized before this function is called.
+ * But we can't call their macros here as it won't use the right mape
+ * encoder (ob_mj) */
+ cbor_encoder_create_map(&g_encoder, &o->os_cbuf.ob_mj.encoder,
+ CborIndefiniteLength);
switch (mask) {
case OC_IF_BASELINE:
@@ -217,52 +235,45 @@ oc_signal_main_loop(void)
{
struct omgr_state *o = &omgr_state;
- os_eventq_put(&o->os_evq, &o->os_oc_event);
+ os_childq_put(&o->os_cq, &o->os_oc_event);
}
-void
-omgr_oic_task(void *arg)
+static void
+omgr_oic_process_oc_event(struct os_event *ev)
{
struct omgr_state *o = &omgr_state;
- struct os_event *ev;
- struct os_callout_func *ocf;
os_time_t next_event;
- oc_main_init((oc_handler_t *)&omgr_oc_handler);
- while (1) {
- ev = os_eventq_get(&o->os_evq);
- switch (ev->ev_type) {
- case OMGR_OC_EVENT:
- case OMGR_OC_TIMER:
- 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);
- }
- break;
- case OS_EVENT_T_TIMER:
- ocf = (struct os_callout_func *)ev;
- ocf->cf_func(CF_ARG(ocf));
- break;
- }
+ next_event = oc_main_poll();
+ if (next_event) {
+ os_callout_reset(&o->os_oc_timer.cf_c, next_event - os_time_get());
+ } else {
+ os_callout_stop(&o->os_oc_timer.cf_c);
}
}
+static void
+omgr_oic_event_start(struct os_event *ev)
+{
+ oc_main_init((oc_handler_t *)&omgr_oc_handler);
+ os_callout_init(&omgr_state.os_oc_timer, mgmt_evq_get(),
+ omgr_oic_process_oc_event, NULL);
+}
+
+static void
+omgr_oic_event_oc_ev(struct os_event *ev)
+{
+ omgr_oic_process_oc_event(NULL);
+}
+
int
oicmgr_init(void)
{
struct omgr_state *o = &omgr_state;
int rc;
- os_eventq_init(&o->os_evq);
-
- rc = os_task_init(&o->os_task, "oicmgr", omgr_oic_task, NULL,
- MYNEWT_VAL(OICMGR_TASK_PRIO), OS_WAIT_FOREVER,
- oicmgr_stack, OICMGR_STACK_SZ);
- if (rc != 0) {
- goto err;
- }
+ os_childq_init(&o->os_cq);
+ o->os_cq.cq_ev_cb = omgr_oic_handle_event;
rc = nmgr_os_groups_register();
if (rc != 0) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/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 e4b1cd6..1ca90f2 100644
--- a/net/oic/src/port/mynewt/adaptor.c
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -113,41 +113,7 @@ void
oc_task_handler(void *arg)
{
while (1) {
- struct os_callout_func *cf;
- oc_message_t *pmsg;
- (void) pmsg; /* to avoid unused */
- struct os_event *evt = os_eventq_get(&oc_event_q);
-
- switch(evt->ev_type) {
-#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
- case OC_ADATOR_EVENT_IP:
- while ((pmsg = oc_attempt_rx_ip()) != NULL) {
- oc_network_event(pmsg);
- }
- break;
-#endif
-#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
- case OC_ADATOR_EVENT_SERIAL:
- while ((pmsg = oc_attempt_rx_serial()) != NULL) {
- oc_network_event(pmsg);
- }
- break;
-#endif
-#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
- case OC_ADATOR_EVENT_GATT:
- while ((pmsg = oc_attempt_rx_gatt()) != NULL) {
- oc_network_event(pmsg);
- }
- break;
-#endif
- case OS_EVENT_T_TIMER:
- cf = (struct os_callout_func *)evt;
- assert(cf->cf_func);
- cf->cf_func(CF_ARG(cf));
- break;
- default:
- ERROR("oc_task_handler: Unidentified event %d\n", evt->ev_type);
- }
+ os_eventq_run(&oc_event_q);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/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 9378f49..6a0d246 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -24,10 +24,6 @@
extern "C" {
#endif
-#define OC_ADATOR_EVENT_IP (OS_EVENT_T_PERUSER + 0)
-#define OC_ADATOR_EVENT_SERIAL (OS_EVENT_T_PERUSER + 1)
-#define OC_ADATOR_EVENT_GATT (OS_EVENT_T_PERUSER + 2)
-
extern struct os_eventq oc_event_q;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/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 13b0ba6..634a20b 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -201,11 +201,21 @@ ble_coap_gatt_srv_init(struct os_eventq **out)
return 0;
}
+static void
+oc_event_gatt(struct os_event *ev)
+{
+ oc_message_t *pmsg;
+
+ while ((pmsg = oc_attempt_rx_gatt()) != NULL) {
+ oc_network_event(pmsg);
+ }
+}
+
int
oc_connectivity_init_gatt(void)
{
os_mqueue_init(&ble_coap_mq, NULL);
- ble_coap_mq.mq_ev.ev_type = OC_ADATOR_EVENT_GATT;
+ ble_coap_mq.mq_ev.ev_cb = oc_event_gatt;
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
index 22f063d..3585c51 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -31,8 +31,10 @@
#include "../oc_log.h"
#include "adaptor.h"
+static void oc_event_ip(struct os_event *ev);
+
struct os_event oc_sock_read_event = {
- .ev_type = OC_ADATOR_EVENT_IP,
+ .ev_cb = oc_event_ip,
};
#ifdef OC_SECURITY
@@ -226,6 +228,16 @@ oc_connectivity_shutdown_ip(void)
}
+static void
+oc_event_ip(struct os_event *ev)
+{
+ oc_message_t *pmsg;
+
+ while ((pmsg = oc_attempt_rx_ip()) != NULL) {
+ oc_network_event(pmsg);
+ }
+}
+
int
oc_connectivity_init_ip(void)
{
@@ -312,4 +324,4 @@ oc_connectivity_init_err:
return rc;
}
-#endif
\ No newline at end of file
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/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 d67c7f5..15f95e0 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -41,6 +41,16 @@ oc_connectivity_shutdown_serial(void) {
shell_nlip_input_register(NULL, NULL);
}
+static void
+oc_event_serial(struct os_event *ev)
+{
+ oc_message_t *pmsg;
+
+ while ((pmsg = oc_attempt_rx_serial()) != NULL) {
+ oc_network_event(pmsg);
+ }
+}
+
int
oc_connectivity_init_serial(void) {
int rc;
@@ -55,7 +65,7 @@ oc_connectivity_init_serial(void) {
goto err;
}
/* override the eventq type */
- oc_serial_mqueue.mq_ev.ev_type = OC_ADATOR_EVENT_SERIAL;
+ oc_serial_mqueue.mq_ev.ev_cb = oc_event_serial;
return 0;
err: