m_javaloader.h

Go to the documentation of this file.
00001 ///
00002 /// \file       m_javaloader.h
00003 ///             Mode class for the JavaLoader mode
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2009, Net Direct Inc. (http://www.netdirect.ca/)
00008     Copyright (C) 2008-2009, Nicolas VIVIEN
00009 
00010         Some parts are inspired from m_desktop.h
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00020 
00021     See the GNU General Public License in the COPYING file at the
00022     root directory of this project for more details.
00023 */
00024 
00025 #ifndef __BARRY_M_JAVALOADER_H__
00026 #define __BARRY_M_JAVALOADER_H__
00027 
00028 #include "dll.h"
00029 #include "m_mode_base.h"
00030 #include "socket.h"
00031 #include "record.h"
00032 #include "data.h"
00033 
00034 namespace Barry {
00035 
00036 // forward declarations
00037 class Parser;
00038 class Builder;
00039 class Controller;
00040 class CodFileBuilder;
00041 
00042 class JLDirectoryEntry;
00043 
00044 class JLEventlogEntry;
00045 
00046 class BXEXPORT JLDirectory : public std::vector<JLDirectoryEntry>
00047 {
00048 public:
00049         typedef std::vector<JLDirectoryEntry>   BaseType;
00050         typedef BaseType::iterator              BaseIterator;
00051         typedef std::vector<uint16_t>           TableType;
00052         typedef TableType::iterator             TableIterator;
00053 
00054 private:
00055         TableType m_idTable;
00056 
00057         int m_level;
00058 
00059 public:
00060         JLDirectory(int level = 0);
00061         ~JLDirectory();
00062 
00063         int Level() const { return m_level; }
00064         TableIterator TableBegin() { return m_idTable.begin(); }
00065         TableIterator TableEnd()   { return m_idTable.end(); }
00066 
00067         void ParseTable(const Data &table_packet);
00068 
00069         void Dump(std::ostream &os) const;
00070 };
00071 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectory &d) {
00072         d.Dump(os);
00073         return os;
00074 }
00075 
00076 class BXEXPORT JLDirectoryEntry
00077 {
00078 private:
00079         int m_level;
00080 
00081 public:
00082         uint16_t Id;
00083         std::string Name;
00084         std::string Version;
00085         uint32_t CodSize;
00086         time_t Timestamp;
00087 
00088         JLDirectory SubDir;
00089 
00090 public:
00091         explicit JLDirectoryEntry(int level);
00092 
00093         void Parse(uint16_t id, const Data &entry_packet);
00094 
00095         void Dump(std::ostream &os) const;
00096 };
00097 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectoryEntry &e) {
00098         e.Dump(os);
00099         return os;
00100 }
00101 
00102 
00103 class BXEXPORT JLScreenInfo {
00104 public:
00105         uint16_t width;
00106         uint16_t height;
00107 
00108 public:
00109         JLScreenInfo();
00110         ~JLScreenInfo();
00111 };
00112 
00113 
00114 class BXEXPORT JLEventlog : public std::vector<JLEventlogEntry>
00115 {
00116 public:
00117         void Dump(std::ostream &os) const;
00118 };
00119 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLEventlog &log) {
00120         log.Dump(os);
00121         return os;
00122 }
00123 
00124 
00125 class BXEXPORT JLEventlogEntry
00126 {
00127 public:
00128         typedef enum {
00129                 ALWAYS_LOG,
00130                 SEVERE_ERROR,
00131                 ERROR,
00132                 WARNING,
00133                 INFORMATION,
00134                 DEBUG_INFO
00135         } Severity_t;
00136 
00137         typedef enum {
00138                 NUMBER = 1,
00139                 STRING,
00140                 EXCEPTION
00141         } ViewerType_t;
00142 
00143         std::string     Guid;
00144         uint64_t        MSTimestamp;    // time_t in milliseconds
00145         Severity_t      Severity;
00146         ViewerType_t    Type;
00147         std::string     App;
00148         std::string     Data;
00149 
00150 protected:
00151         static Severity_t SeverityProto2Rec(unsigned int s);
00152         static unsigned int SeverityRec2Proto(Severity_t s);
00153 
00154         static ViewerType_t ViewerTypeProto2Rec(unsigned int v);
00155         static unsigned int ViewerTypeRec2Proto(ViewerType_t v);
00156 
00157 public:
00158         void Parse(uint16_t size, const char* str);
00159 
00160         std::string GetFormattedTimestamp() const;
00161 
00162         void Dump(std::ostream &os) const;
00163 };
00164 
00165 
00166 class BXEXPORT JLDeviceInfo
00167 {
00168 public:
00169         struct VersionQuad {
00170                 VersionQuad() { }
00171                 VersionQuad(uint32_t v) {
00172                         Major = (v & 0xff000000) >> 24;
00173                         Minor = (v & 0xff0000) >> 16;
00174                         SubMinor = (v & 0xff00) >> 8;
00175                         Build = (v & 0xff);
00176                 }
00177 
00178                 unsigned int Major;
00179                 unsigned int Minor;
00180                 unsigned int SubMinor;
00181                 unsigned int Build;
00182         };
00183 
00184 public:
00185         uint32_t        HardwareId;
00186         uint32_t        Pin;
00187         VersionQuad     OsVersion;
00188         VersionQuad     VmVersion;
00189         uint32_t        RadioId;
00190         uint32_t        VendorId;
00191         uint32_t        ActiveWafs;
00192         Data            OsMetrics;
00193         Data            BootromMetrics;
00194 
00195 public:
00196         void Dump(std::ostream &os) const;
00197 };
00198 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDeviceInfo &info) {
00199         info.Dump(os);
00200         return os;
00201 }
00202 
00203 
00204 namespace Mode {
00205 
00206 //
00207 // JavaLoader class
00208 //
00209 /// The main interface class to the java program loader protocol
00210 ///
00211 /// To use this class, use the following steps:
00212 ///
00213 ///     - Create a Controller object (see Controller class for more details)
00214 ///     - Create this Mode::JavaLoader object, passing in the Controller
00215 ///             object during construction
00216 ///     - Call Open() to open database socket and finish constructing.
00217 ///     - Call LoadDatabase() to retrieve and store a database
00218 ///
00219 class BXEXPORT JavaLoader : public Mode
00220 {
00221 private:
00222         bool m_StreamStarted;
00223 
00224 protected:
00225         void GetDirectoryEntries(JLPacket &packet, uint8_t entry_cmd,
00226                 JLDirectory &dir, bool include_subdirs);
00227         void GetDir(JLPacket &packet, uint8_t entry_cmd, JLDirectory &dir,
00228                 bool include_subdirs);
00229         void ThrowJLError(const std::string &msg, uint8_t cmd);
00230         void DoErase(uint8_t cmd, const std::string &cod_name);
00231         void SaveData(JLPacket &packet, uint16_t, CodFileBuilder &builder,
00232                 std::ostream &output);
00233 
00234         //////////////////////////////////
00235         // overrides
00236 
00237         virtual void OnOpen();
00238 
00239 public:
00240         JavaLoader(Controller &con);
00241         ~JavaLoader();
00242 
00243         //////////////////////////////////
00244         // API
00245         void StartStream();
00246         bool StopStream();
00247 
00248         // mid-stream operations
00249         void SendStream(std::istream &input, size_t module_size);
00250         void LoadApp(std::istream &input);
00251         void SetTime(time_t when);
00252         void GetDirectory(JLDirectory &dir, bool include_subdirs);
00253         void GetScreenshot(JLScreenInfo &info, Data &image);
00254         void Erase(const std::string &cod_name);
00255         void ForceErase(const std::string &cod_name);
00256         void GetEventlog(JLEventlog &log);
00257         void ClearEventlog();
00258         void Save(const std::string &cod_name, std::ostream &output);
00259         void DeviceInfo(JLDeviceInfo &info);
00260         void Wipe(bool apps = true, bool fs = true);
00261         void LogStackTraces();
00262         void ResetToFactory();
00263 };
00264 
00265 }} // namespace Barry::Mode
00266 
00267 #endif
00268 

Generated on Tue Jun 30 16:08:14 2009 for Barry by  doxygen 1.5.8