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  * The networking interface needs more documentation.  It also needs a
00027  * cleanup.  In the mean time, take a look at the TekkotsuMon objects
00028  * in <i>Tekkotsu</i><tt>/Behaviors/Mon</tt>.  They all listen for new
00029  * connections.  Unfortunately, at the momement there are no examples
00030  * of outgoing connections, but it should give you a pretty good idea
00031  * how to start moving.
00032  */
00033 class Wireless {
00034 public:
00035   //! Maximum number of sockets which can be created
00036   static const int WIRELESS_MAX_SOCKETS=100;
00037   
00038   //! Default number of bytes to use for receive buffers (overridden by value passed to socket())
00039   static const int WIRELESS_DEF_RECV_SIZE=1024;
00040   
00041   //! Default number of bytes to use for send buffers (overridden by value passed to socket())
00042   static const int WIRELESS_DEF_SEND_SIZE=1024;
00043   
00044   //! constructor - only one wireless object is required per Aperios process. 
00045   /*! MMCombo already creates one. The (global) instance is called wireless,
00046    * and you can access it by including Wireless/Wireless.h (this file) in
00047    * your code
00048    */
00049   Wireless();
00050   ~Wireless(); //!< destructor
00051   
00052   //@{
00053   //! Creates a new socket
00054   /*! @return pointer to Socket object created
00055    * @param ttype selects between TCP and UDP
00056    * @see WIRELESS_DEF_RECV_SIZE, WIRELESS_DEF_SEND_SIZE */
00057   Socket* socket(TransportType_t ttype);
00058   /*!@param ttype selects between TCP and UDP
00059    * @param recvsize size of input buffer
00060    * @param sendsize size of output buffer
00061    */
00062   Socket* socket(TransportType_t ttype, int recvsize, int sendsize);
00063   //@}
00064 
00065   //! The socket waits for incoming connections.
00066   /*! That is, it acts like a server. If a connection is established and
00067    * later broken, it resumes waiting for new connections.
00068    */
00069   int listen(int sock, int port);
00070 
00071   //! The socket tries to connect to a specific
00072   int connect(int sock, const char* ipaddr, int port);
00073   //! sets receiver callback for a socket
00074   void setReceiver(int sock, int (*rcvcbckfn) (char*, int) );
00075   //! sets the socket to be a daemon (recycles on close)
00076   void setDaemon(int sock, bool val=true) { sockets[sock]->daemon=val; }
00077   //! closes and destroys non server, daemon sockets
00078   void close(int sock);
00079 
00080   //@{
00081   //! utility function that you can use if you're curious about the state of the socket.
00082   /*! You shouldn't need to use it, since asking sockets for write
00083    * and read buffers does the necessary sanity checks
00084    */
00085   bool isConnected(int sock) { return sockets[sock]->state
00086                                         ==CONNECTION_CONNECTED; }
00087   bool isReady(int sock) { return !sockets[sock]->tx; }
00088   bool hasData(int sock) { return !sockets[sock]->rx; }
00089   //@}
00090 
00091   //@{
00092   //! helper function for the function with the same name that takes a socket descriptor (int)
00093   void setReceiver(Socket &sobj, int (*rcvcbckfn) (char*, int) )
00094     { setReceiver(sobj.sock, rcvcbckfn); }
00095   void setReceiver(Socket *sobj, int (*rcvcbckfn) (char*, int) )
00096     { setReceiver(sobj->sock, rcvcbckfn); }
00097   void setDaemon(Socket &sobj, bool val=true) { setDaemon(sobj.sock, val); }
00098   void setDaemon(Socket *sobj, bool val=true) { setDaemon(sobj->sock, val); }
00099   int listen(Socket &sobj, int port) { return listen(sobj.sock, port); } 
00100   int listen(Socket *sobj, int port) { return listen(sobj->sock, port); } 
00101   int connect(Socket &sobj, const char* ipaddr, int port)
00102     { return connect (sobj.sock, ipaddr, port); }
00103   int connect(Socket *sobj, const char* ipaddr, int port)
00104     { return connect (sobj->sock, ipaddr, port); }
00105   void close(Socket &sobj) { close(sobj.sock); }
00106   void close(Socket *sobj) { close(sobj->sock); }
00107   unsigned int getNumInterfaces() { return 1; }
00108   uint32 getIPAddress(unsigned int idx=0);
00109   //@}
00110 
00111   //@{
00112   //! function for internal and Socket use. You should not call this
00113   void receive(int sock, int (*rcvcbckfn) (char*, int) );
00114   void receive(int sock);
00115   //@}
00116 
00117   //@{
00118   //! function called by the Socket objects to actually write
00119   //! data to the network. You should not call this.
00120   void send(int sock);
00121   void blockingSend(int sock);
00122   //@}
00123   
00124 
00125   //@{
00126   //! callback function for communicating
00127   //! with Aperios Networking Toolkit. You should not call this.
00128   void ListenCont (void* msg);
00129   void BindCont   (void* msg);
00130   void ConnectCont(void* msg);
00131   void SendCont   (void* msg);
00132   void ReceiveCont(void* msg);
00133   void CloseCont  (void* msg);
00134   //@}
00135 
00136 private:
00137   //@{
00138   //!private ALOKL_TODO
00139   antStackRef ipstackRef;
00140   OID myOID;
00141   Socket* sockets[WIRELESS_MAX_SOCKETS];
00142   list<int> freeSockets;
00143   //@}
00144 
00145 private:
00146   Wireless(const Wireless&); //!< don't call
00147   Wireless& operator= (const Wireless&); //!< don't call
00148 };
00149 
00150 //! the global wireless object - you'll want to make your function calls on this
00151 extern Wireless* wireless;
00152 
00153 /*! @file
00154  * @brief Interacts with the system to provide networking services
00155  * @author alokl (Creator)
00156  * 
00157  * @verbinclude CMPack_license.txt
00158  *
00159  * $Author: ejt $
00160  * $Name: tekkotsu-2_3 $
00161  * $Revision: 1.17 $
00162  * $State: Exp $
00163  * $Date: 2005/01/27 05:40:46 $
00164  */
00165 
00166 #endif // Wireless_h_DEFINED

Tekkotsu v2.3
Generated Sat Jan 29 02:25:24 2005 by Doxygen 1.4.0