Homepage Demos Overview Downloads Tutorials Reference
Credits

Wireless.h

Go to the documentation of this file.
00001 
00002 #ifndef Wireless_h_DEFINED
00003 #define Wireless_h_DEFINED
00004 
00005 #include <OPENR/OObject.h>
00006 #include <OPENR/OSubject.h>
00007 #include <OPENR/OObserver.h>
00008 #include <ant.h>
00009 //#include "MMCombo/def.h"
00010 #include "Socket.h"
00011 #include "DummySocket.h"
00012 #include <list>
00013 
00014 using namespace SocketNS;
00015 using namespace __gnu_cxx;
00016 
00017 //! Tekkotsu wireless class
00018 /*!
00019  * For more information on using wireless, please read the following tutorials:
00020  * - <a href="../AiboMon.html">TekkotsuMon</a>
00021  * - <a href="../Wireless.html">TCP/IP</a>
00022  * - <a href="../RemoteProcess.html">Remote Processing OPENR</a>
00023  * Tekkotsu Wireless and Remote Processing OPENR provide different
00024  * interfaces to comparable wireless functionality.
00025  */
00026 class Wireless {
00027 public:
00028   //! Maximum number of sockets which can be created
00029   static const int WIRELESS_MAX_SOCKETS=100;
00030   
00031   //! Default number of bytes to use for receive buffers (overridden by value passed to socket())
00032   static const int WIRELESS_DEF_RECV_SIZE=1024;
00033   
00034   //! Default number of bytes to use for send buffers (overridden by value passed to socket())
00035   static const int WIRELESS_DEF_SEND_SIZE=1024;
00036   
00037   //! constructor - only one wireless object is required per Aperios process. 
00038   /*! MMCombo already creates one. The (global) instance is called wireless,
00039    * and you can access it by including Wireless/Wireless.h (this file) in
00040    * your code
00041    */
00042   Wireless();
00043   ~Wireless(); //!< destructor
00044   
00045   //@{
00046   //! Creates a new socket
00047   /*! @return pointer to Socket object created
00048    * @param ttype selects between TCP and UDP
00049    * @see WIRELESS_DEF_RECV_SIZE, WIRELESS_DEF_SEND_SIZE */
00050   Socket* socket(TransportType_t ttype);
00051   /*!@param ttype selects between TCP and UDP
00052    * @param recvsize size of input buffer
00053    * @param sendsize size of output buffer
00054    */
00055   Socket* socket(TransportType_t ttype, int recvsize, int sendsize);
00056   //@}
00057 
00058   //! The socket waits for incoming connections.
00059   /*! That is, it acts like a server. If a connection is established and
00060    * later broken, it resumes waiting for new connections.
00061    */
00062   int listen(int sock, int port);
00063 
00064   //! The socket tries to connect to a specific
00065   int connect(int sock, const char* ipaddr, int port);
00066   //! sets receiver callback for a socket
00067   void setReceiver(int sock, int (*rcvcbckfn) (char*, int) );
00068   //! sets the socket to be a daemon (recycles on close)
00069   void setDaemon(int sock, bool val=true) { sockets[sock]->daemon=val; }
00070   //! closes and destroys non server, daemon sockets
00071   void close(int sock);
00072 
00073   //@{
00074   //! utility function that you can use if you're curious about the state of the socket.
00075   /*! You shouldn't need to use it, since asking sockets for write
00076    * and read buffers does the necessary sanity checks
00077    */
00078   bool isConnected(int sock) { return sockets[sock]->state
00079                                         ==CONNECTION_CONNECTED; }
00080   bool isReady(int sock) { return !sockets[sock]->tx; }
00081   bool hasData(int sock) { return !sockets[sock]->rx; }
00082   //@}
00083 
00084   //@{
00085   //! helper function for the function with the same name that takes a socket descriptor (int)
00086   void setReceiver(Socket &sobj, int (*rcvcbckfn) (char*, int) )
00087     { setReceiver(sobj.sock, rcvcbckfn); }
00088   void setReceiver(Socket *sobj, int (*rcvcbckfn) (char*, int) )
00089     { setReceiver(sobj->sock, rcvcbckfn); }
00090   void setDaemon(Socket &sobj, bool val=true) { setDaemon(sobj.sock, val); }
00091   void setDaemon(Socket *sobj, bool val=true) { setDaemon(sobj->sock, val); }
00092   int listen(Socket &sobj, int port) { return listen(sobj.sock, port); } 
00093   int listen(Socket *sobj, int port) { return listen(sobj->sock, port); } 
00094   int connect(Socket &sobj, const char* ipaddr, int port)
00095     { return connect (sobj.sock, ipaddr, port); }
00096   int connect(Socket *sobj, const char* ipaddr, int port)
00097     { return connect (sobj->sock, ipaddr, port); }
00098   void close(Socket &sobj) { close(sobj.sock); }
00099   void close(Socket *sobj) { close(sobj->sock); }
00100   //@}
00101 
00102   //@{
00103   //! function for internal and Socket use. You should not call this
00104   void receive(int sock, int (*rcvcbckfn) (char*, int) );
00105   void receive(int sock);
00106   //@}
00107 
00108   //@{
00109   //! function called by the Socket objects to actually write
00110   //! data to the network. You should not call this.
00111   void send(int sock);
00112   void blockingSend(int sock);
00113   //@}
00114   
00115 
00116   //@{
00117   //! callback function for communicating
00118   //! with Aperios Networking Toolkit. You should not call this.
00119   void ListenCont (void* msg);
00120   void BindCont   (void* msg);
00121   void ConnectCont(void* msg);
00122   void SendCont   (void* msg);
00123   void ReceiveCont(void* msg);
00124   void CloseCont  (void* msg);
00125   //@}
00126 
00127 private:
00128   //@{
00129   //!private ALOKL_TODO
00130   antStackRef ipstackRef;
00131   OID myOID;
00132   Socket* sockets[WIRELESS_MAX_SOCKETS];
00133   list<int> freeSockets;
00134   //@}
00135 
00136 private:
00137   Wireless(const Wireless&); //!< don't call
00138   Wireless& operator= (const Wireless&); //!< don't call
00139 };
00140 
00141 //! the global wireless object - you'll want to make your function calls on this
00142 extern Wireless* wireless;
00143 
00144 /*! @file
00145  * @brief Interacts with the system to provide networking services
00146  * @author alokl (Creator)
00147  * 
00148  * @verbinclude CMPack_license.txt
00149  *
00150  * $Author: alokl $
00151  * $Name: tekkotsu-2_0 $
00152  * $Revision: 1.14 $
00153  * $State: Rel $
00154  * $Date: 2003/09/21 19:43:41 $
00155  */
00156 
00157 #endif // Wireless_h_DEFINED

Tekkotsu v2.0
Generated Wed Jan 21 03:20:30 2004 by Doxygen 1.3.4