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   //@}
00108 
00109   //@{
00110   //! function for internal and Socket use. You should not call this
00111   void receive(int sock, int (*rcvcbckfn) (char*, int) );
00112   void receive(int sock);
00113   //@}
00114 
00115   //@{
00116   //! function called by the Socket objects to actually write
00117   //! data to the network. You should not call this.
00118   void send(int sock);
00119   void blockingSend(int sock);
00120   //@}
00121   
00122 
00123   //@{
00124   //! callback function for communicating
00125   //! with Aperios Networking Toolkit. You should not call this.
00126   void ListenCont (void* msg);
00127   void BindCont   (void* msg);
00128   void ConnectCont(void* msg);
00129   void SendCont   (void* msg);
00130   void ReceiveCont(void* msg);
00131   void CloseCont  (void* msg);
00132   //@}
00133 
00134 private:
00135   //@{
00136   //!private ALOKL_TODO
00137   antStackRef ipstackRef;
00138   OID myOID;
00139   Socket* sockets[WIRELESS_MAX_SOCKETS];
00140   list<int> freeSockets;
00141   //@}
00142 
00143 private:
00144   Wireless(const Wireless&); //!< don't call
00145   Wireless& operator= (const Wireless&); //!< don't call
00146 };
00147 
00148 //! the global wireless object - you'll want to make your function calls on this
00149 extern Wireless* wireless;
00150 
00151 /*! @file
00152  * @brief Interacts with the system to provide networking services
00153  * @author alokl (Creator)
00154  * 
00155  * @verbinclude CMPack_license.txt
00156  *
00157  * $Author: ejt $
00158  * $Name: tekkotsu-2_2_2 $
00159  * $Revision: 1.15 $
00160  * $State: Exp $
00161  * $Date: 2004/03/24 06:38:21 $
00162  */
00163 
00164 #endif // Wireless_h_DEFINED

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:16 2005 by Doxygen 1.4.0