This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit d614ee1118dcc623d474b0ad7eb7e3441f1b1794
Author: Szymon Janc <[email protected]>
AuthorDate: Tue Oct 6 19:05:07 2026 +0200

    mgmt/mcumgr/stat_mgmt: Remove OS abstraction layer
    
    mcumgr is now part of Mynewt core and there is no need for OS
    abstraction layer. Mynewt implementation is merged into stat_mgmt.c
    and stat_mgmt_impl_* functions are made static. stat_mgmt_config.h is
    removed and syscfg values are used directly. Weak stubs and Mynewt
    port package are removed.
    
    STAT_MGMT_SYSINIT_STAGE setting and package init are moved from port
    package to stat_mgmt package.
    
    No functional changes.
    
    Assisted-by: Claude:claude-opus-5-5
---
 .../stat_mgmt/include/stat_mgmt/stat_mgmt_config.h |  41 --------
 .../stat_mgmt/include/stat_mgmt/stat_mgmt_impl.h   |  70 -------------
 mgmt/mcumgr/cmd/stat_mgmt/pkg.yml                  |   4 +-
 mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/pkg.yml      |  31 ------
 .../stat_mgmt/port/mynewt/src/mynewt_stat_mgmt.c   | 116 ---------------------
 mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/syscfg.yml   |  24 -----
 mgmt/mcumgr/cmd/stat_mgmt/src/stat_mgmt.c          | 100 +++++++++++++++++-
 mgmt/mcumgr/cmd/stat_mgmt/src/stubs.c              |  40 -------
 mgmt/mcumgr/cmd/stat_mgmt/syscfg.yml               |   5 +
 9 files changed, 103 insertions(+), 328 deletions(-)

diff --git a/mgmt/mcumgr/cmd/stat_mgmt/include/stat_mgmt/stat_mgmt_config.h 
b/mgmt/mcumgr/cmd/stat_mgmt/include/stat_mgmt/stat_mgmt_config.h
deleted file mode 100644
index 6c7cbcaef..000000000
--- a/mgmt/mcumgr/cmd/stat_mgmt/include/stat_mgmt/stat_mgmt_config.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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 H_STAT_MGMT_CONFIG_
-#define H_STAT_MGMT_CONFIG_
-
-#if defined MYNEWT
-
-#include "syscfg/syscfg.h"
-
-#define STAT_MGMT_MAX_NAME_LEN  MYNEWT_VAL(STAT_MGMT_MAX_NAME_LEN)
-
-#elif defined __ZEPHYR__
-
-#define STAT_MGMT_MAX_NAME_LEN  CONFIG_STAT_MGMT_MAX_NAME_LEN
-
-#else
-
-/* No direct support for this OS.  The application needs to define the above
- * settings itself.
- */
-
-#endif
-
-#endif
diff --git a/mgmt/mcumgr/cmd/stat_mgmt/include/stat_mgmt/stat_mgmt_impl.h 
b/mgmt/mcumgr/cmd/stat_mgmt/include/stat_mgmt/stat_mgmt_impl.h
deleted file mode 100644
index d60707a49..000000000
--- a/mgmt/mcumgr/cmd/stat_mgmt/include/stat_mgmt/stat_mgmt_impl.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.
- */
-
-/**
- * @file
- * @brief Declares implementation-specific functions required by statistics
- *        management.  The default stubs can be overridden with functions that
- *        are compatible with the host OS.
- */
-
-#ifndef H_STAT_MGMT_IMPL_
-#define H_STAT_MGMT_IMPL_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct stat_mgmt_entry;
-
-typedef int stat_mgmt_foreach_entry_fn(struct stat_mgmt_entry *entry,
-                                       void *arg);
-
-/**
- * @brief Retrieves the name of the stat group at the specified index.
- *
- * @param idx                   The index of the stat group to retrieve.
- * @param out_name              On success, the name of the requested stat
- *                                  group gets written here.
- *
- * @return                      0 on success;
- *                              MGMT_ERR_ENOENT if no group with the specified
- *                                  index exists;
- *                              Other MGMT_ERR_[...] code on failure.
- */
-int stat_mgmt_impl_get_group(int idx, const char **out_name);
-
-/**
- * @brief Applies a function to every entry in the specified stat group.
- *
- * @param group_name            The name of the stat group to operate on.
- * @param cb                    The callback to apply to each stat entry.
- * @param arg                   An optional argument to pass to the callback.
- *
- * @return                      0 on success; MGMT_ERR_[...] code on failure.
- */
-int stat_mgmt_impl_foreach_entry(const char *group_name,
-                                 stat_mgmt_foreach_entry_fn *cb,
-                                 void *arg);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/mgmt/mcumgr/cmd/stat_mgmt/pkg.yml 
b/mgmt/mcumgr/cmd/stat_mgmt/pkg.yml
index d75234e2f..64996ed93 100644
--- a/mgmt/mcumgr/cmd/stat_mgmt/pkg.yml
+++ b/mgmt/mcumgr/cmd/stat_mgmt/pkg.yml
@@ -25,5 +25,7 @@ pkg.keywords:
 
 pkg.deps:
     - '@apache-mynewt-core/kernel/os'
