m_serial.h

Go to the documentation of this file.
00001 ///
00002 /// \file       m_serial.h
00003 ///             Mode class for serial / GPRS modem mode
00004 ///
00005 
00006 /*
00007     Copyright (C) 2008-2012, 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_M_SERIAL_H__
00023 #define __BARRY_M_SERIAL_H__
00024 
00025 #include "dll.h"
00026 #include "modem.h"
00027 #include "socket.h"
00028 #include "data.h"
00029 #include "pppfilter.h"
00030 
00031 namespace Barry {
00032 
00033 // forward declarations
00034 class Controller;
00035 
00036 namespace Mode {
00037 
00038 class BXEXPORT Serial : public Modem
00039 {
00040 public:
00041         typedef void (*DeviceDataCallback)(void *context, const unsigned char *data, int len);
00042 
00043 private:
00044         Controller &m_con;
00045 
00046         SocketHandle m_data;
00047         SocketHandle m_ctrl;
00048 
00049         uint16_t m_ModeSocket;                  // socket recommended by device
00050                                                 // when mode was selected
00051         uint16_t m_CtrlSocket;
00052 
00053         // PPP filtering
00054         PppFilter m_filter;
00055 
00056         // UsbSerData cache
00057 //      Data m_readCache;
00058 
00059         // external callbacks
00060         DeviceDataCallback m_callback;
00061         void *m_callback_context;
00062 
00063 protected:
00064         static void DataCallback(Serial &context, Data *data);
00065         static void CtrlCallback(Serial &context, Data *data);
00066 
00067 public:
00068         Serial(Controller &con, DeviceDataCallback callback, void *callback_context);
00069         ~Serial();
00070 
00071         //////////////////////////////////
00072         // general operations
00073         void Open(const char *password = 0);    // FIXME password needed?  if not,
00074                                                 // then we can remove it from
00075                                                 // the Modem base class
00076         void Close();
00077         void RetryPassword(const char *password);
00078 
00079         //////////////////////////////////
00080         // UsbSerData mode - modem specific
00081 
00082 //      void Read(Data &data, int timeout); // can be called from separate thread
00083         void Write(const Data &data, int timeout = -1);
00084 };
00085 
00086 }} // namespace Barry::Mode
00087 
00088 #endif
00089