CUSTOMIZED FOR WATER MONITOR

Committer:
DuyLionTran
Date:
Thu Dec 07 17:07:22 2017 +0000
Revision:
0:51d7bdf88981
CUSTOMIZED FOR WATER MONITOR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DuyLionTran 0:51d7bdf88981 1 /**
DuyLionTran 0:51d7bdf88981 2 ******************************************************************************
DuyLionTran 0:51d7bdf88981 3 * @file RecordMail.h
DuyLionTran 0:51d7bdf88981 4 * @author ST / Central Labs
DuyLionTran 0:51d7bdf88981 5 * @version V2.0.0
DuyLionTran 0:51d7bdf88981 6 * @date 28 Apr 2017
DuyLionTran 0:51d7bdf88981 7 * @brief Class that specializes the {@link RecordUri} to store a mail content.
DuyLionTran 0:51d7bdf88981 8 ******************************************************************************
DuyLionTran 0:51d7bdf88981 9 * @attention
DuyLionTran 0:51d7bdf88981 10 *
DuyLionTran 0:51d7bdf88981 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
DuyLionTran 0:51d7bdf88981 12 *
DuyLionTran 0:51d7bdf88981 13 * Redistribution and use in source and binary forms, with or without modification,
DuyLionTran 0:51d7bdf88981 14 * are permitted provided that the following conditions are met:
DuyLionTran 0:51d7bdf88981 15 * 1. Redistributions of source code must retain the above copyright notice,
DuyLionTran 0:51d7bdf88981 16 * this list of conditions and the following disclaimer.
DuyLionTran 0:51d7bdf88981 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
DuyLionTran 0:51d7bdf88981 18 * this list of conditions and the following disclaimer in the documentation
DuyLionTran 0:51d7bdf88981 19 * and/or other materials provided with the distribution.
DuyLionTran 0:51d7bdf88981 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
DuyLionTran 0:51d7bdf88981 21 * may be used to endorse or promote products derived from this software
DuyLionTran 0:51d7bdf88981 22 * without specific prior written permission.
DuyLionTran 0:51d7bdf88981 23 *
DuyLionTran 0:51d7bdf88981 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
DuyLionTran 0:51d7bdf88981 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
DuyLionTran 0:51d7bdf88981 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DuyLionTran 0:51d7bdf88981 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
DuyLionTran 0:51d7bdf88981 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DuyLionTran 0:51d7bdf88981 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
DuyLionTran 0:51d7bdf88981 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
DuyLionTran 0:51d7bdf88981 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
DuyLionTran 0:51d7bdf88981 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
DuyLionTran 0:51d7bdf88981 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
DuyLionTran 0:51d7bdf88981 34 *
DuyLionTran 0:51d7bdf88981 35 ******************************************************************************
DuyLionTran 0:51d7bdf88981 36 */
DuyLionTran 0:51d7bdf88981 37 #ifndef NDEFLIB_RECORDTYPE_RECORDMAIL_H_s
DuyLionTran 0:51d7bdf88981 38 #define NDEFLIB_RECORDTYPE_RECORDMAIL_H_
DuyLionTran 0:51d7bdf88981 39
DuyLionTran 0:51d7bdf88981 40 #include "RecordURI.h"
DuyLionTran 0:51d7bdf88981 41
DuyLionTran 0:51d7bdf88981 42 namespace NDefLib {
DuyLionTran 0:51d7bdf88981 43
DuyLionTran 0:51d7bdf88981 44 /**
DuyLionTran 0:51d7bdf88981 45 * Class that specializes the {@link RecordUri} to store a mail content.
DuyLionTran 0:51d7bdf88981 46 */
DuyLionTran 0:51d7bdf88981 47 class RecordMail: public RecordURI {
DuyLionTran 0:51d7bdf88981 48
DuyLionTran 0:51d7bdf88981 49 public:
DuyLionTran 0:51d7bdf88981 50
DuyLionTran 0:51d7bdf88981 51 /**
DuyLionTran 0:51d7bdf88981 52 * Create a RecordMail reading the data from the buffer.
DuyLionTran 0:51d7bdf88981 53 * @param header Record header.
DuyLionTran 0:51d7bdf88981 54 * @param buffer Buffer to read the data from.
DuyLionTran 0:51d7bdf88981 55 * @return an object of type RecordMail or NULL
DuyLionTran 0:51d7bdf88981 56 * @par User is in charge of freeing the pointer returned by this function.
DuyLionTran 0:51d7bdf88981 57 */
DuyLionTran 0:51d7bdf88981 58 static RecordMail* parse(const RecordHeader &header,
DuyLionTran 0:51d7bdf88981 59 const uint8_t* buffer);
DuyLionTran 0:51d7bdf88981 60
DuyLionTran 0:51d7bdf88981 61 /**
DuyLionTran 0:51d7bdf88981 62 * Create a mail.
DuyLionTran 0:51d7bdf88981 63 * @param toAddress Mail recipient.
DuyLionTran 0:51d7bdf88981 64 * @param subject Mail subject.
DuyLionTran 0:51d7bdf88981 65 * @param msg Message.
DuyLionTran 0:51d7bdf88981 66 */
DuyLionTran 0:51d7bdf88981 67 RecordMail(const std::string &toAddress, const std::string &subject,
DuyLionTran 0:51d7bdf88981 68 const std::string &msg) :
DuyLionTran 0:51d7bdf88981 69 RecordURI(RecordURI::MAIL), mToAddress(toAddress), mSubject(
DuyLionTran 0:51d7bdf88981 70 subject), mBody(msg),mContentIsChange(true) { } ;
DuyLionTran 0:51d7bdf88981 71
DuyLionTran 0:51d7bdf88981 72 virtual ~RecordMail() { };
DuyLionTran 0:51d7bdf88981 73
DuyLionTran 0:51d7bdf88981 74 /**
DuyLionTran 0:51d7bdf88981 75 * @return the mail recipient address
DuyLionTran 0:51d7bdf88981 76 */
DuyLionTran 0:51d7bdf88981 77 const std::string& get_to_address() const {
DuyLionTran 0:51d7bdf88981 78 return mToAddress;
DuyLionTran 0:51d7bdf88981 79 }
DuyLionTran 0:51d7bdf88981 80
DuyLionTran 0:51d7bdf88981 81 /**
DuyLionTran 0:51d7bdf88981 82 * @return the mail subject
DuyLionTran 0:51d7bdf88981 83 */
DuyLionTran 0:51d7bdf88981 84 const std::string& get_subject() const {
DuyLionTran 0:51d7bdf88981 85 return mSubject;
DuyLionTran 0:51d7bdf88981 86 }
DuyLionTran 0:51d7bdf88981 87
DuyLionTran 0:51d7bdf88981 88 /**
DuyLionTran 0:51d7bdf88981 89 * @return the mail body
DuyLionTran 0:51d7bdf88981 90 */
DuyLionTran 0:51d7bdf88981 91 const std::string& get_body() const {
DuyLionTran 0:51d7bdf88981 92 return mBody;
DuyLionTran 0:51d7bdf88981 93 }
DuyLionTran 0:51d7bdf88981 94
DuyLionTran 0:51d7bdf88981 95 /**
DuyLionTran 0:51d7bdf88981 96 * Change the mail recipient.
DuyLionTran 0:51d7bdf88981 97 * @param dest Recipient address.
DuyLionTran 0:51d7bdf88981 98 * @par The string is copied inside the class.
DuyLionTran 0:51d7bdf88981 99 */
DuyLionTran 0:51d7bdf88981 100 void set_to_address(const std::string& dest){
DuyLionTran 0:51d7bdf88981 101 mContentIsChange=true;
DuyLionTran 0:51d7bdf88981 102 mToAddress=dest;
DuyLionTran 0:51d7bdf88981 103 }
DuyLionTran 0:51d7bdf88981 104
DuyLionTran 0:51d7bdf88981 105 /**
DuyLionTran 0:51d7bdf88981 106 * Change the mail subject.
DuyLionTran 0:51d7bdf88981 107 * @param subj New mail subject.
DuyLionTran 0:51d7bdf88981 108 * @par The string is copied inside the class.
DuyLionTran 0:51d7bdf88981 109 */
DuyLionTran 0:51d7bdf88981 110 void set_subject(const std::string& subj) {
DuyLionTran 0:51d7bdf88981 111 mContentIsChange=true;
DuyLionTran 0:51d7bdf88981 112 mSubject=subj;
DuyLionTran 0:51d7bdf88981 113 }
DuyLionTran 0:51d7bdf88981 114
DuyLionTran 0:51d7bdf88981 115 /**
DuyLionTran 0:51d7bdf88981 116 * Change the mail body.
DuyLionTran 0:51d7bdf88981 117 * @param body New mail body.
DuyLionTran 0:51d7bdf88981 118 * @par The string is copied inside the class.
DuyLionTran 0:51d7bdf88981 119 */
DuyLionTran 0:51d7bdf88981 120 void set_body(const std::string& body) {
DuyLionTran 0:51d7bdf88981 121 mContentIsChange=true;
DuyLionTran 0:51d7bdf88981 122 mBody=body;
DuyLionTran 0:51d7bdf88981 123 }
DuyLionTran 0:51d7bdf88981 124
DuyLionTran 0:51d7bdf88981 125 /**
DuyLionTran 0:51d7bdf88981 126 * Get the record type.
DuyLionTran 0:51d7bdf88981 127 * @return TYPE_URI_MAIL
DuyLionTran 0:51d7bdf88981 128 */
DuyLionTran 0:51d7bdf88981 129 virtual RecordType_t get_type() const {
DuyLionTran 0:51d7bdf88981 130 return TYPE_URI_MAIL;
DuyLionTran 0:51d7bdf88981 131 } //getType
DuyLionTran 0:51d7bdf88981 132
DuyLionTran 0:51d7bdf88981 133 /**
DuyLionTran 0:51d7bdf88981 134 * Compare 2 RecordMails.
DuyLionTran 0:51d7bdf88981 135 * @return true if both the tags have the same addresses,subjects and bodies
DuyLionTran 0:51d7bdf88981 136 */
DuyLionTran 0:51d7bdf88981 137 bool operator==(const RecordMail& other)const{
DuyLionTran 0:51d7bdf88981 138 return mToAddress == other.mToAddress &&
DuyLionTran 0:51d7bdf88981 139 mSubject == other.mSubject &&
DuyLionTran 0:51d7bdf88981 140 mBody == other.mBody;
DuyLionTran 0:51d7bdf88981 141 }
DuyLionTran 0:51d7bdf88981 142
DuyLionTran 0:51d7bdf88981 143 protected:
DuyLionTran 0:51d7bdf88981 144
DuyLionTran 0:51d7bdf88981 145 /**
DuyLionTran 0:51d7bdf88981 146 * Generate the uri content that encodes the mail content.
DuyLionTran 0:51d7bdf88981 147 * @see RecordUri#updateContent
DuyLionTran 0:51d7bdf88981 148 */
DuyLionTran 0:51d7bdf88981 149 virtual void update_content();
DuyLionTran 0:51d7bdf88981 150
DuyLionTran 0:51d7bdf88981 151 private:
DuyLionTran 0:51d7bdf88981 152
DuyLionTran 0:51d7bdf88981 153 std::string mToAddress; ///< Mail address.
DuyLionTran 0:51d7bdf88981 154 std::string mSubject; ///< Mail subject.
DuyLionTran 0:51d7bdf88981 155 std::string mBody; ///< Mail body.
DuyLionTran 0:51d7bdf88981 156 bool mContentIsChange; ///< True if the use update some mail field.
DuyLionTran 0:51d7bdf88981 157
DuyLionTran 0:51d7bdf88981 158 static const std::string sSubjectTag; ///< String to use bofore the subject.
DuyLionTran 0:51d7bdf88981 159 static const std::string sBodyTag; ///< String to use before the mail body.
DuyLionTran 0:51d7bdf88981 160 };
DuyLionTran 0:51d7bdf88981 161
DuyLionTran 0:51d7bdf88981 162 } /* namespace NDefLib */
DuyLionTran 0:51d7bdf88981 163
DuyLionTran 0:51d7bdf88981 164 #endif /* NDEFLIB_RECORDTYPE_RECORDMAIL_H_ */