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.
SimpleMessageParser.cpp
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 #include "nfc/ndef/common/SimpleMessageParser.h" 00018 00019 namespace mbed { 00020 namespace nfc { 00021 namespace ndef { 00022 namespace common { 00023 00024 SimpleMessageParser::SimpleMessageParser() : 00025 _message_parser(), 00026 _record_parser_chain(), 00027 _uri_parser(), 00028 _text_parser(), 00029 _mime_parser(), 00030 _delegate(NULL) 00031 { 00032 // setup the parser chain 00033 _record_parser_chain.set_next_parser(&_uri_parser); 00034 _record_parser_chain.set_next_parser(&_text_parser); 00035 _record_parser_chain.set_next_parser(&_mime_parser); 00036 00037 // wire event handling 00038 _message_parser.set_delegate(this); 00039 _uri_parser.set_delegate(this); 00040 _text_parser.set_delegate(this); 00041 _mime_parser.set_delegate(this); 00042 } 00043 00044 void SimpleMessageParser::set_delegate(Delegate *delegate) 00045 { 00046 _delegate = delegate; 00047 } 00048 00049 void SimpleMessageParser::parse(const Span<const uint8_t> &data_buffer) 00050 { 00051 _message_parser.parse(data_buffer); 00052 } 00053 00054 void SimpleMessageParser::add_record_parser(RecordParser *parser) 00055 { 00056 _record_parser_chain.set_next_parser(parser); 00057 } 00058 00059 void SimpleMessageParser::on_parsing_error(MessageParser::error_t error) 00060 { 00061 if (_delegate) { 00062 _delegate->on_parsing_error(error); 00063 } 00064 } 00065 00066 void SimpleMessageParser::on_parsing_started() 00067 { 00068 if (_delegate) { 00069 _delegate->on_parsing_started(); 00070 } 00071 } 00072 00073 void SimpleMessageParser::on_record_parsed(const Record &record) 00074 { 00075 bool parsed = _record_parser_chain.parse(record); 00076 00077 if (!parsed && _delegate) { 00078 _delegate->on_unknown_record_parsed(record); 00079 } 00080 } 00081 00082 void SimpleMessageParser::on_parsing_terminated() 00083 { 00084 if (_delegate) { 00085 _delegate->on_parsing_terminated(); 00086 } 00087 } 00088 00089 void SimpleMessageParser::on_record_parsed( 00090 const URI &uri, 00091 const RecordID &id 00092 ) 00093 { 00094 if (_delegate) { 00095 _delegate->on_uri_parsed(uri, id); 00096 } 00097 } 00098 00099 void SimpleMessageParser::on_record_parsed( 00100 const Text &text, 00101 const RecordID &id 00102 ) 00103 { 00104 if (_delegate) { 00105 _delegate->on_text_parsed(text, id); 00106 } 00107 } 00108 00109 void SimpleMessageParser::on_record_parsed( 00110 const Mime &mime, 00111 const RecordID &id 00112 ) 00113 { 00114 if (_delegate) { 00115 _delegate->on_mime_parsed(mime, id); 00116 } 00117 } 00118 00119 } // namespace common 00120 } // namespace ndef 00121 } // namespace nfc 00122 } // namespace mbed 00123 00124
Generated on Tue Aug 9 2022 00:37:19 by
1.7.2