controller.h

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

Generated on Tue Jun 30 16:08:13 2009 for Barry by  doxygen 1.5.8