-    - '@apache-mynewt-core/mgmt/mcumgr/cmd/stat_mgmt/port/mynewt'
     - '@apache-mynewt-core/mgmt/mcumgr/mgmt'
+
+pkg.init:
+    stat_mgmt_module_init: 'MYNEWT_VAL(STAT_MGMT_SYSINIT_STAGE)'
diff --git a/mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/pkg.yml 
b/mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/pkg.yml
deleted file mode 100644
index f20a5ba06..000000000
--- a/mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/pkg.yml
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# 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.
-#
-
-pkg.name: mgmt/mcumgr/cmd/stat_mgmt/port/mynewt
-pkg.description: 'Statistics management command handlers for mcumgr.'
-pkg.author: "Apache Mynewt <[email protected]>"
-pkg.homepage: "http://mynewt.apache.org/";
-pkg.keywords:
-
-pkg.deps:
-    - '@apache-mynewt-core/mgmt/mcumgr/cmd/stat_mgmt'
-    - '@apache-mynewt-core/mgmt/mcumgr/mgmt'
-
-pkg.init:
-    stat_mgmt_module_init: 'MYNEWT_VAL(STAT_MGMT_SYSINIT_STAGE)'
diff --git a/mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/src/mynewt_stat_mgmt.c 
b/mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/src/mynewt_stat_mgmt.c
deleted file mode 100644
index d9231ae56..000000000
--- a/mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/src/mynewt_stat_mgmt.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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.
- */
-
-
-#include "stats/stats.h"
-#include "mgmt/mgmt.h"
-#include "sysinit/sysinit.h"
-#include "stat_mgmt/stat_mgmt.h"
-#include "stat_mgmt/stat_mgmt_impl.h"
-#include "stat_mgmt/stat_mgmt_config.h"
-
-struct mynewt_stat_mgmt_walk_arg {
-    stat_mgmt_foreach_entry_fn *cb;
-    void *arg;
-};
-
-int
-stat_mgmt_impl_get_group(int idx, const char **out_name)
-{
-    const struct stats_hdr *cur;
-    int i;
-    int rc;
-
-    rc = MGMT_ERR_ENOENT;
-
-    cur = NULL;
-    i = 0;
-    STAILQ_FOREACH(cur, &g_stats_registry, s_next) {
-        if (i == idx) {
-            rc = 0;
-            break;
-        }
-        i++;
-    }
-
-    if (!rc) {
-        *out_name = cur->s_name;
-    }
-
-    return rc;
-}
-
-static int
-mynewt_stat_mgmt_walk_cb(struct stats_hdr *hdr, void *arg,
-                         char *name, uint16_t off)
-{
-    struct mynewt_stat_mgmt_walk_arg *walk_arg;
-    struct stat_mgmt_entry entry;
-    void *stat_val;
-
-    walk_arg = arg;
-
-    stat_val = (uint8_t *)hdr + off;
-    switch (hdr->s_size) {
-    case sizeof (uint16_t):
-        entry.value = *(uint16_t *) stat_val;
-        break;
-    case sizeof (uint32_t):
-        entry.value = *(uint32_t *) stat_val;
-        break;
-    case sizeof (uint64_t):
-        entry.value = *(uint64_t *) stat_val;
-        break;
-    default:
-        return MGMT_ERR_EUNKNOWN;
-    }
-    entry.name = name;
-
-    return walk_arg->cb(&entry, walk_arg->arg);
-}
-
-int
-stat_mgmt_impl_foreach_entry(const char *group_name,
-                             stat_mgmt_foreach_entry_fn *cb,
-                             void *arg)
-{
-    struct mynewt_stat_mgmt_walk_arg walk_arg;
-    struct stats_hdr *hdr;
-
-    hdr = stats_group_find(group_name);
-    if (hdr == NULL) {
-        return MGMT_ERR_ENOENT;
-    }
-
-    walk_arg = (struct mynewt_stat_mgmt_walk_arg) {
-        .cb = cb,
-        .arg = arg,
-    };
-
-    return stats_walk(hdr, mynewt_stat_mgmt_walk_cb, &walk_arg);
-}
-
-void
-stat_mgmt_module_init(void)
-{
-    /* Ensure this function only gets called by sysinit. */
-    SYSINIT_ASSERT_ACTIVE();
-
-    stat_mgmt_register_group();
-}
diff --git a/mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/syscfg.yml 
b/mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/syscfg.yml
deleted file mode 100644
index 7b704ed78..000000000
--- a/mgmt/mcumgr/cmd/stat_mgmt/port/mynewt/syscfg.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-#
-# 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.defs:
-    STAT_MGMT_SYSINIT_STAGE:
-        description: >
-            System Initialization stage for STAT_MGMT package
-        value: 501
diff --git a/mgmt/mcumgr/cmd/stat_mgmt/src/stat_mgmt.c 
b/mgmt/mcumgr/cmd/stat_mgmt/src/stat_mgmt.c
index 7fad709e5..3307497ee 100644
--- a/mgmt/mcumgr/cmd/stat_mgmt/src/stat_mgmt.c
+++ b/mgmt/mcumgr/cmd/stat_mgmt/src/stat_mgmt.c
@@ -20,11 +20,92 @@
 #include <string.h>
 #include <stdio.h>
 
