debian: added giffgaff chatscripts
[barry.git] / src / m_javaloader.h
blobbe9c33030dbaa020a2667adc7120f4eee0881e51
1 ///
2 /// \file m_javaloader.h
3 /// Mode class for the JavaLoader mode
4 ///
6 /*
7 Copyright (C) 2005-2013, 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 JLDirectoryEntry();
91 explicit JLDirectoryEntry(int level);
93 void Parse(uint16_t id, const Data &entry_packet);
95 void Dump(std::ostream &os) const;
97 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectoryEntry &e) {
98 e.Dump(os);
99 return os;
103 class BXEXPORT JLScreenInfo {
104 public:
105 uint16_t width;
106 uint16_t height;
108 public:
109 JLScreenInfo();
110 ~JLScreenInfo();
114 class BXEXPORT JLEventlog : public std::vector<JLEventlogEntry>
116 public:
117 void Dump(std::ostream &os) const;
119 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLEventlog &log) {
120 log.Dump(os);
121 return os;
125 class BXEXPORT JLEventlogEntry
127 public:
128 typedef enum {
129 JES_ALWAYS_LOG,
130 JES_SEVERE_ERROR,
131 JES_ERROR,
132 JES_WARNING,
133 JES_INFORMATION,
134 JES_DEBUG_INFO
135 } Severity_t;
137 typedef enum {
138 JEVT_NUMBER = 1,
139 JEVT_STRING,
140 JEVT_EXCEPTION
141 } ViewerType_t;
143 std::string Guid;
144 uint64_t MSTimestamp; // time_t in milliseconds
145 Severity_t Severity;
146 ViewerType_t Type;
147 std::string App;
148 std::string Data;
150 protected:
151 static Severity_t SeverityProto2Rec(unsigned int s);
152 static unsigned int SeverityRec2Proto(Severity_t s);
154 static ViewerType_t ViewerTypeProto2Rec(unsigned int v);
155 static unsigned int ViewerTypeRec2Proto(ViewerType_t v);
157 public:
158 void Parse(uint16_t size, const char* str);
160 std::string GetFormattedTimestamp() const;
162 void Dump(std::ostream &os) const;
166 class BXEXPORT JLDeviceInfo
168 public:
169 struct VersionQuad {
170 VersionQuad() { }
171 VersionQuad(uint32_t v) {
172 Major = (v & 0xff000000) >> 24;
173 Minor = (v & 0xff0000) >> 16;
174 SubMinor = (v & 0xff00) >> 8;
175 Build = (v & 0xff);
178 unsigned int Major;
179 unsigned int Minor;
180 unsigned int SubMinor;
181 unsigned int Build;
184 public:
185 uint32_t HardwareId;
186 class Pin Pin;
187 VersionQuad OsVersion;
188 VersionQuad VmVersion;
189 uint32_t RadioId;
190 uint32_t VendorId;
191 uint32_t ActiveWafs;
192 Data OsMetrics;
193 Data BootromMetrics;
195 public:
196 void Dump(std::ostream &os) const;
198 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDeviceInfo &info) {
199 info.Dump(os);
200 return os;
204 namespace Mode {
207 // JavaLoader class
209 /// The main interface class to the java program loader protocol
211 /// To use this class, use the following steps:
213 /// - Create a Controller object (see Controller class for more details)
214 /// - Create this Mode::JavaLoader object, passing in the Controller
215 /// object during construction
216 /// - Call Open() to open database socket and finish constructing.
217 /// - Call LoadDatabase() to retrieve and store a database
219 class BXEXPORT JavaLoader : public Mode
221 private:
222 bool m_StreamStarted;
224 protected:
225 void GetDirectoryEntries(JLPacket &packet, uint8_t entry_cmd,
226 JLDirectory &dir, bool include_subdirs);
227 void GetDir(JLPacket &packet, uint8_t entry_cmd, JLDirectory &dir,
228 bool include_subdirs);
229 void ThrowJLError(const std::string &msg, uint8_t cmd);
230 void DoErase(uint8_t cmd, const std::string &cod_name);
231 void SaveData(JLPacket &packet, uint16_t, CodFileBuilder &builder,
232 std::ostream &output);
234 //////////////////////////////////
235 // overrides
237 virtual void OnOpen();
239 public:
240 JavaLoader(Controller &con);
241 ~JavaLoader();
243 //////////////////////////////////
244 // API
245 void StartStream();
246 bool StopStream();
248 // mid-stream operations
249 void SendStream(std::istream &input, size_t module_size);
250 void LoadApp(std::istream &input);
251 void SetTime(time_t when);
252 void GetDirectory(JLDirectory &dir, bool include_subdirs);
253 void GetScreenshot(JLScreenInfo &info, Data &image);
254 void Erase(const std::string &cod_name);
255 void ForceErase(const std::string &cod_name);
256 void GetEventlog(JLEventlog &log);
257 void ClearEventlog();
258 void Save(const std::string &cod_name, std::ostream &output);
259 void DeviceInfo(JLDeviceInfo &info);
260 void Wipe(bool apps = true, bool fs = true);
261 void LogStackTraces();
262 void ResetToFactory();
265 }} // namespace Barry::Mode
267 #endif