diff --git a/features/nfc/nfc/NFCNDEFCapable.h b/features/nfc/nfc/NFCNDEFCapable.h index 6f81944ac7..bd900b941b 100644 --- a/features/nfc/nfc/NFCNDEFCapable.h +++ b/features/nfc/nfc/NFCNDEFCapable.h @@ -36,40 +36,55 @@ namespace nfc { public: /** * Check if this instance actually supports NDEF content. + * * @return whether NDEF content is supported */ virtual bool is_ndef_supported() const { return false; } - /** - * Set the instance of the parser which should handle incoming NDEF messages. - * If set to NULL, incoming NDEF messages will be rejected - * @param[in] parser a pointer to the parser to use, or NULL - */ - void set_ndef_message_parser(ndef::MessageParser* parser) const; + struct NFCNDEFCapableDelegate { + /** + * Parse a NDEF message. + * + * @param[in] buffer a buffer containing the message to parse + * @param[in] size the buffer's size + */ + void parse_ndef_message(const uint8_t* buffer, size_t size) { } - /** - * Set the instance of the build which should generate outgoing NDEF messages. - * If set to NULL, outgoing NDEF messages will not be produced - * @param[in] builder a pointer to the builder to use, or NULL - */ - void set_ndef_message_builder(ndef::MessageBuilder* builder) const; + /** + * Build a NDEF message. + * + * @param[in] buffer a mutable buffer in which the message should be stored + * @param[in] capacity the buffer's capacity + * @return the number of bytes actually used + */ + size_t build_ndef_message(uint8_t* buffer, size_t capacity) { return 0; } + }; protected: /** - * Get the NDEF message parser to use, or NULL. - * @return a pointer to a parser, or NULL + * Parse a NDEF message. + * + * @param[in] a buffer containing a NDEF message */ - ndef::MessageParser* ndef_message_parser(); + void parse_ndef_message(const ac_buffer_t& buffer); /** - * Get the NDEF message builder to use, or NULL. - * @return a pointer to a builder, or NULL + * Build NDEF message. + * + * @param[in,out] a buffer builder in which to create the NDEF message. + * The backing buffer is guaranteed to be continuous. */ - ndef::MessageBuilder* ndef_message_builder(); + void build_ndef_message(ac_buffer_builder_t& buffer_builder); + + /** + * Set the delegate that will receive events generated by this class. + * + * @oaram[in] delegate the delegate instance to use + */ + void set_delegate(Delegate* delegate); private: - ndef::MessageParser* _message_parser; - ndef::MessageBuilder* _message_builder; + Delegate* _delegate; }; /**