r_hhagent.h

Go to the documentation of this file.
00001 ///
00002 /// \file       r_hhagent.h
00003 ///             Blackberry database record parser class for Handheld Agent records
00004 ///
00005 
00006 /*
00007     Copyright (C) 2011-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #ifndef __BARRY_RECORD_HHAGENT_H__
00023 #define __BARRY_RECORD_HHAGENT_H__
00024 
00025 #include "dll.h"
00026 #include "record.h"
00027 
00028 namespace Barry {
00029 
00030 // forward declarations
00031 class IConverter;
00032 
00033 //
00034 // NOTE:  All classes here must be container-safe!  Perhaps add sorting
00035 //        operators in the future.
00036 //
00037 
00038 /// \addtogroup RecordParserClasses
00039 /// @{
00040 
00041 //
00042 // Handheld Agent record class
00043 //
00044 /// Represents a single record in the Handheld Agent database.
00045 ///
00046 class BXEXPORT HandheldAgent
00047 {
00048 public:
00049         typedef Barry::UnknownsType                     UnknownsType;
00050 
00051         //
00052         // Record fields
00053         //
00054 
00055         // contact specific data
00056         uint8_t RecType;
00057         uint32_t RecordId;
00058 
00059         std::string MEID;
00060         std::string Model;
00061         std::string Bands;
00062         std::string Pin;                // may not be valid for every record
00063         std::string Version;
00064         std::string PlatformVersion;
00065         std::string Manufacturer;
00066         std::string Network;
00067 
00068         UnknownsType Unknowns;
00069 
00070 public:
00071         const unsigned char* ParseField(const unsigned char *begin,
00072                 const unsigned char *end, const IConverter *ic = 0);
00073 
00074 public:
00075         HandheldAgent();
00076         ~HandheldAgent();
00077 
00078         uint32_t GetID() const { return RecordId; }
00079         std::string GetFullName() const;
00080         const std::string& GetEmail(unsigned int index = 0) const;
00081 
00082         // Parser / Builder API (see parser.h / builder.h)
00083         void Validate() const;
00084         uint8_t GetRecType() const { return RecType; }
00085         uint32_t GetUniqueId() const { return RecordId; }
00086         void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00087         void ParseHeader(const Data &data, size_t &offset);
00088         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00089         void BuildHeader(Data &data, size_t &offset) const;
00090         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00091 
00092         // operations (common among record classes)
00093         void Clear();                   // erase everything
00094         void Dump(std::ostream &os) const;
00095         std::string GetDescription() const;
00096 
00097         // Sorting - use enough data to make the sorting as
00098         //           consistent as possible
00099         bool operator<(const HandheldAgent &other) const;
00100 
00101         // database name
00102         static const char * GetDBName() { return "Handheld Agent"; }
00103         static uint8_t GetDefaultRecType() { return 0; }
00104         static uint32_t GetMEIDRecordId() { return 0x3000000; }
00105         static uint32_t GetUnknown1RecordId() { return 0x4000000; }
00106         static uint32_t GetUnknown2RecordId() { return 0x5000000; }
00107         static uint32_t GetUnknown3RecordId() { return 0x7000000; }
00108         static bool IsSpecial(uint32_t record_id);
00109 
00110         // utility functions
00111         static bool IsESNHex(const std::string &esn);
00112         static bool IsESNDec(const std::string &esn);
00113         static std::string ESNDec2Hex(const std::string &esn);
00114         static std::string ESNHex2Dec(const std::string &esn);
00115 
00116         // Generic Field Handle support
00117         static const FieldHandle<HandheldAgent>::ListT& GetFieldHandles();
00118 };
00119 
00120 BXEXPORT inline std::ostream& operator<< (std::ostream &os, const HandheldAgent &hha) {
00121         hha.Dump(os);
00122         return os;
00123 }
00124 
00125 /// @}
00126 
00127 } // namespace Barry
00128 
00129 #endif
00130