Utility library to read and write Ndef messages from/to a Type4 NFC tag
Dependents: NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more
Fork of NDefLib by
NDEF NFC library
This library provides an abstract API to create NDEF formatted messages and records and to read/write them from/to a Type4 NFC Tag.
Implementations
At the moment, the NDEF API is implemented by X_NUCLEO_NFC01A1 and X_NUCLEO_NFC02A1 Dynamic NFC Tag libraries respectively driving the X-NUCLEO-NFC01A1 and X-NUCLEO-NFC02A1 boards.
RecordType/RecordMail.h@9:689c1f56f359, 2016-01-08 (annotated)
- Committer:
- giovannivisentini
- Date:
- Fri Jan 08 15:26:21 2016 +0000
- Revision:
- 9:689c1f56f359
- Parent:
- 8:473f6e0b03df
- Child:
- 12:ed4d9b8d1410
update the comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
giovannivisentini | 6:739e3211749d | 1 | /** |
giovannivisentini | 6:739e3211749d | 2 | ****************************************************************************** |
giovannivisentini | 6:739e3211749d | 3 | * @file RecordMail.h |
giovannivisentini | 8:473f6e0b03df | 4 | * @author ST / Central Labs |
giovannivisentini | 6:739e3211749d | 5 | * @version V1.0.0 |
giovannivisentini | 6:739e3211749d | 6 | * @date 17 Nov 2015 |
giovannivisentini | 9:689c1f56f359 | 7 | * @brief class that specialize the {@link RecordUri} for store the mail content |
giovannivisentini | 6:739e3211749d | 8 | ****************************************************************************** |
giovannivisentini | 6:739e3211749d | 9 | * @attention |
giovannivisentini | 6:739e3211749d | 10 | * |
giovannivisentini | 6:739e3211749d | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
giovannivisentini | 0:04b82ae7aa43 | 12 | * |
giovannivisentini | 6:739e3211749d | 13 | * Redistribution and use in source and binary forms, with or without modification, |
giovannivisentini | 6:739e3211749d | 14 | * are permitted provided that the following conditions are met: |
giovannivisentini | 6:739e3211749d | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
giovannivisentini | 6:739e3211749d | 16 | * this list of conditions and the following disclaimer. |
giovannivisentini | 6:739e3211749d | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
giovannivisentini | 6:739e3211749d | 18 | * this list of conditions and the following disclaimer in the documentation |
giovannivisentini | 6:739e3211749d | 19 | * and/or other materials provided with the distribution. |
giovannivisentini | 6:739e3211749d | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
giovannivisentini | 6:739e3211749d | 21 | * may be used to endorse or promote products derived from this software |
giovannivisentini | 6:739e3211749d | 22 | * without specific prior written permission. |
giovannivisentini | 6:739e3211749d | 23 | * |
giovannivisentini | 6:739e3211749d | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
giovannivisentini | 6:739e3211749d | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
giovannivisentini | 6:739e3211749d | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
giovannivisentini | 6:739e3211749d | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
giovannivisentini | 6:739e3211749d | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
giovannivisentini | 6:739e3211749d | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
giovannivisentini | 6:739e3211749d | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
giovannivisentini | 6:739e3211749d | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
giovannivisentini | 6:739e3211749d | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
giovannivisentini | 6:739e3211749d | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
giovannivisentini | 6:739e3211749d | 34 | * |
giovannivisentini | 6:739e3211749d | 35 | ****************************************************************************** |
giovannivisentini | 0:04b82ae7aa43 | 36 | */ |
giovannivisentini | 1:a0eeb478a45a | 37 | #ifndef NDEFLIB_RECORDTYPE_RECORDMAIL_H_s |
giovannivisentini | 0:04b82ae7aa43 | 38 | #define NDEFLIB_RECORDTYPE_RECORDMAIL_H_ |
giovannivisentini | 0:04b82ae7aa43 | 39 | |
giovannivisentini | 1:a0eeb478a45a | 40 | #include "RecordURI.h" |
giovannivisentini | 0:04b82ae7aa43 | 41 | |
giovannivisentini | 0:04b82ae7aa43 | 42 | namespace NDefLib { |
giovannivisentini | 0:04b82ae7aa43 | 43 | |
giovannivisentini | 4:eaf6c49a86e4 | 44 | /** |
giovannivisentini | 9:689c1f56f359 | 45 | * Class that specialize the {@link RecordUri} for store the mail content |
giovannivisentini | 4:eaf6c49a86e4 | 46 | */ |
giovannivisentini | 1:a0eeb478a45a | 47 | class RecordMail: public RecordURI { |
giovannivisentini | 1:a0eeb478a45a | 48 | |
giovannivisentini | 0:04b82ae7aa43 | 49 | public: |
giovannivisentini | 4:eaf6c49a86e4 | 50 | |
giovannivisentini | 4:eaf6c49a86e4 | 51 | /** |
giovannivisentini | 4:eaf6c49a86e4 | 52 | * create an RecordMail reading the data from the buffer |
giovannivisentini | 4:eaf6c49a86e4 | 53 | * @param header record header already read |
giovannivisentini | 4:eaf6c49a86e4 | 54 | * @param buffer buffer where read the data |
giovannivisentini | 4:eaf6c49a86e4 | 55 | * @return an object of type RecordMail or NULL |
giovannivisentini | 4:eaf6c49a86e4 | 56 | * @par free the pointer return by this function |
giovannivisentini | 4:eaf6c49a86e4 | 57 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 58 | static RecordMail* parse(const RecordHeader &header, |
giovannivisentini | 4:eaf6c49a86e4 | 59 | const uint8_t* buffer); |
giovannivisentini | 1:a0eeb478a45a | 60 | |
giovannivisentini | 4:eaf6c49a86e4 | 61 | /** |
giovannivisentini | 4:eaf6c49a86e4 | 62 | * create a mail |
giovannivisentini | 4:eaf6c49a86e4 | 63 | * @param toAddress where send the mail |
giovannivisentini | 4:eaf6c49a86e4 | 64 | * @param subject mail subject |
giovannivisentini | 4:eaf6c49a86e4 | 65 | * @param msg message |
giovannivisentini | 4:eaf6c49a86e4 | 66 | */ |
giovannivisentini | 7:1ebd6049fa57 | 67 | RecordMail(const std::string &toAddress, const std::string &subject, |
giovannivisentini | 4:eaf6c49a86e4 | 68 | const std::string &msg) : |
giovannivisentini | 4:eaf6c49a86e4 | 69 | RecordURI(RecordURI::MAIL), mToAddress(toAddress), mSubject( |
giovannivisentini | 4:eaf6c49a86e4 | 70 | subject), mBody(msg),mContentIsChange(true) { } ; |
giovannivisentini | 0:04b82ae7aa43 | 71 | |
giovannivisentini | 4:eaf6c49a86e4 | 72 | virtual ~RecordMail() { }; |
giovannivisentini | 4:eaf6c49a86e4 | 73 | |
giovannivisentini | 9:689c1f56f359 | 74 | /** |
giovannivisentini | 9:689c1f56f359 | 75 | * @return the mail recipient address |
giovannivisentini | 9:689c1f56f359 | 76 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 77 | const std::string& getToAddress() const { |
giovannivisentini | 4:eaf6c49a86e4 | 78 | return mToAddress; |
giovannivisentini | 1:a0eeb478a45a | 79 | } |
giovannivisentini | 1:a0eeb478a45a | 80 | |
giovannivisentini | 9:689c1f56f359 | 81 | /** |
giovannivisentini | 9:689c1f56f359 | 82 | * @return the mail subject |
giovannivisentini | 9:689c1f56f359 | 83 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 84 | const std::string& getSubject() const { |
giovannivisentini | 1:a0eeb478a45a | 85 | return mSubject; |
giovannivisentini | 1:a0eeb478a45a | 86 | } |
giovannivisentini | 1:a0eeb478a45a | 87 | |
giovannivisentini | 9:689c1f56f359 | 88 | /** |
giovannivisentini | 9:689c1f56f359 | 89 | * @return the mail body |
giovannivisentini | 9:689c1f56f359 | 90 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 91 | const std::string& getBody() const { |
giovannivisentini | 1:a0eeb478a45a | 92 | return mBody; |
giovannivisentini | 1:a0eeb478a45a | 93 | } |
giovannivisentini | 1:a0eeb478a45a | 94 | |
giovannivisentini | 9:689c1f56f359 | 95 | /** |
giovannivisentini | 9:689c1f56f359 | 96 | * change the mail recipient |
giovannivisentini | 9:689c1f56f359 | 97 | * @param dest recipient address |
giovannivisentini | 9:689c1f56f359 | 98 | * the string is copyed inside the class |
giovannivisentini | 9:689c1f56f359 | 99 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 100 | void setToAddress(const std::string& dest){ |
giovannivisentini | 4:eaf6c49a86e4 | 101 | mContentIsChange=true; |
giovannivisentini | 4:eaf6c49a86e4 | 102 | mToAddress=dest; |
giovannivisentini | 4:eaf6c49a86e4 | 103 | } |
giovannivisentini | 4:eaf6c49a86e4 | 104 | |
giovannivisentini | 9:689c1f56f359 | 105 | /** |
giovannivisentini | 9:689c1f56f359 | 106 | * change the mail subject |
giovannivisentini | 9:689c1f56f359 | 107 | * @param subj new mail subject |
giovannivisentini | 9:689c1f56f359 | 108 | * the string is copyed inside the class |
giovannivisentini | 9:689c1f56f359 | 109 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 110 | void setSubject(const std::string& subj) { |
giovannivisentini | 4:eaf6c49a86e4 | 111 | mContentIsChange=true; |
giovannivisentini | 4:eaf6c49a86e4 | 112 | mSubject=subj; |
giovannivisentini | 4:eaf6c49a86e4 | 113 | } |
giovannivisentini | 4:eaf6c49a86e4 | 114 | |
giovannivisentini | 9:689c1f56f359 | 115 | /** |
giovannivisentini | 9:689c1f56f359 | 116 | * change the mail body |
giovannivisentini | 9:689c1f56f359 | 117 | * @param body new mail body |
giovannivisentini | 9:689c1f56f359 | 118 | * the string is copyed inside the class |
giovannivisentini | 9:689c1f56f359 | 119 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 120 | void setBody(const std::string& body) { |
giovannivisentini | 4:eaf6c49a86e4 | 121 | mContentIsChange=true; |
giovannivisentini | 4:eaf6c49a86e4 | 122 | mBody=body; |
giovannivisentini | 4:eaf6c49a86e4 | 123 | } |
giovannivisentini | 4:eaf6c49a86e4 | 124 | |
giovannivisentini | 9:689c1f56f359 | 125 | /** |
giovannivisentini | 9:689c1f56f359 | 126 | * get the record type |
giovannivisentini | 9:689c1f56f359 | 127 | * @return TYPE_URI_MAIL |
giovannivisentini | 9:689c1f56f359 | 128 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 129 | virtual RecordType_t getType() const { |
giovannivisentini | 1:a0eeb478a45a | 130 | return TYPE_URI_MAIL; |
giovannivisentini | 4:eaf6c49a86e4 | 131 | } //getType |
giovannivisentini | 4:eaf6c49a86e4 | 132 | |
giovannivisentini | 9:689c1f56f359 | 133 | /** |
giovannivisentini | 9:689c1f56f359 | 134 | * compare 2 RecordMail |
giovannivisentini | 9:689c1f56f359 | 135 | * @return true if both the tag have address,subject and body |
giovannivisentini | 9:689c1f56f359 | 136 | */ |
giovannivisentini | 7:1ebd6049fa57 | 137 | bool operator==(const RecordMail& other)const{ |
giovannivisentini | 7:1ebd6049fa57 | 138 | return mToAddress == other.mToAddress && |
giovannivisentini | 7:1ebd6049fa57 | 139 | mSubject == other.mSubject && |
giovannivisentini | 7:1ebd6049fa57 | 140 | mBody == other.mBody; |
giovannivisentini | 7:1ebd6049fa57 | 141 | } |
giovannivisentini | 7:1ebd6049fa57 | 142 | |
giovannivisentini | 4:eaf6c49a86e4 | 143 | protected: |
giovannivisentini | 9:689c1f56f359 | 144 | |
giovannivisentini | 9:689c1f56f359 | 145 | /** |
giovannivisentini | 9:689c1f56f359 | 146 | * generate the uri content that encode the mail content |
giovannivisentini | 9:689c1f56f359 | 147 | * @see RecordUri#updateContent |
giovannivisentini | 9:689c1f56f359 | 148 | */ |
giovannivisentini | 4:eaf6c49a86e4 | 149 | virtual void updateContent(); |
giovannivisentini | 4:eaf6c49a86e4 | 150 | |
giovannivisentini | 0:04b82ae7aa43 | 151 | private: |
giovannivisentini | 0:04b82ae7aa43 | 152 | |
giovannivisentini | 9:689c1f56f359 | 153 | std::string mToAddress; ///< mail address |
giovannivisentini | 9:689c1f56f359 | 154 | std::string mSubject; ///< mail subject |
giovannivisentini | 9:689c1f56f359 | 155 | std::string mBody; ///< mail body |
giovannivisentini | 9:689c1f56f359 | 156 | bool mContentIsChange; ///< true if the use update some mail field |
giovannivisentini | 1:a0eeb478a45a | 157 | |
giovannivisentini | 9:689c1f56f359 | 158 | static const std::string sSubjectTag; ///< string to use bofore the subject |
giovannivisentini | 9:689c1f56f359 | 159 | static const std::string sBodyTag; ///< string to use before the mail body |
giovannivisentini | 0:04b82ae7aa43 | 160 | }; |
giovannivisentini | 0:04b82ae7aa43 | 161 | |
giovannivisentini | 0:04b82ae7aa43 | 162 | } /* namespace NDefLib */ |
giovannivisentini | 0:04b82ae7aa43 | 163 | |
giovannivisentini | 0:04b82ae7aa43 | 164 | #endif /* NDEFLIB_RECORDTYPE_RECORDMAIL_H_ */ |