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/08 22:55:09 UTC
[19/22] incubator-mynewt-core git commit: BLE ANS service - Use
sysinit.
BLE ANS service - Use sysinit.
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/32b0d33a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/32b0d33a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/32b0d33a
Branch: refs/heads/develop
Commit: 32b0d33a3a409668e9199c9bb6c28a8f5db3d374
Parents: ff4ce46
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Nov 8 14:40:56 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 8 14:40:56 2016 -0800
----------------------------------------------------------------------
.../ans/include/services/ans/ble_svc_ans.h | 4 +-
net/nimble/host/services/ans/pkg.yml | 3 +
net/nimble/host/services/ans/src/ble_svc_ans.c | 65 ++++++++------------
net/nimble/host/services/ans/syscfg.yml | 25 ++++++++
4 files changed, 56 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32b0d33a/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h b/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h
index eaf102a..8d3e3cf 100644
--- a/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h
+++ b/net/nimble/host/services/ans/include/services/ans/ble_svc_ans.h
@@ -79,9 +79,7 @@ int ble_svc_ans_new_alert_add(uint8_t cat_id,
const char * info_str);
int ble_svc_ans_unr_alert_add(uint8_t cat_id);
-int ble_svc_ans_init(struct ble_hs_cfg *cfg,
- uint8_t initial_new_alert_cat,
- uint8_t initial_unr_alert_cat);
+void ble_svc_ans_init(void);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32b0d33a/net/nimble/host/services/ans/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/pkg.yml b/net/nimble/host/services/ans/pkg.yml
index 91a92c6..41a738c 100644
--- a/net/nimble/host/services/ans/pkg.yml
+++ b/net/nimble/host/services/ans/pkg.yml
@@ -29,3 +29,6 @@ pkg.keywords:
pkg.deps:
- net/nimble/host
+
+pkg.init_function: ble_svc_ans_init
+pkg.init_stage: 3
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32b0d33a/net/nimble/host/services/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/src/ble_svc_ans.c b/net/nimble/host/services/ans/src/ble_svc_ans.c
index eae4598..249e2f5 100644
--- a/net/nimble/host/services/ans/src/ble_svc_ans.c
+++ b/net/nimble/host/services/ans/src/ble_svc_ans.c
@@ -20,6 +20,8 @@
#include <assert.h>
#include <string.h>
#include <math.h>
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
#include "host/ble_hs.h"
#include "host/ble_gap.h"
#include "services/ans/ble_svc_ans.h"
@@ -348,44 +350,6 @@ ble_svc_ans_unr_alert_add(uint8_t cat_id)
}
/**
- * Initialize the ANS with initial values for enabled categories
- * for new and unread alert characteristics. Bitwise or the
- * catagory bitmasks to enable multiple catagories.
- *
- * XXX: We should technically be able to change the new alert and
- * unread alert catagories when we have no active connections.
- *
- * @param cfg The host configuration
- * @param initial_new_alert_cat Initial supported new alert category
- * bitmask.
- * @param initial_unr_alert_cat Initial supported unread alert category
- * bitmask.
- *
- * @return 0 on success, non-zero error code otherwise.
- */
-int
-ble_svc_ans_init(struct ble_hs_cfg *cfg, uint8_t initial_new_alert_cat,
- uint8_t initial_unr_alert_cat)
-{
- int rc;
-
- ble_svc_ans_new_alert_cat = initial_new_alert_cat;
- ble_svc_ans_unr_alert_cat = initial_unr_alert_cat;
-
- rc = ble_gatts_count_cfg(ble_svc_ans_defs, cfg);
- if (rc != 0) {
- return rc;
- }
-
- rc = ble_gatts_add_svcs(ble_svc_ans_defs);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-/**
* Send a new alert notification to the given category with the
* given info string.
*
@@ -465,3 +429,28 @@ ble_svc_ans_chr_write(struct os_mbuf *om, uint16_t min_len,
return 0;
}
+
+/**
+ * Initialize the ANS with initial values for enabled categories
+ * for new and unread alert characteristics. Bitwise or the
+ * catagory bitmasks to enable multiple catagories.
+ *
+ * XXX: We should technically be able to change the new alert and
+ * unread alert catagories when we have no active connections.
+ *
+ * @return 0 on success, non-zero error code otherwise.
+ */
+void
+ble_svc_ans_init(void)
+{
+ int rc;
+
+ rc = ble_gatts_count_cfg(ble_svc_ans_defs);
+ SYSINIT_PANIC_ASSERT(rc == 0);
+
+ rc = ble_gatts_add_svcs(ble_svc_ans_defs);
+ SYSINIT_PANIC_ASSERT(rc == 0);
+
+ ble_svc_ans_new_alert_cat = MYNEWT_VAL(BLE_SVC_ANS_NEW_ALERT_CAT);
+ ble_svc_ans_unr_alert_cat = MYNEWT_VAL(BLE_SVC_ANS_UNR_ALERT_CAT);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32b0d33a/net/nimble/host/services/ans/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/syscfg.yml b/net/nimble/host/services/ans/syscfg.yml
new file mode 100644
index 0000000..a77f23d
--- /dev/null
+++ b/net/nimble/host/services/ans/syscfg.yml
@@ -0,0 +1,25 @@
+# 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:
+ BLE_SVC_ANS_NEW_ALERT_CAT:
+ description: "Initial supported new alert category bitmask."
+ value: 0
+
+ BLE_SVC_ANS_UNR_ALERT_CAT:
+ description: "Initial supported unread alert category bitmask."
+ value: 0