- added src/endian.h... still need to add configure support to
[barry.git] / src / controller.h
blob1c5e34adcec9a7735298d2bde9866b1911f23065
1 ///
2 /// \file controller.h
3 /// High level BlackBerry API class
4 ///
6 /*
7 Copyright (C) 2005-2006, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_CONTROLLER_H__
23 #define __BARRY_CONTROLLER_H__
25 #include "usbwrap.h"
26 #include "probe.h"
27 #include "socket.h"
28 #include "record.h"
30 /// Project namespace, containing all related functions and classes.
31 /// This is the only namespace applications should be concerned with,
32 /// for now.
33 namespace Barry {
35 // forward declarations
36 class Parser;
37 class Builder;
40 // Controller class
42 /// The main interface class. This class coordinates the communication to
43 /// a single handheld.
44 ///
45 /// To use this class, use the following steps:
46 ///
47 /// - Probe the USB bus for matching devices with the Probe class
48 /// - Pass one of the probe results into the Controller constructor
49 /// to connect
50 /// - Call OpenMode() to select the desired mode. This will fill all
51 /// internal data structures for that mode, such as the
52 /// Database Database in Desktop mode.
53 /// NOTE: only Desktop mode is currently implemented.
54 /// - Call GetDBDB() to get the device's database database
55 /// - Call GetDBID() to get a database ID by name
56 /// - In Desktop mode, call LoadDatabase() to retrieve and store a database
57 ///
58 class Controller
60 public:
61 /// Handheld mode type
62 enum ModeType {
63 Unspecified, //< default on start up
64 Bypass, //< unsupported, unknown
65 Desktop, //< desktop mode required for database
66 //< operation
67 JavaLoader //< unsupported
69 enum CommandType { Unknown, DatabaseAccess };
71 private:
72 Usb::Device m_dev;
73 Usb::Interface *m_iface;
74 uint32_t m_pin;
76 Socket m_socket;
78 CommandTable m_commandTable;
79 DatabaseDatabase m_dbdb;
81 ModeType m_mode;
83 protected:
84 void SelectMode(ModeType mode, uint16_t &socket, uint8_t &flag);
85 unsigned int GetCommand(CommandType ct);
87 void LoadCommandTable();
88 void LoadDBDB();
90 public:
91 Controller(const ProbeResult &device);
92 ~Controller();
94 //////////////////////////////////
95 // meta access
97 /// Returns DatabaseDatabase object for this connection.
98 /// Must call OpenMode() to select Desktop mode first
99 const DatabaseDatabase& GetDBDB() const { return m_dbdb; }
100 unsigned int GetDBID(const std::string &name) const;
102 //////////////////////////////////
103 // general operations
104 void OpenMode(ModeType mode);
106 //////////////////////////////////
107 // Desktop mode - database specific
108 void LoadDatabase(unsigned int dbId, Parser &parser);
109 void SaveDatabase(unsigned int dbId, Builder &builder);
111 template <class RecordT, class StorageT> void LoadDatabaseByType(StorageT &store);
112 template <class RecordT, class StorageT> void SaveDatabaseByType(StorageT &store);
114 template <class StorageT> void LoadDatabaseByName(const std::string &name, StorageT &store);
115 template <class StorageT> void SaveDatabaseByName(const std::string &name, StorageT &store);
118 } // namespace Barry
120 #endif