+#include "os/mynewt.h"
+#include "stats/stats.h"
 #include "mgmt/mgmt.h"
 #include "cborattr/cborattr.h"
 #include "stat_mgmt/stat_mgmt.h"
-#include "stat_mgmt/stat_mgmt_impl.h"
-#include "stat_mgmt/stat_mgmt_config.h"
+
+typedef int stat_mgmt_foreach_entry_fn(struct stat_mgmt_entry *entry, void 
*arg);
+
+struct stat_mgmt_walk_arg {
+    stat_mgmt_foreach_entry_fn *cb;
+    void *arg;
+};
+
+static int
+stat_mgmt_get_group(int idx, const char **out_name)
+{
+    const struct stats_hdr *cur;
+    int i;
+    int rc;
+
+    rc = MGMT_ERR_ENOENT;
+
+    cur = NULL;
+    i = 0;
+    STAILQ_FOREACH(cur, &g_stats_registry, s_next) {
+        if (i == idx) {
+            rc = 0;
+            break;
+        }
+        i++;
+    }
+
+    if (!rc) {
+        *out_name = cur->s_name;
+    }
+
+    return rc;
+}
+
+static int
+stat_mgmt_walk_cb(struct stats_hdr *hdr, void *arg, char *name, uint16_t off)
+{
+    struct stat_mgmt_walk_arg *walk_arg;
+    struct stat_mgmt_entry entry;
+    void *stat_val;
+
+    walk_arg = arg;
+
+    stat_val = (uint8_t *)hdr + off;
+    switch (hdr->s_size) {
+    case sizeof(uint16_t):
+        entry.value = *(uint16_t *)stat_val;
+        break;
+    case sizeof(uint32_t):
+        entry.value = *(uint32_t *)stat_val;
+        break;
+    case sizeof(uint64_t):
+        entry.value = *(uint64_t *)stat_val;
+        break;
+    default:
+        return MGMT_ERR_EUNKNOWN;
+    }
+    entry.name = name;
+
+    return walk_arg->cb(&entry, walk_arg->arg);
+}
+
+static int
+stat_mgmt_foreach_entry(const char *group_name, stat_mgmt_foreach_entry_fn *cb,
+                        void *arg)
+{
+    struct stat_mgmt_walk_arg walk_arg;
+    struct stats_hdr *hdr;
+
+    hdr = stats_group_find(group_name);
+    if (hdr == NULL) {
+        return MGMT_ERR_ENOENT;
+    }
+
+    walk_arg = (struct stat_mgmt_walk_arg){
+        .cb = cb,
+        .arg = arg,
+    };
+
+    return stats_walk(hdr, stat_mgmt_walk_cb, &walk_arg);
+}
 
 static mgmt_handler_fn stat_mgmt_show;
 static mgmt_handler_fn stat_mgmt_list;
