Dawn Framework 1.0
Universal data acquisition framework for embedded systems
prph_dis.cxx
1// dawn/src/proto/nimble/prph_dis.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/proto/nimble/prph_dis.hxx"
7
8using namespace dawn;
9
10extern "C"
11{
12 // Device Information Service Implementation
13
14 void ble_svc_dis_init();
15};
16
17// Assumption: Configuration item passed by caller is a valid type supported by
18// This class.
19void CProtoNimblePrphDis::configureDesc(const SObjectCfg::SObjectCfgItem *item)
20{
21 // Nothing here
22}
23
24CProtoNimblePrphDis::CProtoNimblePrphDis(const SObjectCfg::SObjectCfgItem *desc_,
26 : IProtoNimblePrphService(desc_, cb_)
27{
28 // Service ID not assigned yet
29
30 id = -1;
31}
32
33CProtoNimblePrphDis::~CProtoNimblePrphDis()
34{
35 deinit();
36}
37
39{
40 // ble_svc_dis_init() touches NimBLE singleton state and must run at most
41 // once per stack lifetime, regardless of how many DIS objects exist.
42
43 static bool s_dis_initialized = false;
44
45 // Configure object
46
47 configureDesc(desc);
48
49 if (!s_dis_initialized)
50 {
51 ble_svc_dis_init();
52 s_dis_initialized = true;
53 }
54
55 // Register servie in peripheral handler
56
57 id = cb->serviceRegister(nullptr);
58 if (id < 0)
59 {
60 DAWNERR("DIS service registration failed\n");
61 return -EIO;
62 }
63
64 return OK;
65}
66
68{
69 return OK;
70}
71
73{
74 // Signal start to peripheral handler
75
76 return cb->startService(id);
77}
78
80{
81 // Signal stop to peripheral handler
82
83 return cb->stopService(id);
84}
int deinit()
Deinitialize service.
Definition prph_dis.cxx:67
int start()
Start service.
Definition prph_dis.cxx:72
int init()
Initialize service.
Definition prph_dis.cxx:38
int stop()
Stop service.
Definition prph_dis.cxx:79
Interface for BLE peripheral services with GATT characteristics.
Definition iprph.hxx:24
virtual int startService(int id)=0
Start a specific service.
virtual int serviceRegister(struct ble_gatt_svc_def *svc)=0
Register a GATT service with the peripheral.
virtual int stopService(int id)=0
Stop a specific service.
Base interface for GATT services exposed by BLE peripheral.
Definition iprph.hxx:467
const SObjectCfg::SObjectCfgItem * desc
Configuration descriptor for this service.
Definition iprph.hxx:574
IProtoNimblePrphCb * cb
Callback interface to peripheral.
Definition iprph.hxx:566
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Single configuration item within object.