Mbed OS Reference
Loading...
Searching...
No Matches
NFCNDEFCapable.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2018 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef MBED_NFC_NDEF_CAPABLE_H
19#define MBED_NFC_NDEF_CAPABLE_H
20
21#include <stdint.h>
22
23#include "platform/Span.h"
24
25#include "NFCDefinitions.h"
26
27#include "stack/ndef/ndef.h"
31
32namespace mbed {
33namespace nfc {
34
35/**
36 * @addtogroup nfc
37 * @{
38 */
39
40/**
41 * The base class for all endpoints that can support NDEF content.
42 */
44public:
45 /**
46 * Construct a NFCNDEFCapable instance.
47 * @param[in] buffer a bytes array used to store NDEF messages
48 */
50
51 /**
52 * Check if this instance actually supports NDEF content.
53 *
54 * @return whether NDEF content is supported
55 */
56 virtual bool is_ndef_supported() const
57 {
58 return false;
59 }
60
61 struct Delegate {
62 /**
63 * Parse a NDEF message.
64 *
65 * @param[in] buffer a buffer containing the message to parse
66 */
67 virtual void parse_ndef_message(const Span<const uint8_t> &buffer) { }
68
69 /**
70 * Build a NDEF message.
71 *
72 * @param[in] buffer a mutable buffer in which the message should be stored
73 *
74 * @return the number of bytes actually used
75 */
76 virtual size_t build_ndef_message(const Span<uint8_t> &buffer)
77 {
78 return 0;
79 }
80
81 protected:
82 ~Delegate() {}
83 };
84
85protected:
86 /**
87 * Parse a NDEF message.
88 *
89 * @param[in] buffer a buffer containing a NDEF message
90 */
91 void parse_ndef_message(const ac_buffer_t &buffer);
92
93 /**
94 * Build NDEF message.
95 *
96 * @param[in,out] buffer_builder a buffer builder in which to create the NDEF message.
97 * The backing buffer is guaranteed to be continuous.
98 */
100
101 /**
102 * Retrieve underlying NDEF message instance
103 * @return pointer to NDEF message instance
104 */
106
107private:
108 /**
109 * Get the delegate that will receive events generated by this class.
110 *
111 * @return the delegate instance to use
112 */
113 virtual Delegate *ndef_capable_delegate();
114
115 // Callbacks from NDEF stack
116 static nfc_err_t s_ndef_encode(ndef_msg_t *pTag, ac_buffer_builder_t *pBufferBldr, void *pUserData);
117 static nfc_err_t s_ndef_decode(ndef_msg_t *pTag, ac_buffer_t *pBuffer, void *pUserData);
118 nfc_err_t ndef_encode(ac_buffer_builder_t *pBufferBldr);
119 nfc_err_t ndef_decode(ac_buffer_t *pBuffer);
120
121 ndef_msg_t _ndef_message;
122};
123
124/**
125 * @}
126 */
127
128} // namespace nfc
129} // namespace mbed
130
131#endif
The base class for all endpoints that can support NDEF content.
ndef_msg_t * ndef_message()
Retrieve underlying NDEF message instance.
void parse_ndef_message(const ac_buffer_t &buffer)
Parse a NDEF message.
NFCNDEFCapable(const Span< uint8_t > &buffer)
Construct a NFCNDEFCapable instance.
virtual bool is_ndef_supported() const
Check if this instance actually supports NDEF content.
void build_ndef_message(ac_buffer_builder_t &buffer_builder)
Build NDEF message.
int nfc_err_t
Type for NFC errors.
Definition: nfc_errors.h:60
Nonowning view to a sequence of contiguous elements.
Definition: Span.h:215
virtual void parse_ndef_message(const Span< const uint8_t > &buffer)
Parse a NDEF message.
virtual size_t build_ndef_message(const Span< uint8_t > &buffer)
Build a NDEF message.