Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

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

Tekkotsu v1.4
Generated Sat Jul 19 00:06:32 2003 by Doxygen 1.3.2