v-16

Committer:
DuyLionTran
Date:
Tue Dec 12 15:58:23 2017 +0000
Revision:
0:89e2c8a57572
version 1.6

Who changed what in which revision?

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