Bumped copyright dates for 2013
[barry.git] / src / r_calllog.h
blob582fb2764b0b9663e08e59a011127f7385700cc8
1 ///
2 /// \file r_calllog.h
3 /// Record parsing class for call logs
4 ///
6 /*
7 Copyright (C) 2008-2009, Nicolas VIVIEN
8 Copyright (C) 2005-2013, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #ifndef __BARRY_RECORD_CALLLOG_H__
24 #define __BARRY_RECORD_CALLLOG_H__
26 #include "dll.h"
27 #include "record.h"
28 #include <vector>
29 #include <string>
30 #include <stdint.h>
32 namespace Barry {
34 // forward declarations
35 class IConverter;
37 class BXEXPORT CallLog
39 public:
40 typedef Barry::UnknownsType UnknownsType;
42 uint8_t RecType;
43 uint32_t RecordId;
45 uint32_t Duration; //< duration of call in seconds
46 uint64_t Timestamp; //< timestamp of call in milliseconds
47 //< use GetTime() to convert to
48 //< a time_t
49 std::string ContactName;
50 std::string PhoneNumber;
52 enum DirectionFlagType
54 Receiver = 0, //< We have received a call
55 Emitter, //< We have composed a call
56 Failed, //< We have missing a call and the
57 //< emitter is arrived on our
58 //< answering machine
59 Missing //< We have missing a call. The
60 //< emitter has stopped the
61 //< communication.
63 DirectionFlagType DirectionFlag;
65 enum StatusFlagType
67 OK = 0, //
68 Busy, //< We have sent the emitter on our
69 //< answering machine
70 NetError, //< Network communication error
71 Unknown //< Not supported by Barry CallLog parser
73 StatusFlagType StatusFlag;
75 enum PhoneTypeFlagType
77 TypeUndefined = 0,
78 TypeOffice,
79 TypeHome,
80 TypeMobile,
81 TypeUnknown // To be completed (Office2, Home2, Pager ???)
83 PhoneTypeFlagType PhoneTypeFlag;
85 enum PhoneInfoFlagType
87 InfoUndefined = 0,
88 InfoKnown, //< PhoneNumber should be set
89 InfoUnknown, //< PhoneNumber isn't set
90 InfoPrivate //< PhoneNumber is private
92 PhoneInfoFlagType PhoneInfoFlag;
94 UnknownsType Unknowns;
96 protected:
97 time_t GetTime() const;
99 static DirectionFlagType DirectionProto2Rec(uint8_t s);
100 static uint8_t DirectionRec2Proto(DirectionFlagType s);
102 static PhoneTypeFlagType PhoneTypeProto2Rec(uint8_t s);
103 static uint8_t PhoneTypeRec2Proto(PhoneTypeFlagType s);
105 public:
106 CallLog();
107 ~CallLog();
109 // Parser / Builder API (see parser.h / builder.h)
110 void Validate() const;
111 const unsigned char* ParseField(const unsigned char *begin,
112 const unsigned char *end, const IConverter *ic = 0);
113 uint8_t GetRecType() const { return RecType; }
114 uint32_t GetUniqueId() const { return RecordId; }
115 void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
116 void ParseHeader(const Data &data, size_t &offset);
117 void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
118 void BuildHeader(Data &data, size_t &offset) const;
119 void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
121 // operations (common among record classes)
122 void Clear();
123 void Dump(std::ostream &os) const;
124 std::string GetDescription() const;
126 // Sorting
127 bool operator<(const CallLog &other) const { return Timestamp < other.Timestamp; }
129 // database name
130 static const char * GetDBName() { return "Phone Call Logs"; }
131 static uint8_t GetDefaultRecType() { return 0; }
133 // Generic Field Handle support
134 static const FieldHandle<CallLog>::ListT& GetFieldHandles();
137 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const CallLog &msg) {
138 msg.Dump(os);
139 return os;
142 } // namespace Barry
144 #endif