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

[20/27] incubator-mynewt-core git commit: oic; change oc_rep_objects pool to be os_mempool.

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();