2 /// \file m_javaloader.h
3 /// Mode class for the JavaLoader mode
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__
29 #include "m_mode_base.h"
36 // forward declarations
42 class JLDirectoryEntry
;
44 class JLEventlogEntry
;
46 class BXEXPORT JLDirectory
: public std::vector
<JLDirectoryEntry
>
49 typedef std::vector
<JLDirectoryEntry
> BaseType
;
50 typedef BaseType::iterator BaseIterator
;
51 typedef std::vector
<uint16_t> TableType
;
52 typedef TableType::iterator TableIterator
;
60 JLDirectory(int level
= 0);
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
) {
76 class BXEXPORT 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
) {
103 class BXEXPORT JLScreenInfo
{
114 class BXEXPORT JLEventlog
: public std::vector
<JLEventlogEntry
>
117 void Dump(std::ostream
&os
) const;
119 BXEXPORT
inline std::ostream
& operator<<(std::ostream
&os
, const JLEventlog
&log
) {
125 class BXEXPORT JLEventlogEntry
144 uint64_t MSTimestamp
; // time_t in milliseconds
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
);
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
171 VersionQuad(uint32_t v
) {
172 Major
= (v
& 0xff000000) >> 24;
173 Minor
= (v
& 0xff0000) >> 16;
174 SubMinor
= (v
& 0xff00) >> 8;
180 unsigned int SubMinor
;
187 VersionQuad OsVersion
;
188 VersionQuad VmVersion
;
196 void Dump(std::ostream
&os
) const;
198 BXEXPORT
inline std::ostream
& operator<<(std::ostream
&os
, const JLDeviceInfo
&info
) {
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
222 bool m_StreamStarted
;
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 //////////////////////////////////
237 virtual void OnOpen();
240 JavaLoader(Controller
&con
);
243 //////////////////////////////////
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