Include OS and Bootrom metrics in deviceinfo output
[barry.git] / src / m_javaloader.h
blob8ec5461bb419c01d59af7a8dcb5245c3ae21cf3b
1 ///
2 /// \file m_javaloader.h
3 /// Mode class for the JavaLoader mode
4 ///
6 /*
7 Copyright (C) 2005-2009, 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"
34 namespace Barry {
36 // forward declarations
37 class Parser;
38 class Builder;
39 class Controller;
40 class CodFileBuilder;
42 class JLDirectoryEntry;
44 class JLEventlogEntry;
46 class BXEXPORT JLDirectory : public std::vector<JLDirectoryEntry>
48 public:
49 typedef std::vector<JLDirectoryEntry> BaseType;
50 typedef BaseType::iterator BaseIterator;
51 typedef std::vector<uint16_t> TableType;
52 typedef TableType::iterator TableIterator;
54 private:
55 TableType m_idTable;
57 int m_level;
59 public:
60 JLDirectory(int level = 0);
61 ~JLDirectory();
63 int Level() const { return m_level; }
64 TableIterator TableBegin() { return m_idTable.begin(); }
65 TableIterator TableEnd() { return m_idTable.end(); }
67 void ParseTable(const Data &table_packet);
69 void Dump(std::ostream &os) const;
71 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectory &d) {
72 d.Dump(os);
73 return os;
76 class BXEXPORT JLDirectoryEntry
78 private:
79 int m_level;
81 public:
82 uint16_t Id;
83 std::string Name;
84 std::string Version;
85 uint32_t CodSize;
86 time_t Timestamp;
88 JLDirectory SubDir;
90 public:
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 ALWAYS_LOG,
130 SEVERE_ERROR,
131 ERROR,
132 WARNING,
133 INFORMATION,
134 DEBUG_INFO
135 } Severity_t;
137 typedef enum {
138 NUMBER = 1,
139 STRING,
140 EXCEPTION
141 } ViewerType_t;
143 std::string Guid;
144 uint64_t Timestamp; //FIXME what is this? time since epoch? eg: 0x11F133E6470
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 void Dump(std::ostream &os) const;
164 class BXEXPORT JLDeviceInfo
166 public:
167 struct VersionQuad {
168 VersionQuad() { }
169 VersionQuad(uint32_t v) {
170 Major = (v & 0xff000000) >> 24;
171 Minor = (v & 0xff0000) >> 16;
172 SubMinor = (v & 0xff00) >> 8;
173 Build = (v & 0xff);
176 unsigned int Major;
177 unsigned int Minor;
178 unsigned int SubMinor;
179 unsigned int Build;
182 public:
183 uint32_t HardwareId;
184 uint32_t Pin;
185 VersionQuad OsVersion;
186 VersionQuad VmVersion;
187 uint32_t RadioId;
188 uint32_t VendorId;
189 uint32_t ActiveWafs;
190 Data OsMetrics;
191 Data BootromMetrics;
193 public:
194 void Dump(std::ostream &os) const;
196 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDeviceInfo &info) {
197 info.Dump(os);
198 return os;
202 namespace Mode {
205 // JavaLoader class
207 /// The main interface class to the java program loader protocol
209 /// To use this class, use the following steps:
211 /// - Create a Controller object (see Controller class for more details)
212 /// - Create this Mode::JavaLoader object, passing in the Controller
213 /// object during construction
214 /// - Call Open() to open database socket and finish constructing.
215 /// - Call LoadDatabase() to retrieve and store a database
217 class BXEXPORT JavaLoader : public Mode
219 private:
220 bool m_StreamStarted;
222 protected:
223 void GetDirectoryEntries(JLPacket &packet, uint8_t entry_cmd,
224 JLDirectory &dir, bool include_subdirs);
225 void GetDir(JLPacket &packet, uint8_t entry_cmd, JLDirectory &dir,
226 bool include_subdirs);
227 void ThrowJLError(const std::string &msg, uint8_t cmd);
228 void DoErase(uint8_t cmd, const std::string &cod_name);
229 void SaveData(JLPacket &packet, uint16_t, CodFileBuilder &builder,
230 std::ostream &output);
232 //////////////////////////////////
233 // overrides
235 virtual void OnOpen();
237 public:
238 JavaLoader(Controller &con);
239 ~JavaLoader();
241 //////////////////////////////////
242 // API
243 void StartStream();
244 bool StopStream();
246 // mid-stream operations
247 void SendStream(std::istream &input, size_t module_size);
248 void LoadApp(std::istream &input);
249 void SetTime(time_t when);
250 void GetDirectory(JLDirectory &dir, bool include_subdirs);
251 void GetScreenshot(JLScreenInfo &info, Data &image);
252 void Erase(const std::string &cod_name);
253 void ForceErase(const std::string &cod_name);
254 void GetEventlog(JLEventlog &log);
255 void ClearEventlog();
256 void Save(const std::string &cod_name, std::ostream &output);
257 void DeviceInfo(JLDeviceInfo &info);
260 }} // namespace Barry::Mode
262 #endif