From 684b3cad086acb4cc6583f2ab10b2f35545ab660 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Fri, 24 Aug 2018 17:35:55 +0100 Subject: [PATCH] NDEF: Move common types into the namespace ndef::common --- features/nfc/nfc/{ => ndef}/common/Mime.h | 8 +++-- .../{ => ndef}/common/SimpleMessageParser.h | 31 ++++++++++--------- features/nfc/nfc/{ => ndef}/common/Text.h | 8 +++-- features/nfc/nfc/{ => ndef}/common/URI.h | 8 +++-- features/nfc/nfc/{ => ndef}/common/util.h | 2 ++ .../nfc/source/nfc/{ => ndef}/common/Mime.cpp | 12 ++++--- .../{ => ndef}/common/SimpleMessageParser.cpp | 14 +++++---- .../nfc/source/nfc/{ => ndef}/common/Text.cpp | 14 +++++---- .../nfc/source/nfc/{ => ndef}/common/URI.cpp | 14 +++++---- .../nfc/source/nfc/{ => ndef}/common/util.cpp | 4 ++- 10 files changed, 67 insertions(+), 48 deletions(-) rename features/nfc/nfc/{ => ndef}/common/Mime.h (93%) rename features/nfc/nfc/{ => ndef}/common/SimpleMessageParser.h (79%) rename features/nfc/nfc/{ => ndef}/common/Text.h (94%) rename features/nfc/nfc/{ => ndef}/common/URI.h (96%) rename features/nfc/nfc/{ => ndef}/common/util.h (97%) rename features/nfc/source/nfc/{ => ndef}/common/Mime.cpp (93%) rename features/nfc/source/nfc/{ => ndef}/common/SimpleMessageParser.cpp (88%) rename features/nfc/source/nfc/{ => ndef}/common/Text.cpp (93%) rename features/nfc/source/nfc/{ => ndef}/common/URI.cpp (91%) rename features/nfc/source/nfc/{ => ndef}/common/util.cpp (92%) diff --git a/features/nfc/nfc/common/Mime.h b/features/nfc/nfc/ndef/common/Mime.h similarity index 93% rename from features/nfc/nfc/common/Mime.h rename to features/nfc/nfc/ndef/common/Mime.h index ae5a7ba9a5..ee10b765c5 100644 --- a/features/nfc/nfc/common/Mime.h +++ b/features/nfc/nfc/ndef/common/Mime.h @@ -24,6 +24,7 @@ namespace mbed { namespace nfc { +namespace ndef { namespace common { /** @@ -103,7 +104,7 @@ public: * Append into a message builder */ bool append_as_record( - ndef::MessageBuilder &message_builder, + MessageBuilder &message_builder, bool is_last_record = false ); @@ -126,9 +127,9 @@ private: /** * Parse a Mime payload. */ -class MimeParser : public ndef::GenericRecordParser { +class MimeParser : public GenericRecordParser { public: - bool do_parse(const ndef::Record &record, Mime &mime); + bool do_parse(const Record &record, Mime &mime); }; /** @@ -136,6 +137,7 @@ public: */ } // namespace common +} // namespace ndef } // namespace nfc } // namespace mbed diff --git a/features/nfc/nfc/common/SimpleMessageParser.h b/features/nfc/nfc/ndef/common/SimpleMessageParser.h similarity index 79% rename from features/nfc/nfc/common/SimpleMessageParser.h rename to features/nfc/nfc/ndef/common/SimpleMessageParser.h index 003f581a8e..2e9859c9fd 100644 --- a/features/nfc/nfc/common/SimpleMessageParser.h +++ b/features/nfc/nfc/ndef/common/SimpleMessageParser.h @@ -26,6 +26,7 @@ namespace mbed { namespace nfc { +namespace ndef { namespace common { /** @@ -39,7 +40,7 @@ namespace common { * Custom parsers can be added at runtime as well. */ class SimpleMessageParser : - ndef::MessageParser::Delegate, + MessageParser::Delegate, URIParser::Delegate, TextParser::Delegate, MimeParser::Delegate @@ -53,7 +54,7 @@ public: * Invoked when an error is present in the message. * @param error The error present in the message. */ - virtual void on_parsing_error(ndef::MessageParser::error_t error) { } + virtual void on_parsing_error(MessageParser::error_t error) { } /** * Invoked when parsing as started. @@ -64,25 +65,25 @@ public: * Invoked when a text element has been parsed. * @param text The text parsed. */ - virtual void on_text_parsed(const Text &text, const ndef::RecordID &id) { } + virtual void on_text_parsed(const Text &text, const RecordID &id) { } /** * Invoked when a text element has been parsed. * @param text The text parsed. */ - virtual void on_uri_parsed(const URI &uri, const ndef::RecordID &id) { } + virtual void on_uri_parsed(const URI &uri, const RecordID &id) { } /** * Invoked when a mime element has been parsed. * @param mime The mime object parsed. */ - virtual void on_mime_parsed(const Mime &mime, const ndef::RecordID &id) { } + virtual void on_mime_parsed(const Mime &mime, const RecordID &id) { } /** * Invoked when an unknown record has been parsed. * @param The record freshly parsed. */ - virtual void on_unknown_record_parsed(const ndef::Record &record) { } + virtual void on_unknown_record_parsed(const Record &record) { } /** * Invoked when parsing is over. @@ -118,49 +119,49 @@ public: * Insert a new parser in the parser chain. * @param parser The parser to add in the parsing chain. */ - void add_record_parser(ndef::RecordParser *parser); + void add_record_parser(RecordParser *parser); private: //////////////////////////////////////////////////////////////////////////// /// Implementation of MessageParser::EventHandler - virtual void on_parsing_error(ndef::MessageParser::error_t error); + virtual void on_parsing_error(MessageParser::error_t error); virtual void on_parsing_started(); - virtual void on_record_parsed(const ndef::Record &record); + virtual void on_record_parsed(const Record &record); virtual void on_parsing_terminated(); //////////////////////////////////////////////////////////////////////////// /// Implementation of URIParser::EventHandler - virtual void on_record_parsed(const URI &uri, const ndef::RecordID &id); + virtual void on_record_parsed(const URI &uri, const RecordID &id); //////////////////////////////////////////////////////////////////////////// /// Implementation of TextParser::EventHandler - virtual void on_record_parsed(const Text &text, const ndef::RecordID &id); + virtual void on_record_parsed(const Text &text, const RecordID &id); //////////////////////////////////////////////////////////////////////////// /// Implementation of MimeParser::EventHandler - virtual void on_record_parsed(const Mime &mime, const ndef::RecordID &id); + virtual void on_record_parsed(const Mime &mime, const RecordID &id); - ndef::MessageParser _message_parser; - ndef::RecordParserChain _record_parser_chain; + MessageParser _message_parser; + RecordParserChain _record_parser_chain; URIParser _uri_parser; TextParser _text_parser; MimeParser _mime_parser; Delegate *_delegate; }; - /** * @} */ } // namespace common +} // namespace ndef } // namespace nfc } // namespace mbed diff --git a/features/nfc/nfc/common/Text.h b/features/nfc/nfc/ndef/common/Text.h similarity index 94% rename from features/nfc/nfc/common/Text.h rename to features/nfc/nfc/ndef/common/Text.h index 0ae9cc6abd..997394d251 100644 --- a/features/nfc/nfc/common/Text.h +++ b/features/nfc/nfc/ndef/common/Text.h @@ -24,6 +24,7 @@ namespace mbed { namespace nfc { +namespace ndef { namespace common { /** @@ -120,7 +121,7 @@ public: * Append into a message builder */ bool append_as_record( - ndef::MessageBuilder &message_builder, + MessageBuilder &message_builder, bool is_last_record = false ); @@ -136,9 +137,9 @@ private: /** * Parse a Text. */ -class TextParser : public ndef::GenericRecordParser { +class TextParser : public GenericRecordParser { public: - virtual bool do_parse(const ndef::Record &record, Text &text); + virtual bool do_parse(const Record &record, Text &text); }; /** @@ -146,6 +147,7 @@ public: */ } // namespace common +} // namespace ndef } // namespace nfc } // namespace mbed diff --git a/features/nfc/nfc/common/URI.h b/features/nfc/nfc/ndef/common/URI.h similarity index 96% rename from features/nfc/nfc/common/URI.h rename to features/nfc/nfc/ndef/common/URI.h index c7d6107c8b..df10e064cc 100644 --- a/features/nfc/nfc/common/URI.h +++ b/features/nfc/nfc/ndef/common/URI.h @@ -26,6 +26,7 @@ namespace mbed { namespace nfc { +namespace ndef { namespace common { /** @@ -145,7 +146,7 @@ public: * Append into a message builder */ bool append_as_record( - ndef::MessageBuilder &message_builder, + MessageBuilder &message_builder, bool is_last_record = false ); @@ -181,9 +182,9 @@ private: /** * Parser of a URI. */ -class URIParser : public ndef::GenericRecordParser { +class URIParser : public GenericRecordParser { public: - bool do_parse(const ndef::Record &record, URI &uri); + bool do_parse(const Record &record, URI &uri); }; /** @@ -191,6 +192,7 @@ public: */ } // namespace common +} // namespace ndef } // namespace nfc } // namespace mbed diff --git a/features/nfc/nfc/common/util.h b/features/nfc/nfc/ndef/common/util.h similarity index 97% rename from features/nfc/nfc/common/util.h rename to features/nfc/nfc/ndef/common/util.h index 4526fe0e30..40e38a301a 100644 --- a/features/nfc/nfc/common/util.h +++ b/features/nfc/nfc/ndef/common/util.h @@ -21,6 +21,7 @@ namespace mbed { namespace nfc { +namespace ndef { namespace common { /** @@ -61,6 +62,7 @@ Span span_from_cstr(const char *cstr); */ } // namespace common +} // namespace ndef } // namespace nfc } // namespace mbed diff --git a/features/nfc/source/nfc/common/Mime.cpp b/features/nfc/source/nfc/ndef/common/Mime.cpp similarity index 93% rename from features/nfc/source/nfc/common/Mime.cpp rename to features/nfc/source/nfc/ndef/common/Mime.cpp index 712e881956..ca651c1d77 100644 --- a/features/nfc/source/nfc/common/Mime.cpp +++ b/features/nfc/source/nfc/ndef/common/Mime.cpp @@ -20,6 +20,7 @@ namespace mbed { namespace nfc { +namespace ndef { namespace common { Mime::Mime() : @@ -92,12 +93,12 @@ Span Mime::get_mime_content() const } bool Mime::append_as_record( - ndef::MessageBuilder &message_builder, + MessageBuilder &message_builder, bool is_last_record ) { return message_builder.append_record( - ndef::RecordType( - ndef::RecordType::media_type, + RecordType( + RecordType::media_type, get_mime_type() ), get_mime_content(), @@ -121,9 +122,9 @@ size_t Mime::mime_size() const return _type_size + _content_size; } -bool MimeParser::do_parse(const ndef::Record &record, Mime &mime) +bool MimeParser::do_parse(const Record &record, Mime &mime) { - if (record.type.tnf != ndef::RecordType::media_type) { + if (record.type.tnf != RecordType::media_type) { return false; } @@ -149,5 +150,6 @@ bool MimeParser::do_parse(const ndef::Record &record, Mime &mime) } } // namespace common +} // namespace ndef } // namespace nfc } // namespace mbed diff --git a/features/nfc/source/nfc/common/SimpleMessageParser.cpp b/features/nfc/source/nfc/ndef/common/SimpleMessageParser.cpp similarity index 88% rename from features/nfc/source/nfc/common/SimpleMessageParser.cpp rename to features/nfc/source/nfc/ndef/common/SimpleMessageParser.cpp index 62b6b4a77c..867e9f4d73 100644 --- a/features/nfc/source/nfc/common/SimpleMessageParser.cpp +++ b/features/nfc/source/nfc/ndef/common/SimpleMessageParser.cpp @@ -18,6 +18,7 @@ namespace mbed { namespace nfc { +namespace ndef { namespace common { SimpleMessageParser::SimpleMessageParser() : @@ -50,12 +51,12 @@ void SimpleMessageParser::parse(const Span &data_buffer) _message_parser.parse(data_buffer); } -void SimpleMessageParser::add_record_parser(ndef::RecordParser *parser) +void SimpleMessageParser::add_record_parser(RecordParser *parser) { _record_parser_chain.set_next_parser(parser); } -void SimpleMessageParser::on_parsing_error(ndef::MessageParser::error_t error) +void SimpleMessageParser::on_parsing_error(MessageParser::error_t error) { if (_delegate) { _delegate->on_parsing_error(error); @@ -69,7 +70,7 @@ void SimpleMessageParser::on_parsing_started() } } -void SimpleMessageParser::on_record_parsed(const ndef::Record &record) +void SimpleMessageParser::on_record_parsed(const Record &record) { bool parsed = _record_parser_chain.parse(record); @@ -87,7 +88,7 @@ void SimpleMessageParser::on_parsing_terminated() void SimpleMessageParser::on_record_parsed( const URI &uri, - const ndef::RecordID &id + const RecordID &id ) { if (_delegate) { _delegate->on_uri_parsed(uri, id); @@ -96,7 +97,7 @@ void SimpleMessageParser::on_record_parsed( void SimpleMessageParser::on_record_parsed( const Text &text, - const ndef::RecordID &id + const RecordID &id ) { if (_delegate) { _delegate->on_text_parsed(text, id); @@ -105,7 +106,7 @@ void SimpleMessageParser::on_record_parsed( void SimpleMessageParser::on_record_parsed( const Mime &mime, - const ndef::RecordID &id + const RecordID &id ) { if (_delegate) { _delegate->on_mime_parsed(mime, id); @@ -113,6 +114,7 @@ void SimpleMessageParser::on_record_parsed( } } // namespace common +} // namespace ndef } // namespace nfc } // namespace mbed diff --git a/features/nfc/source/nfc/common/Text.cpp b/features/nfc/source/nfc/ndef/common/Text.cpp similarity index 93% rename from features/nfc/source/nfc/common/Text.cpp rename to features/nfc/source/nfc/ndef/common/Text.cpp index 384b0273d6..bc7e0550b8 100644 --- a/features/nfc/source/nfc/common/Text.cpp +++ b/features/nfc/source/nfc/ndef/common/Text.cpp @@ -29,6 +29,7 @@ static const uint8_t text_record_type_value[] = { 'T' }; namespace mbed { namespace nfc { +namespace ndef { namespace common { Text::Text() : @@ -129,23 +130,23 @@ void Text::move_data(uint8_t *text, size_t size) { } bool Text::append_as_record( - ndef::MessageBuilder &message_builder, + MessageBuilder &message_builder, bool is_last_record ) { // Build the record type - ndef::RecordType type( - ndef::RecordType::well_known_type, + RecordType type( + RecordType::well_known_type, text_record_type_value ); // build the record payload - ndef::RecordPayload payload(_text_record, _text_record_size); + RecordPayload payload(_text_record, _text_record_size); return message_builder.append_record(type, payload, is_last_record); } -bool TextParser::do_parse(const ndef::Record &record, Text &text) +bool TextParser::do_parse(const Record &record, Text &text) { - if (record.type.tnf != ndef::RecordType::well_known_type) { + if (record.type.tnf != RecordType::well_known_type) { return false; } @@ -167,5 +168,6 @@ bool TextParser::do_parse(const ndef::Record &record, Text &text) } } // namespace common +} // namespace ndef } // namespace nfc } // namespace mbed diff --git a/features/nfc/source/nfc/common/URI.cpp b/features/nfc/source/nfc/ndef/common/URI.cpp similarity index 91% rename from features/nfc/source/nfc/common/URI.cpp rename to features/nfc/source/nfc/ndef/common/URI.cpp index b13e03f0ef..ccd6ad953f 100644 --- a/features/nfc/source/nfc/common/URI.cpp +++ b/features/nfc/source/nfc/ndef/common/URI.cpp @@ -26,6 +26,7 @@ static const uint8_t uri_record_type_value[] = { 'U' } ; namespace mbed { namespace nfc { +namespace ndef { namespace common { URI::URI() : @@ -107,20 +108,20 @@ Span URI::get_uri_field() const ); } -bool URI::append_as_record(ndef::MessageBuilder &message_builder, bool is_last_record) +bool URI::append_as_record(MessageBuilder &message_builder, bool is_last_record) { if (!_uri) { return false; } // Build the record type - ndef::RecordType type( - ndef::RecordType::well_known_type, + RecordType type( + RecordType::well_known_type, uri_record_type_value ); // build the record payload - ndef::RecordPayload payload(_uri, _uri_size); + RecordPayload payload(_uri, _uri_size); return message_builder.append_record(type, payload, is_last_record); } @@ -132,9 +133,9 @@ void URI::move_data(uint8_t *new_uri, size_t new_uri_size) _uri_size = new_uri_size; } -bool URIParser::do_parse(const ndef::Record &record, URI &uri) +bool URIParser::do_parse(const Record &record, URI &uri) { - if (record.type.tnf != ndef::RecordType::well_known_type) { + if (record.type.tnf != RecordType::well_known_type) { return false; } @@ -156,6 +157,7 @@ bool URIParser::do_parse(const ndef::Record &record, URI &uri) } } // namespace common +} // namespace ndef } // namespace nfc } // namespace mbed diff --git a/features/nfc/source/nfc/common/util.cpp b/features/nfc/source/nfc/ndef/common/util.cpp similarity index 92% rename from features/nfc/source/nfc/common/util.cpp rename to features/nfc/source/nfc/ndef/common/util.cpp index 728e65768f..34dd815102 100644 --- a/features/nfc/source/nfc/common/util.cpp +++ b/features/nfc/source/nfc/ndef/common/util.cpp @@ -14,12 +14,13 @@ * limitations under the License. */ -#include "nfc/common/util.h" +#include "nfc/ndef/common/util.h" #include namespace mbed { namespace nfc { +namespace ndef { namespace common { Span span_from_cstr(const char *cstr) @@ -32,6 +33,7 @@ Span span_from_cstr(const char *cstr) */ } // namespace common +} // namespace ndef } // namespace nfc } // namespace mbed