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:07 UTC

[08/27] incubator-mynewt-core git commit: oic coap; use os_callout as timer instead of oc_etimer.

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;