3 /// High level BlackBerry API class
7 Copyright (C) 2005-2007, 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__
31 /// Project namespace, containing all related functions and classes.
32 /// This is the only namespace applications should be concerned with,
36 // forward declarations
44 /// The main interface class. This class coordinates the communication to
45 /// a single handheld.
47 /// To use this class, use the following steps:
49 /// - Probe the USB bus for matching devices with the Probe class
50 /// - Pass one of the probe results into the Controller constructor
52 /// - Call OpenMode() to select the desired mode. This will fill all
53 /// internal data structures for that mode, such as the
54 /// Database Database in Desktop mode.
55 /// NOTE: only Desktop mode is currently implemented.
56 /// - Call GetDBDB() to get the device's database database
57 /// - Call GetDBID() to get a database ID by name
58 /// - In Desktop mode, call LoadDatabase() to retrieve and store a database
62 friend class Barry::DBPacket
;
65 /// Handheld mode type
67 Unspecified
, //< default on start up
68 Bypass
, //< unsupported, unknown
69 Desktop
, //< desktop mode required for database
71 JavaLoader
, //< unsupported
72 UsbSerData
//< GPRS modem support over USB
74 enum CommandType
{ Unknown
, DatabaseAccess
};
78 Usb::Interface
*m_iface
;
83 CommandTable m_commandTable
;
84 DatabaseDatabase m_dbdb
;
88 uint16_t m_modeSocket
; // socket recommended by device
89 // when mode was selected
92 Data m_writeCache
, m_readCache
;
94 // tracking of open Desktop socket, and the need to reset
98 void SelectMode(ModeType mode
);
99 unsigned int GetCommand(CommandType ct
);
101 void LoadCommandTable();
105 Controller(const ProbeResult
&device
);
108 //////////////////////////////////
111 /// Returns DatabaseDatabase object for this connection.
112 /// Must call OpenMode() to select Desktop mode first
113 const DatabaseDatabase
& GetDBDB() const { return m_dbdb
; }
114 unsigned int GetDBID(const std::string
&name
) const;
116 //////////////////////////////////
117 // general operations
118 void OpenMode(ModeType mode
, const char *password
= 0);
119 void RetryPassword(const char *password
);
121 //////////////////////////////////
122 // Desktop mode - database specific
124 // dirty flag related functions, for sync operations
125 void GetRecordStateTable(unsigned int dbId
, RecordStateTable
&result
);
126 void AddRecord(unsigned int dbId
, Builder
&build
); // RecordId is
127 // retrieved from build, and duplicate IDs are allowed,
128 // but *not* recommended!
129 void GetRecord(unsigned int dbId
, unsigned int stateTableIndex
, Parser
&parser
);
130 void SetRecord(unsigned int dbId
, unsigned int stateTableIndex
, Builder
&build
);
131 void ClearDirty(unsigned int dbId
, unsigned int stateTableIndex
);
132 void DeleteRecord(unsigned int dbId
, unsigned int stateTableIndex
);
134 // pure load/save operations
135 void LoadDatabase(unsigned int dbId
, Parser
&parser
);
136 void SaveDatabase(unsigned int dbId
, Builder
&builder
);
138 template <class RecordT
, class StorageT
> void LoadDatabaseByType(StorageT
&store
);
139 template <class RecordT
, class StorageT
> void SaveDatabaseByType(StorageT
&store
);
141 template <class StorageT
> void LoadDatabaseByName(const std::string
&name
, StorageT
&store
);
142 template <class StorageT
> void SaveDatabaseByName(const std::string
&name
, StorageT
&store
);
144 template <class RecordT
> void AddRecordByType(uint32_t recordId
, const RecordT
&rec
);
147 //////////////////////////////////
148 // UsbSerData mode - modem specific
150 void SerialRead(Data
&data
, int timeout
); // can be called from separate thread
151 void SerialWrite(const Data
&data
);