r_sms.h

00001 ///
00002 /// \file       r_task.h
00003 ///             Record parsing class for the task database.
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
00008     Copyright (C) 2009, Ryan Li(ryan@ryanium.com)
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019     See the GNU General Public License in the COPYING file at the
00020     root directory of this project for more details.
00021 */
00022 
00023 #ifndef __BARRY_RECORD_SMS_H__
00024 #define __BARRY_RECORD_SMS_H__
00025 
00026 #include "dll.h"
00027 #include "record.h"
00028 #include <vector>
00029 #include <string>
00030 #include <stdint.h>
00031 
00032 namespace Barry {
00033 
00034 // forward declarations
00035 class IConverter;
00036 
00037 class BXEXPORT Sms
00038 {
00039 public:
00040         typedef std::vector<UnknownField> UnknownsType;
00041 
00042         uint8_t RecType;
00043         uint32_t RecordId;
00044 
00045         enum MessageType
00046         {
00047                 Unknown = 0,
00048                 Received,
00049                 Sent,
00050                 Draft
00051         };
00052         MessageType MessageStatus;
00053 
00054         enum DeliveryType
00055         {
00056                 NoReport = 0,
00057                 Failed,
00058                 Succedded
00059         };
00060         DeliveryType DeliveryStatus; // not implemented yet
00061 
00062         bool IsNew;
00063         bool NewConversation;
00064         bool Saved;
00065         bool Deleted;
00066         bool Opened;
00067 
00068         uint64_t Timestamp; // milliseconds from Jan 1, 1970
00069         uint64_t ServiceCenterTimestamp; // not applicable for non-incoming messages
00070 
00071         enum DataCodingSchemeType
00072         {
00073                 SevenBit = 0,
00074                 EightBit,
00075                 UCS2
00076         };
00077         DataCodingSchemeType DataCodingScheme;
00078 
00079         uint32_t ErrorId;
00080 
00081         std::vector<std::string> Addresses;
00082         std::string Body;
00083 
00084         UnknownsType Unknowns;
00085 
00086 public:
00087         Sms();
00088         ~Sms();
00089 
00090         time_t GetTime() const;
00091         time_t GetServiceCenterTime() const;
00092         void SetTime(const time_t timestamp, unsigned int milliseconds = 0);
00093         void SetServiceCenterTime(const time_t timestamp, unsigned int milliseconds = 0);
00094 
00095         const unsigned char* ParseField(const unsigned char *begin, const unsigned char *end, const IConverter *ic = 0);
00096         uint8_t GetRecType() const { return RecType; }
00097         uint32_t GetUniqueId() const { return RecordId; }
00098         void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00099         void ParseHeader(const Data &data, size_t &offset);
00100         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00101         void BuildHeader(Data &data, size_t &offset) const;
00102 
00103         void Clear();
00104 
00105         void Dump(std::ostream &os) const;
00106 
00107         static std::string ConvertGsmToUtf8(const std::string &);
00108 
00109         // sorting
00110         bool operator<(const Sms &other) const {
00111                 return Timestamp < other.Timestamp;
00112         }
00113 
00114         // database name
00115         static const char * GetDBName() { return "SMS Messages"; }
00116         static uint8_t GetDefaultRecType() { return 5; }
00117 };
00118 
00119 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const Sms &msg) {
00120         msg.Dump(os);
00121         return os;
00122 }
00123 
00124 } // namespace Barry
00125 
00126 #endif
00127 
Generated by  doxygen 1.6.2-20100208