vrahane commented on a change in pull request #1917: Use SMP/OMP/MCUmgr, remove 
newtmgr and change OICMGR to use OMP 
URL: https://github.com/apache/mynewt-core/pull/1917#discussion_r332300157
 
 

 ##########
 File path: mgmt/oicmgr/src/oicmgr.c
 ##########
 @@ -19,244 +19,217 @@
 
 #include <assert.h>
 #include <string.h>
-
 #include "os/mynewt.h"
+#include "mem/mem.h"
+#include "mgmt/mgmt.h"
+#include "omp/omp.h"
+
+#include "tinycbor/cbor.h"
+#include "tinycbor/cbor_mbuf_writer.h"
+#include "tinycbor/cbor_mbuf_reader.h"
+#include "cborattr/cborattr.h"
+#include "omp/omp.h"
+
+#include "oic/oc_api.h"
+
+static struct omp_state omgr_state;
+
+static mgmt_alloc_rsp_fn omgr_alloc_rsp;
+static mgmt_trim_front_fn omgr_trim_front;
+static mgmt_reset_buf_fn omgr_reset_buf;
+static mgmt_write_at_fn omgr_write_at;
+static mgmt_init_reader_fn omgr_init_reader;
+static mgmt_init_writer_fn omgr_init_writer;
+static mgmt_free_buf_fn omgr_free_buf;
+
+const struct mgmt_streamer_cfg g_omgr_cbor_cfg = {
+    .alloc_rsp = omgr_alloc_rsp,
+    .trim_front = omgr_trim_front,
+    .reset_buf = omgr_reset_buf,
+    .write_at = omgr_write_at,
+    .init_reader = omgr_init_reader,
+    .init_writer = omgr_init_writer,
+    .free_buf = omgr_free_buf,
+};
 
-#include <mgmt/mgmt.h>
-#include <nmgr_os/nmgr_os.h>
+static void*
+omgr_alloc_rsp(const void *src_buf,  void *req)
+{
+    struct os_mbuf *m;
+    struct os_mbuf *rsp;
 
-#include <cborattr/cborattr.h>
-#include <tinycbor/cbor.h>
-#include <tinycbor/cbor_mbuf_reader.h>
-#include <oic/oc_api.h>
-#include "oicmgr/oicmgr.h"
+    if (!req) {
+        return NULL;
+    }
 
-struct omgr_cbuf {
-    struct mgmt_cbuf ob_mj;
-    struct cbor_mbuf_reader ob_reader;
-};
+    m = (struct os_mbuf *)req;
 
-struct omgr_state {
-    struct os_eventq *os_evq;
-    struct os_task os_task;
-    struct omgr_cbuf os_cbuf;          /* CBOR buffer for NMGR task */
-};
+    rsp = os_msys_get_pkthdr(0, OS_MBUF_USRHDR_LEN(m));
+    if (!rsp) {
+        return NULL;
+    }
 
-static struct omgr_state omgr_state;
+    memcpy(OS_MBUF_USRHDR(rsp), OS_MBUF_USRHDR(m), OS_MBUF_USRHDR_LEN(m));
 
-struct os_eventq *
-mgmt_evq_get(void)
-{
-    return omgr_state.os_evq;
+    return req;
 }
 
-void
-mgmt_evq_set(struct os_eventq *evq)
+static void
+omgr_trim_front(void *m, size_t len, void *arg)
 {
-    omgr_state.os_evq = evq;
+    os_mbuf_adj(m, len);
 }
 
-static int
-omgr_oic_read_hdr(struct CborValue *cv, struct nmgr_hdr *out_hdr)
+static void
+omgr_reset_buf(void *m, void *arg)
 {
-    size_t hlen;
-    int rc;
-
-    struct cbor_attr_t attrs[] = {
-        [0] = {
-            .attribute = "_h",
-            .type = CborAttrByteStringType,
-            .addr.bytestring.data = (void *)out_hdr,
-            .addr.bytestring.len = &hlen,
-            .nodefault = 1,
-            .len = sizeof *out_hdr,
-        },
-        [1] = { 0 }
-    };
-
-    rc = cbor_read_object(cv, attrs);
-    if (rc != 0 || hlen != sizeof *out_hdr) {
-        return MGMT_ERR_EINVAL;
+    if (!m) {
+        return;
     }
 
-    out_hdr->nh_len = ntohs(out_hdr->nh_len);
-    out_hdr->nh_group = ntohs(out_hdr->nh_group);
-
-    return 0;
+    /* We need to trim from the back because the head
+     * costains useful information which we do not wast
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to