desktop: CalEditDlg: fixed dialog title bar
[barry.git] / src / m_javaloader.h
blob2f1b92a71d10c90087443ad05c097936dc7bd6db
1 ///
2 /// \file m_javaloader.h
3 /// Mode class for the JavaLoader mode
4 ///
6 /*
7 Copyright (C) 2005-2012, 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 "data.h"
31 #include "pin.h"
33 namespace Barry {
35 // forward declarations
36 class Parser;
37 class Builder;
38 class Controller;
39 class CodFileBuilder;
41 class JLDirectoryEntry;
43 class JLEventlogEntry;
45 class BXEXPORT JLDirectory : public std::vector<JLDirectoryEntry>
47 public:
48 typedef std::vector<JLDirectoryEntry> BaseType;
49 typedef BaseType::iterator BaseIterator;
50 typedef std::vector<uint16_t> TableType;
51 typedef TableType::iterator TableIterator;
53 private:
54 TableType m_idTable;
56 int m_level;
58 public:
59 JLDirectory(int level = 0);
60 ~JLDirectory();
62 int Level() const { return m_level; }
63 TableIterator TableBegin() { return m_idTable.begin(); }
64 TableIterator TableEnd() { return m_idTable.end(); }
66 void ParseTable(const Data &table_packet);
68 void Dump(std::ostream &os) const;
70 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectory &d) {
71 d.Dump(os);
72 return os;
75 class BXEXPORT JLDirectoryEntry
77 private:
78 int m_level;
80 public:
81 uint16_t Id;
82 std::string Name;
83 std::string Version;
84 uint32_t CodSize;
85 time_t Timestamp;
87 JLDirectory SubDir;
89 public:
90 explicit JLDirectoryEntry(int level);
92 void Parse(uint16_t id, const Data &entry_packet);
94 void Dump(std::ostream &os) const;
96 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectoryEntry &e) {
97 e.Dump(os);
98 return os;
102 class BXEXPORT JLScreenInfo {
103 public:
104 uint16_t width;
105 uint16_t height;
107 public:
108 JLScreenInfo();
109 ~JLScreenInfo();
113 class BXEXPORT JLEventlog : public std::vector<JLEventlogEntry>
115 public:
116 void Dump(std::ostream &os) const;
118 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLEventlog &log) {
119 log.Dump(os);
120 return os;
124 class BXEXPORT JLEventlogEntry
126 public:
127 typedef enum {
128 JES_ALWAYS_LOG,
129 JES_SEVERE_ERROR,
130 JES_ERROR,
131 JES_WARNING,
132 JES_INFORMATION,
133 JES_DEBUG_INFO
134 } Severity_t;
136 typedef enum {
137 JEVT_NUMBER = 1,
138 JEVT_STRING,
139 JEVT_EXCEPTION
140 } ViewerType_t;
142 std::string Guid;
143 uint64_t MSTimestamp; // time_t in milliseconds
144 Severity_t Severity;
145 ViewerType_t Type;
146 std::string App;
147 std::string Data;
149 protected:
150 static Severity_t SeverityProto2Rec(unsigned int s);
151 static unsigned int SeverityRec2Proto(Severity_t s);
153 static ViewerType_t ViewerTypeProto2Rec(unsigned int v);
154 static unsigned int ViewerTypeRec2Proto(ViewerType_t v);
156 public:
157 void Parse(uint16_t size, const char* str);
159 std::string GetFormattedTimestamp() const;
161 void Dump(std::ostream &os) const;
165 class BXEXPORT JLDeviceInfo
167 public:
168 struct VersionQuad {
169 VersionQuad() { }
170 VersionQuad(uint32_t v) {
171 Major = (v & 0xff000000) >> 24;
172 Minor = (v & 0xff0000) >> 16;
173 SubMinor = (v & 0xff00) >> 8;
174 Build = (v & 0xff);
177 unsigned int Major;
178 unsigned int Minor;
179 unsigned int SubMinor;
180 unsigned int Build;
183 public:
184 uint32_t HardwareId;
185 struct Pin Pin;
186 VersionQuad OsVersion;
187 VersionQuad VmVersion;
188 uint32_t RadioId;
189 uint32_t VendorId;
190 uint32_t ActiveWafs;
191 Data OsMetrics;
192 Data BootromMetrics;
194 public:
195 void Dump(std::ostream &os) const;
197 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDeviceInfo &info) {
198 info.Dump(os);
199 return os;
203 namespace Mode {
206 // JavaLoader class
208 /// The main interface class to the java program loader protocol
210 /// To use this class, use the following steps:
212 /// - Create a Controller object (see Controller class for more details)
213 /// - Create this Mode::JavaLoader object, passing in the Controller
214 /// object during construction
215 /// - Call Open() to open database socket and finish constructing.
216 /// - Call LoadDatabase() to retrieve and store a database
218 class BXEXPORT JavaLoader : public Mode
220 private:
221 bool m_StreamStarted;
223 protected:
224 void GetDirectoryEntries(JLPacket &packet, uint8_t entry_cmd,
225 JLDirectory &dir, bool include_subdirs);
226 void GetDir(JLPacket &packet, uint8_t entry_cmd, JLDirectory &dir,
227 bool include_subdirs);
228 void ThrowJLError(const std::string &msg, uint8_t cmd);
229 void DoErase(uint8_t cmd, const std::string &cod_name);
230 void SaveData(JLPacket &packet, uint16_t, CodFileBuilder &builder,
231 std::ostream &output);
233 //////////////////////////////////
234 // overrides
236 virtual void OnOpen();
238 public:
239 JavaLoader(Controller &con);
240 ~JavaLoader();
242 //////////////////////////////////
243 // API
244 void StartStream();
245 bool StopStream();
247 // mid-stream operations
248 void SendStream(std::istream &input, size_t module_size);
249 void LoadApp(std::istream &input);
250 void SetTime(time_t when);
251 void GetDirectory(JLDirectory &dir, bool include_subdirs);
252 void GetScreenshot(JLScreenInfo &info, Data &image);
253 void Erase(const std::string &cod_name);
254 void ForceErase(const std::string &cod_name);
255 void GetEventlog(JLEventlog &log);
256 void ClearEventlog();
257 void Save(const std::string &cod_name, std::ostream &output);
258 void DeviceInfo(JLDeviceInfo &info);
259 void Wipe(bool apps = true, bool fs = true);
260 void LogStackTraces();
261 void ResetToFactory();
264 }} // namespace Barry::Mode
266 #endif