NDEF: Move common types into the namespace ndef::common

pull/7822/head
Vincent Coubard 2018-08-24 17:35:55 +01:00 committed by Donatien Garnier
parent 3770cfb963
commit 684b3cad08
10 changed files with 67 additions and 48 deletions

View File

@ -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<MimeParser, Mime> {
class MimeParser : public GenericRecordParser<MimeParser, Mime> {
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

View File

@ -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

View File

@ -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<TextParser, Text> {
class TextParser : public GenericRecordParser<TextParser, Text> {
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

View File

@ -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<URIParser, URI> {
class URIParser : public GenericRecordParser<URIParser, URI> {
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

View File

@ -21,6 +21,7 @@
namespace mbed {
namespace nfc {
namespace ndef {
namespace common {
/**
@ -61,6 +62,7 @@ Span<const uint8_t> span_from_cstr(const char *cstr);
*/
} // namespace common
} // namespace ndef
} // namespace nfc
} // namespace mbed

View File

@ -20,6 +20,7 @@
namespace mbed {
namespace nfc {
namespace ndef {
namespace common {
Mime::Mime() :
@ -92,12 +93,12 @@ Span<const uint8_t> 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

View File

@ -18,6 +18,7 @@
namespace mbed {
namespace nfc {
namespace ndef {
namespace common {
SimpleMessageParser::SimpleMessageParser() :
@ -50,12 +51,12 @@ void SimpleMessageParser::parse(const Span<const uint8_t> &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

View File

@ -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

View File

@ -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<const uint8_t> 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

View File

@ -14,12 +14,13 @@
* limitations under the License.
*/
#include "nfc/common/util.h"
#include "nfc/ndef/common/util.h"
#include <cstring>
namespace mbed {
namespace nfc {
namespace ndef {
namespace common {
Span<const uint8_t> span_from_cstr(const char *cstr)
@ -32,6 +33,7 @@ Span<const uint8_t> span_from_cstr(const char *cstr)
*/
} // namespace common
} // namespace ndef
} // namespace nfc
} // namespace mbed