Javaloader list mode updates
[barry.git] / src / m_javaloader.h
blob5b76dae574d57b97b43aba16ba54747675954cac
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 "socket.h"
30 #include "record.h"
32 namespace Barry {
34 // forward declarations
35 class Parser;
36 class Builder;
37 class Controller;
39 class JLDirectoryEntry;
41 class BXEXPORT JLDirectory : public std::vector<JLDirectoryEntry>
43 public:
44 typedef std::vector<JLDirectoryEntry> BaseType;
45 typedef BaseType::iterator BaseIterator;
46 typedef std::vector<uint16_t> TableType;
47 typedef TableType::iterator TableIterator;
49 private:
50 TableType m_idTable;
52 int m_level;
54 public:
55 JLDirectory(int level = 0);
56 ~JLDirectory();
58 int Level() const { return m_level; }
59 TableIterator TableBegin() { return m_idTable.begin(); }
60 TableIterator TableEnd() { return m_idTable.end(); }
62 void ParseTable(const Data &table_packet);
64 void Dump(std::ostream &os) const;
66 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectory &d) {
67 d.Dump(os);
68 return os;
71 class BXEXPORT JLDirectoryEntry
73 private:
74 int m_level;
76 public:
77 uint16_t Id;
78 std::string Name;
79 std::string Version;
80 uint32_t CodSize;
81 time_t Timestamp;
83 JLDirectory SubDir;
85 public:
86 explicit JLDirectoryEntry(int level);
88 void Parse(uint16_t id, const Data &entry_packet);
90 void Dump(std::ostream &os) const;
92 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JLDirectoryEntry &e) {
93 e.Dump(os);
94 return os;
98 namespace Mode {
101 // JavaLoader class
103 /// The main interface class to the java program loader protocol
105 /// To use this class, use the following steps:
107 /// - Create a Controller object (see Controller class for more details)
108 /// - Create this Mode::JavaLoader object, passing in the Controller
109 /// object during construction
110 /// - Call Open() to open database socket and finish constructing.
111 /// - Call LoadDatabase() to retrieve and store a database
113 class BXEXPORT JavaLoader
115 private:
116 Controller &m_con;
118 SocketHandle m_socket;
120 uint16_t m_ModeSocket; // socket recommended by device
121 // when mode was selected
123 protected:
124 void GetDirectoryEntries(JLPacket &packet, uint8_t entry_cmd,
125 JLDirectory &dir, bool include_subdirs);
126 void GetDir(JLPacket &packet, uint8_t entry_cmd, JLDirectory &dir,
127 bool include_subdirs);
128 void ThrowJLError(const std::string &msg, uint8_t cmd);
130 public:
131 JavaLoader(Controller &con);
132 ~JavaLoader();
134 //////////////////////////////////
135 // primary operations - required before anything else
137 void Open(const char *password = 0);
138 void RetryPassword(const char *password);
140 //////////////////////////////////
141 // API
142 void StartStream();
143 void StopStream(void);
145 // mid-stream operations
146 void SendStream(char *buffer, int size);
147 void SetTime(time_t when);
148 void GetDirectory(JLDirectory &dir, bool include_subdirs);
151 }} // namespace Barry::Mode
153 #endif