lib: added back m_seen_usb_error check in DefaultRead()
[barry.git] / src / m_javaloader.h
blob9dcaa3f4183142b8f95ac81cb53ca4f98fa3bd0e
1 ///
2 /// \file m_javaloader.h
3 /// Mode class for the JavaLoader mode
4 ///
6 /*
7 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
8 Copyright (C) 2008-2009, Nicolas VIVIEN
10 Some parts are inspired from m_desktop.h
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU General Public License in the COPYING file at the
22 root directory of this project for more details.
25 #ifndef __BARRY_M_JAVALOADER_H__
26 #define __BARRY_M_JAVALOADER_H__
28 #include "dll.h"
29 #include "m_mode_base.h"
30 #include "socket.h"
31 #include "record.h"
32 #include "data.h"
33 #include "pin.h"
35 namespace Barry {
37 // forward declarations
38 class Parser;
39 class Builder;
40 class Controller;
41 class CodFileBuilder;
43 class JLDirectoryEntry;
45 class JLEventlogEntry;
47 class BXEXPORT JLDirectory : public std::vector<JLDirectoryEntry>
49 public:
50 typedef std::vector<JLDirectoryEntry> BaseType;
51 typedef BaseType::iterator BaseIterator;
52 typedef std::vector<uint16_t> TableType;
53 typedef TableType::iterator TableIterator;
55 private:
56 TableType m_idTable;
58 int m_level;
60 public:
61 JLDirectory(int level = 0);
62 ~JLDirectory();
64 int Level() const { return m_level; }
65 TableIterator TableBegin() { return m_idTable.begin(); }
66 TableIterator TableEnd() { return m_idTable.end(); }
68 void ParseTable(const Data &table_packet);
70 void Dump(std::ostream &os) const;
72 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectory &d) {
73 d.Dump(os);
74 return os;
77 class BXEXPORT JLDirectoryEntry
79 private:
80 int m_level;
82 public:
83 uint16_t Id;
84 std::string Name;
85 std::string Version;
86 uint32_t CodSize;
87 time_t Timestamp;
89 JLDirectory SubDir;
91 public:
92 explicit JLDirectoryEntry(int level);
94 void Parse(uint16_t id, const Data &entry_packet);
96 void Dump(std::ostream &os) const;
98 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectoryEntry &e) {
99 e.Dump(os);
100 return os;
104 class BXEXPORT JLScreenInfo {
105 public:
106 uint16_t width;
107 uint16_t height;
109 public:
110 JLScreenInfo();
111 ~JLScreenInfo();
115 class BXEXPORT JLEventlog : public std::vector<JLEventlogEntry>
117 public:
118 void Dump(std::ostream &os) const;
120 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLEventlog &log) {
121 log.Dump(os);
122 return os;
126 class BXEXPORT JLEventlogEntry
128 public:
129 typedef enum {
130 JES_ALWAYS_LOG,
131 JES_SEVERE_ERROR,
132 JES_ERROR,
133 JES_WARNING,
134 JES_INFORMATION,
135 JES_DEBUG_INFO
136 } Severity_t;
138 typedef enum {
139 JEVT_NUMBER = 1,
140 JEVT_STRING,
141 JEVT_EXCEPTION
142 } ViewerType_t;
144 std::string Guid;
145 uint64_t MSTimestamp; // time_t in milliseconds
146 Severity_t Severity;
147 ViewerType_t Type;
148 std::string App;
149 std::string Data;
151 protected:
152 static Severity_t SeverityProto2Rec(unsigned int s);
153 static unsigned int SeverityRec2Proto(Severity_t s);
155 static ViewerType_t ViewerTypeProto2Rec(unsigned int v);
156 static unsigned int ViewerTypeRec2Proto(ViewerType_t v);
158 public:
159 void Parse(uint16_t size, const char* str);
161 std::string GetFormattedTimestamp() const;
163 void Dump(std::ostream &os) const;
167 class BXEXPORT JLDeviceInfo
169 public:
170 struct VersionQuad {
171 VersionQuad() { }
172 VersionQuad(uint32_t v) {
173 Major = (v & 0xff000000) >> 24;
174 Minor = (v & 0xff0000) >> 16;
175 SubMinor = (v & 0xff00) >> 8;
176 Build = (v & 0xff);
179 unsigned int Major;
180 unsigned int Minor;
181 unsigned int SubMinor;
182 unsigned int Build;
185 public:
186 uint32_t HardwareId;
187 struct Pin Pin;
188 VersionQuad OsVersion;
189 VersionQuad VmVersion;
190 uint32_t RadioId;
191 uint32_t VendorId;
192 uint32_t ActiveWafs;
193 Data OsMetrics;
194 Data BootromMetrics;
196 public:
197 void Dump(std::ostream &os) const;
199 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDeviceInfo &info) {
200 info.Dump(os);
201 return os;
205 namespace Mode {
208 // JavaLoader class
210 /// The main interface class to the java program loader protocol
212 /// To use this class, use the following steps:
214 /// - Create a Controller object (see Controller class for more details)
215 /// - Create this Mode::JavaLoader object, passing in the Controller
216 /// object during construction
217 /// - Call Open() to open database socket and finish constructing.
218 /// - Call LoadDatabase() to retrieve and store a database
220 class BXEXPORT JavaLoader : public Mode
222 private:
223 bool m_StreamStarted;
225 protected:
226 void GetDirectoryEntries(JLPacket &packet, uint8_t entry_cmd,
227 JLDirectory &dir, bool include_subdirs);
228 void GetDir(JLPacket &packet, uint8_t entry_cmd, JLDirectory &dir,
229 bool include_subdirs);
230 void ThrowJLError(const std::string &msg, uint8_t cmd);
231 void DoErase(uint8_t cmd, const std::string &cod_name);
232 void SaveData(JLPacket &packet, uint16_t, CodFileBuilder &builder,
233 std::ostream &output);
235 //////////////////////////////////
236 // overrides
238 virtual void OnOpen();
240 public:
241 JavaLoader(Controller &con);
242 ~JavaLoader();
244 //////////////////////////////////
245 // API
246 void StartStream();
247 bool StopStream();
249 // mid-stream operations
250 void SendStream(std::istream &input, size_t module_size);
251 void LoadApp(std::istream &input);
252 void SetTime(time_t when);
253 void GetDirectory(JLDirectory &dir, bool include_subdirs);
254 void GetScreenshot(JLScreenInfo &info, Data &image);
255 void Erase(const std::string &cod_name);
256 void ForceErase(const std::string &cod_name);
257 void GetEventlog(JLEventlog &log);
258 void ClearEventlog();
259 void Save(const std::string &cod_name, std::ostream &output);
260 void DeviceInfo(JLDeviceInfo &info);
261 void Wipe(bool apps = true, bool fs = true);
262 void LogStackTraces();
263 void ResetToFactory();
266 }} // namespace Barry::Mode
268 #endif