Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: nRF51_Vdd TextLCD BME280
SimpleMessageParser.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef NFC_COMMON_SIMPLEMESSAGEPARSER_H_ 00018 #define NFC_COMMON_SIMPLEMESSAGEPARSER_H_ 00019 00020 #include "platform/Span.h" 00021 00022 #include "nfc/ndef/MessageParser.h" 00023 #include "nfc/ndef/RecordParser.h" 00024 #include "nfc/ndef/common/URI.h" 00025 #include "nfc/ndef/common/Text.h" 00026 #include "nfc/ndef/common/Mime.h" 00027 00028 namespace mbed { 00029 namespace nfc { 00030 namespace ndef { 00031 namespace common { 00032 00033 /** 00034 * @addtogroup nfc 00035 * @{ 00036 */ 00037 00038 /** 00039 * Basic message parser that aggregates URIParser, TextParser and MimeParser. 00040 * 00041 * Custom parsers can be added at runtime as well. 00042 */ 00043 class SimpleMessageParser : 00044 MessageParser::Delegate, 00045 URIParser::Delegate, 00046 TextParser::Delegate, 00047 MimeParser::Delegate { 00048 public: 00049 /** 00050 * Delegate invoked when the parser raise an event. 00051 */ 00052 struct Delegate { 00053 /** 00054 * Invoked when an error is present in the message. 00055 * @param error The error present in the message. 00056 */ 00057 virtual void on_parsing_error(MessageParser::error_t error) { } 00058 00059 /** 00060 * Invoked when parsing as started. 00061 */ 00062 virtual void on_parsing_started() { } 00063 00064 /** 00065 * Invoked when a text element has been parsed. 00066 * 00067 * @param text The text parsed. 00068 * @param id The RecordId of the text object. 00069 */ 00070 virtual void on_text_parsed(const Text &text, const RecordID &id) { } 00071 00072 /** 00073 * Invoked when a text element has been parsed. 00074 * 00075 * @param uri The uri parsed. 00076 * @param id The RecordId of the uri object. 00077 */ 00078 virtual void on_uri_parsed(const URI &uri, const RecordID &id) { } 00079 00080 /** 00081 * Invoked when a mime element has been parsed. 00082 * 00083 * @param mime The mime object parsed. 00084 * @param id The RecordId of the mime object. 00085 */ 00086 virtual void on_mime_parsed(const Mime &mime, const RecordID &id) { } 00087 00088 /** 00089 * Invoked when an unknown record has been parsed. 00090 * @param record The record freshly parsed. 00091 */ 00092 virtual void on_unknown_record_parsed(const Record &record) { } 00093 00094 /** 00095 * Invoked when parsing is over. 00096 */ 00097 virtual void on_parsing_terminated() { } 00098 00099 protected: 00100 ~Delegate() { } 00101 }; 00102 00103 /** 00104 * Construct a new CommonMessageParser. 00105 */ 00106 SimpleMessageParser(); 00107 00108 /** 00109 * Set the handler that processes parsing events. 00110 * @param delegate The parsing event handler. 00111 */ 00112 void set_delegate(Delegate *delegate); 00113 00114 /** 00115 * Parse an NDEF Message. 00116 * 00117 * Records and errors are reported to the handler registered with 00118 * set_event_handler. 00119 * 00120 * @param data_buffer The data buffer that contains the NDEF message. 00121 */ 00122 void parse(const Span<const uint8_t> &data_buffer); 00123 00124 /** 00125 * Insert a new parser in the parser chain. 00126 * @param parser The parser to add in the parsing chain. 00127 */ 00128 void add_record_parser(RecordParser *parser); 00129 00130 private: 00131 //////////////////////////////////////////////////////////////////////////// 00132 /// Implementation of MessageParser::EventHandler 00133 00134 virtual void on_parsing_error(MessageParser::error_t error); 00135 00136 virtual void on_parsing_started(); 00137 00138 virtual void on_record_parsed(const Record &record); 00139 00140 virtual void on_parsing_terminated(); 00141 00142 //////////////////////////////////////////////////////////////////////////// 00143 /// Implementation of URIParser::EventHandler 00144 00145 virtual void on_record_parsed(const URI &uri, const RecordID &id); 00146 00147 //////////////////////////////////////////////////////////////////////////// 00148 /// Implementation of TextParser::EventHandler 00149 00150 virtual void on_record_parsed(const Text &text, const RecordID &id); 00151 00152 //////////////////////////////////////////////////////////////////////////// 00153 /// Implementation of MimeParser::EventHandler 00154 00155 virtual void on_record_parsed(const Mime &mime, const RecordID &id); 00156 00157 MessageParser _message_parser; 00158 RecordParserChain _record_parser_chain; 00159 URIParser _uri_parser; 00160 TextParser _text_parser; 00161 MimeParser _mime_parser; 00162 Delegate *_delegate; 00163 }; 00164 00165 /** 00166 * @} 00167 */ 00168 00169 } // namespace common 00170 } // namespace ndef 00171 } // namespace nfc 00172 } // namespace mbed 00173 00174 #endif /* NFC_COMMON_SIMPLEMESSAGEPARSER_H_ */
Generated on Tue Jul 12 2022 15:15:58 by
