00001 /// 00002 /// \file controller.h 00003 /// High level BlackBerry API class 00004 /// 00005 00006 /* 00007 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/) 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00017 00018 See the GNU General Public License in the COPYING file at the 00019 root directory of this project for more details. 00020 */ 00021 00022 #ifndef __BARRY_CONTROLLER_H__ 00023 #define __BARRY_CONTROLLER_H__ 00024 00025 #include "dll.h" 00026 #include "usbwrap.h" 00027 #include "socket.h" 00028 #include "pin.h" 00029 #include "probe.h" 00030 00031 /// Project namespace, containing all related functions and classes. 00032 /// This is the only namespace applications should be concerned with, 00033 /// for now. 00034 namespace Barry { 00035 00036 // forward declarations 00037 class SocketRoutingQueue; 00038 00039 namespace Mode { 00040 class Mode; 00041 class IpModem; 00042 class Serial; 00043 class JavaLoader; 00044 class JVMDebug; 00045 } 00046 00047 // 00048 // Controller class 00049 // 00050 /// The main interface class. This class coordinates the communication to 00051 /// a single handheld. This class also owns the only Usb::Device object 00052 /// the handheld. All other classes reference this one for the low level 00053 /// device object. This class owns the only SocketZero object as well, 00054 /// which is the object that any SocketRoutingQueue is plugged into 00055 /// if constructed that way. 00056 /// 00057 /// To use this class, use the following steps: 00058 /// 00059 /// - Probe the USB bus for matching devices with the Probe class 00060 /// - Create an optional SocketRoutingQueue object and create a 00061 /// read thread for it, or use its default read thread. 00062 /// - Pass one of the probe results into the Controller constructor 00063 /// to connect to the USB device. Pass the routing queue 00064 /// to the Controller constructor here too, if needed. 00065 /// - Create the Mode object of your choice. See m_desktop.h 00066 /// and m_serial.h for these mode classes. You pass 00067 /// your controller object into these mode constructors 00068 /// to create the mode. 00069 /// 00070 class BXEXPORT Controller 00071 { 00072 friend class Barry::Mode::Mode; 00073 friend class Barry::Mode::IpModem; 00074 friend class Barry::Mode::Serial; 00075 friend class Barry::Mode::JavaLoader; 00076 friend class Barry::Mode::JVMDebug; 00077 00078 public: 00079 /// Handheld mode type 00080 enum ModeType { 00081 Unspecified, //< default on start up (unused) 00082 Bypass, //< unsupported, unknown 00083 Desktop, //< desktop mode required for database 00084 //< operation 00085 JavaLoader, //< experimental 00086 JVMDebug, //< experimental 00087 UsbSerData, //< GPRS modem support over USB 00088 UsbSerCtrl //< internally used behind the scenes 00089 }; 00090 00091 private: 00092 ProbeResult m_result; 00093 Usb::Device m_dev; 00094 Usb::Interface *m_iface; 00095 Pin m_pin; 00096 00097 SocketZero m_zero; 00098 SocketRoutingQueue *m_queue; //< ptr to external object; no delete 00099 00100 private: 00101 void SetupUsb(const ProbeResult &device); 00102 00103 protected: 00104 uint16_t SelectMode(ModeType mode); // returns mode socket 00105 00106 public: 00107 explicit Controller(const ProbeResult &device); 00108 Controller(const ProbeResult &device, SocketRoutingQueue &queue); 00109 ~Controller(); 00110 00111 bool HasQueue() const { return m_queue; } 00112 00113 const ProbeResult& GetProbeResult() const { return m_result; } 00114 }; 00115 00116 } // namespace Barry 00117 00118 #endif 00119