ST / NDefLib

Dependents:   NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more

Fork of NDefLib by ST Expansion SW Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RecordSMS.h Source File

RecordSMS.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    RecordSMS.h
00004  * @author  ST / Central Labs
00005  * @version V2.0.0
00006  * @date    28 Apr 2017
00007  * @brief   Extend the {@link RecordUri} to handle the SMS content
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *   1. Redistributions of source code must retain the above copyright notice,
00016  *      this list of conditions and the following disclaimer.
00017  *   2. Redistributions in binary form must reproduce the above copyright notice,
00018  *      this list of conditions and the following disclaimer in the documentation
00019  *      and/or other materials provided with the distribution.
00020  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021  *      may be used to endorse or promote products derived from this software
00022  *      without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  ******************************************************************************
00036  */
00037 
00038 #ifndef NDEFLIB_RECORDTYPE_RECORDSMS_H_
00039 #define NDEFLIB_RECORDTYPE_RECORDSMS_H_
00040 
00041 #include <string>
00042 
00043 #include "RecordURI.h"
00044 
00045 namespace NDefLib {
00046 
00047 /**
00048  * Extend the {@link RecordUri} to handle the SMS content.
00049  */
00050 class RecordSMS: public RecordURI {
00051 public:
00052 
00053     /**
00054      * Read a recordSMS.
00055      * @param header Record header.
00056      * @param buffer Buffer to read the data from.
00057      * @return a RecordSMS type or NULL if it was not possible to build this record
00058      * @par User is in charge of freeing the pointer returned by this function.
00059      */
00060     static RecordSMS* parse(const RecordHeader &header,
00061             const uint8_t *buffer);
00062 
00063     /**
00064      * Build a sms record.
00065      * @param number Sms recipient phone number.
00066      * @param message Message to send.
00067      * @par Strings are copied inside the class.
00068      */
00069     RecordSMS(const std::string &number, const std::string &message);
00070 
00071     /**
00072      * Get the record type.
00073      * @return TYPE_URI_SMS
00074      */
00075     virtual RecordType_t get_type() const {
00076         return TYPE_URI_SMS;
00077     } //getType
00078 
00079     /**
00080      * Get recipient number.
00081      * @return recipient number
00082      */
00083     const std::string& get_number() const {
00084         return mNumber;
00085     }
00086 
00087     /**
00088      * Get SMS text message.
00089      * @return SMS text message
00090      */
00091     const std::string& get_messagge() const {
00092         return mMsg;
00093     }
00094 
00095     /**
00096      * Change the recipent number.
00097      * @param number New recipent number.
00098      */
00099     void set_number(const std::string &number){
00100         mNumber=number;
00101         mContentIsChange=true;
00102     }
00103 
00104     /**
00105      * Change the message content.
00106      * @param message New message.
00107      */
00108     void set_message(const std::string &message){
00109         mMsg=message;
00110         mContentIsChange=true;
00111     }
00112 
00113     /**
00114      * Compare 2 objects.
00115      * @return true if the records have the same message and number.
00116      */
00117     bool operator==(const RecordSMS &other) const {
00118         return (mMsg == other.mMsg) &&
00119                 (mNumber == other.mNumber);
00120     }
00121 
00122     virtual ~RecordSMS() {
00123     };
00124 
00125 protected:
00126     
00127     /**
00128      * Generate the URI content that encodes the sms.
00129      * @see RecordUri#updateContent
00130      */
00131     virtual void update_content();
00132 
00133 private:
00134     std::string mNumber; ///< Recipient number.
00135     std::string mMsg; ///< Sms text.
00136 
00137     /**
00138      * This variable is true when we need to update the URI content,
00139      * it is an optimization to avoid to rebuild multiple times the URI content when 
00140      * data has not changed
00141      */
00142     bool mContentIsChange;
00143 
00144     /**
00145      * String used as URI type.
00146      */
00147     static const std::string sSmsTag;
00148 
00149     /**
00150      * String used to separate the number and body data.
00151      */
00152     static const std::string sBodyTag;
00153 };
00154 
00155 } /* namespace NDefLib */
00156 
00157 #endif /* NDEFLIB_RECORDTYPE_RECORDSMS_H_ */