menu: added new Keywords tag to .desktop files
[barry.git] / src / controller.h
blob25f0fe25927c3268c3bccd5008dd0c2619625d6e
1 ///
2 /// \file controller.h
3 /// High level BlackBerry API class
4 ///
6 /*
7 Copyright (C) 2005-2013, 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 "dll.h"
26 #include "socket.h"
28 /// Project namespace, containing all related functions and classes.
29 /// This is the only namespace applications should be concerned with,
30 /// for now.
31 namespace Barry {
33 // forward declarations
34 class SocketRoutingQueue;
35 struct ProbeResult;
37 class PrivateControllerData;
39 namespace Mode {
40 class Mode;
41 class IpModem;
42 class Serial;
43 class JavaLoader;
44 class JVMDebug;
45 class RawChannel;
49 // Controller class
51 /// The main interface class. This class coordinates the communication to
52 /// a single handheld. This class also owns the only Usb::Device object
53 /// the handheld. All other classes reference this one for the low level
54 /// device object. This class owns the only SocketZero object as well,
55 /// which is the object that any SocketRoutingQueue is plugged into
56 /// if constructed that way.
57 ///
58 /// To use this class, use the following steps:
59 ///
60 /// - Probe the USB bus for matching devices with the Probe class
61 /// - Create an optional SocketRoutingQueue object and create a
62 /// read thread for it, or use its default read thread.
63 /// - Pass one of the probe results into the Controller constructor
64 /// to connect to the USB device. Pass the routing queue
65 /// to the Controller constructor here too, if needed.
66 /// - Create the Mode object of your choice. See m_desktop.h
67 /// and m_serial.h for these mode classes. You pass
68 /// your controller object into these mode constructors
69 /// to create the mode.
70 ///
71 class BXEXPORT Controller
73 friend class Barry::Mode::Mode;
74 friend class Barry::Mode::IpModem;
75 friend class Barry::Mode::Serial;
76 friend class Barry::Mode::JavaLoader;
77 friend class Barry::Mode::JVMDebug;
78 friend class Barry::Mode::RawChannel;
80 public:
81 /// Handheld mode type
82 enum ModeType {
83 Unspecified, //< default on start up (unused)
84 Bypass, //< unsupported, unknown
85 Desktop, //< desktop mode required for database
86 //< operation
87 JavaLoader, //< experimental
88 JVMDebug, //< experimental
89 UsbSerData, //< GPRS modem support over USB
90 UsbSerCtrl, //< internally used behind the scenes
91 RawChannel //< raw channel
94 private:
95 const std::auto_ptr<PrivateControllerData> m_priv;
97 private:
98 Controller(const Controller& rhs); // prevent copying
99 void SetupUsb(const ProbeResult &device);
101 protected:
102 uint16_t SelectMode(ModeType mode); // returns mode socket
103 uint16_t SelectMode(ModeType mode, const char *explicitModeName); // returns mode socket
104 SocketHandle OpenSocket(uint16_t socket, const char *password = 0);
105 SocketHandle OpenSocket(
106 SocketRoutingQueue::SocketDataHandlerPtr handler,
107 uint16_t socket, const char *password = 0);
108 PrivateControllerData* GetPrivate() { return m_priv.get(); }
110 public:
111 explicit Controller(const ProbeResult &device,
112 int default_timeout = USBWRAP_DEFAULT_TIMEOUT);
113 Controller(const ProbeResult &device, SocketRoutingQueue &queue,
114 int default_timeout = USBWRAP_DEFAULT_TIMEOUT);
115 ~Controller();
117 bool HasQueue() const;
118 SocketRoutingQueue* GetQueue(); // FIXME - not really ideal to have
119 // this exposed, but oh well
121 const ProbeResult& GetProbeResult() const;
124 } // namespace Barry
126 #endif