r_calllog.h

Go to the documentation of this file.
00001 ///
00002 /// \file       r_calllog.h
00003 ///             Record parsing class for call logs
00004 ///
00005 
00006 /*
00007     Copyright (C) 2008-2009, Nicolas VIVIEN
00008     Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
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_CALLLOG_H__
00024 #define __BARRY_RECORD_CALLLOG_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 CallLog
00038 {
00039 public:
00040         typedef Barry::UnknownsType             UnknownsType;
00041 
00042         uint8_t RecType;
00043         uint32_t RecordId;
00044 
00045         uint32_t Duration;              //< duration of call in seconds
00046         uint64_t Timestamp;             //< timestamp of call in milliseconds
00047                                         //< use GetTime() to convert to
00048                                         //< a time_t
00049         std::string ContactName;
00050         std::string PhoneNumber;
00051 
00052         enum DirectionFlagType
00053         {
00054                 Receiver = 0,           //< We have received a call
00055                 Emitter,                //< We have composed a call
00056                 Failed,                 //< We have missing a call and the
00057                                         //< emitter is arrived on our
00058                                         //< answering machine
00059                 Missing                 //< We have missing a call. The
00060                                         //< emitter has stopped the
00061                                         //< communication.
00062         };
00063         DirectionFlagType DirectionFlag;
00064 
00065         enum StatusFlagType
00066         {
00067                 OK = 0,                 //
00068                 Busy,                   //< We have sent the emitter on our
00069                                         //< answering machine
00070                 NetError,               //< Network communication error
00071                 Unknown                 //< Not supported by Barry CallLog parser
00072         };
00073         StatusFlagType StatusFlag;
00074 
00075         enum PhoneTypeFlagType
00076         {
00077                 TypeUndefined = 0,
00078                 TypeOffice,
00079                 TypeHome,
00080                 TypeMobile,
00081                 TypeUnknown             // To be completed (Office2, Home2, Pager ???)
00082         };
00083         PhoneTypeFlagType PhoneTypeFlag;
00084 
00085         enum PhoneInfoFlagType
00086         {
00087                 InfoUndefined = 0,
00088                 InfoKnown,              //< PhoneNumber should be set
00089                 InfoUnknown,            //< PhoneNumber isn't set
00090                 InfoPrivate             //< PhoneNumber is private
00091         };
00092         PhoneInfoFlagType PhoneInfoFlag;
00093 
00094         UnknownsType Unknowns;
00095 
00096 protected:
00097         time_t GetTime() const;
00098 
00099         static DirectionFlagType DirectionProto2Rec(uint8_t s);
00100         static uint8_t DirectionRec2Proto(DirectionFlagType s);
00101 
00102         static PhoneTypeFlagType PhoneTypeProto2Rec(uint8_t s);
00103         static uint8_t PhoneTypeRec2Proto(PhoneTypeFlagType s);
00104 
00105 public:
00106         CallLog();
00107         ~CallLog();
00108 
00109         // Parser / Builder API (see parser.h / builder.h)
00110         void Validate() const;
00111         const unsigned char* ParseField(const unsigned char *begin,
00112                 const unsigned char *end, const IConverter *ic = 0);
00113         uint8_t GetRecType() const { return RecType; }
00114         uint32_t GetUniqueId() const { return RecordId; }
00115         void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00116         void ParseHeader(const Data &data, size_t &offset);
00117         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00118         void BuildHeader(Data &data, size_t &offset) const;
00119         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00120 
00121         // operations (common among record classes)
00122         void Clear();
00123         void Dump(std::ostream &os) const;
00124         std::string GetDescription() const;
00125 
00126         // Sorting
00127         bool operator<(const CallLog &other) const { return Timestamp < other.Timestamp; }
00128 
00129         // database name
00130         static const char * GetDBName() { return "Phone Call Logs"; }
00131         static uint8_t GetDefaultRecType() { return 0; }
00132 
00133         // Generic Field Handle support
00134         static const FieldHandle<CallLog>::ListT& GetFieldHandles();
00135 };
00136 
00137 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const CallLog &msg) {
00138         msg.Dump(os);
00139         return os;
00140 }
00141 
00142 } // namespace Barry
00143 
00144 #endif
00145