@@ -68,7 +149,7 @@ stat_mgmt_cb_encode(struct stat_mgmt_entry *entry, void *arg)
 static int
 stat_mgmt_show(struct mgmt_ctxt *ctxt)
 {
-    char stat_name[STAT_MGMT_MAX_NAME_LEN];
+    char stat_name[MYNEWT_VAL(STAT_MGMT_MAX_NAME_LEN)];
     CborEncoder map_enc;
     CborError err;
     int rc;
@@ -95,7 +176,7 @@ stat_mgmt_show(struct mgmt_ctxt *ctxt)
     err |= cbor_encode_text_stringz(&ctxt->encoder, "fields");
     err |= cbor_encoder_create_map(&ctxt->encoder, &map_enc, 
CborIndefiniteLength);
 
-    rc = stat_mgmt_impl_foreach_entry(stat_name, stat_mgmt_cb_encode, 
&map_enc);
+    rc = stat_mgmt_foreach_entry(stat_name, stat_mgmt_cb_encode, &map_enc);
 
     err |= cbor_encoder_close_container(&ctxt->encoder, &map_enc);
     if (err != 0) {
@@ -127,7 +208,7 @@ stat_mgmt_list(struct mgmt_ctxt *ctxt)
      * array.
      */
     for (i = 0;; i++) {
-        rc = stat_mgmt_impl_get_group(i, &group_name);
+        rc = stat_mgmt_get_group(i, &group_name);
         if (rc == MGMT_ERR_ENOENT) {
             /* No more stat groups. */
             break;
@@ -152,3 +233,12 @@ stat_mgmt_register_group(void)
 {
     mgmt_register_group(&stat_mgmt_group);
 }
+
+void
+stat_mgmt_module_init(void)
+{
+    /* Ensure this function only gets called by sysinit. */
+    SYSINIT_ASSERT_ACTIVE();
+
+    stat_mgmt_register_group();
+}
diff --git a/mgmt/mcumgr/cmd/stat_mgmt/src/stubs.c 
b/mgmt/mcumgr/cmd/stat_mgmt/src/stubs.c
deleted file mode 100644
index 906056fd3..000000000
--- a/mgmt/mcumgr/cmd/stat_mgmt/src/stubs.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.
- */
-
-/**
- * These stubs get linked in when there is no equivalent OS-specific
- * implementation.
- */
-
-#include "mgmt/mgmt.h"
-#include "stat_mgmt/stat_mgmt_impl.h"
-
-int __attribute__((weak))
-stat_mgmt_impl_get_group(int idx, const char **out_name)
-{
-    return MGMT_ERR_ENOTSUP;
-}
-
-int __attribute__((weak))
-stat_mgmt_impl_foreach_entry(const char *stat_name,
-                             stat_mgmt_foreach_entry_fn *cb,
-                             void *arg)
-{
-    return MGMT_ERR_ENOTSUP;
-}
diff --git a/mgmt/mcumgr/cmd/stat_mgmt/syscfg.yml 
b/mgmt/mcumgr/cmd/stat_mgmt/syscfg.yml
index 5fd9f0619..9f7b18ff3 100644
--- a/mgmt/mcumgr/cmd/stat_mgmt/syscfg.yml
+++ b/mgmt/mcumgr/cmd/stat_mgmt/syscfg.yml
@@ -24,3 +24,8 @@ syscfg.defs:
             stat read commands.  If a stat group's name exceeds this limit, it 
will
             be impossible to retrieve its values with a stat show command.
         value: 32
+
+    STAT_MGMT_SYSINIT_STAGE:
+        description: >
+            System Initialization stage for STAT_MGMT package
+        value: 501

Reply via email to