00001 /// 00002 /// \file controller.h 00003 /// High level BlackBerry API class 00004 /// 00005 00006 /* 00007 Copyright (C) 2005-2008, 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 "probe.h" 00029 00030 /// Project namespace, containing all related functions and classes. 00031 /// This is the only namespace applications should be concerned with, 00032 /// for now. 00033 namespace Barry { 00034 00035 // forward declarations 00036 class SocketRoutingQueue; 00037 00038 namespace Mode { 00039 class Desktop; 00040 class IpModem; 00041 class Serial; 00042 } 00043 00044 // 00045 // Controller class 00046 // 00047 /// The main interface class. This class coordinates the communication to 00048 /// a single handheld. This class also owns the only Usb::Device object 00049 /// the handheld. All other classes reference this one for the low level 00050 /// device object. This class owns the only SocketZero object as well, 00051 /// which is the object that any SocketRoutingQueue is plugged into 00052 /// if constructed that way. 00053 /// 00054 /// To use this class, use the following steps: 00055 /// 00056 /// - Probe the USB bus for matching devices with the Probe class 00057 /// - Create an optional SocketRoutingQueue object and create a 00058 /// read thread for it, or use its default read thread. 00059 /// - Pass one of the probe results into the Controller constructor 00060 /// to connect to the USB device. Pass the routing queue 00061 /// to the Controller constructor here too, if needed. 00062 /// - Create the Mode object of your choice. See m_desktop.h 00063 /// and m_serial.h for these mode classes. You pass 00064 /// your controller object into these mode constructors 00065 /// to create the mode. 00066 /// 00067 class BXEXPORT Controller 00068 { 00069 friend class Barry::Mode::Desktop; 00070 friend class Barry::Mode::IpModem; 00071 friend class Barry::Mode::Serial; 00072 00073 public: 00074 /// Handheld mode type 00075 enum ModeType { 00076 Unspecified, //< default on start up (unused) 00077 Bypass, //< unsupported, unknown 00078 Desktop, //< desktop mode required for database 00079 //< operation 00080 JavaLoader, //< unsupported 00081 UsbSerData, //< GPRS modem support over USB 00082 UsbSerCtrl //< internally used behind the scenes 00083 }; 00084 00085 private: 00086 ProbeResult m_result; 00087 Usb::Device m_dev; 00088 Usb::Interface *m_iface; 00089 uint32_t m_pin; 00090 00091 SocketZero m_zero; 00092 SocketRoutingQueue *m_queue; //< ptr to external object; no delete 00093 00094 private: 00095 void SetupUsb(const ProbeResult &device); 00096 00097 protected: 00098 uint16_t SelectMode(ModeType mode); // returns mode socket 00099 00100 public: 00101 explicit Controller(const ProbeResult &device); 00102 Controller(const ProbeResult &device, SocketRoutingQueue &queue); 00103 ~Controller(); 00104 00105 bool HasQueue() const { return m_queue; } 00106 00107 const ProbeResult& GetProbeResult() const { return m_result; } 00108 }; 00109 00110 } // namespace Barry 00111 00112 #endif 00113