Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phNodeComm.h

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004 
00005     Copyright (C) 2003 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008 
00009     This file is part of Phission.
00010 
00011     Phission is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     Phission is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU General Public License for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with Phission; if not, write to the Free Software
00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 
00025  ---------------------------------------------------------------------------*/
00026 /* -------------------------------------------------------------------------- *
00027  * phNodeComm.h: Class responsible for connecting to another Node
00028  * Controller or accepting a connection from another Node Controller
00029  * to ease in establishing the Node Controller Distributed Network.
00030  * --------------------------------------------------------------------------*/
00031 #ifndef PHSERVERTHREAD_H
00032 #define PHSERVERTHREAD_H
00033 
00034 #include <phission.h>
00035 #include <phLamportSystem.h>
00036 
00037 /* -------------------------------------------------------------------------- */
00038 class phNodeComm : public phThread
00039 {
00040 private:
00041     /* --------------------------------------------------------- */
00042     /* 1.) Connection Setup variables */
00043     
00044     /* m_port:
00045      *      - This is the port to set in the phServerSocket 
00046      *      class for listening for client connection requests.
00047      *      - This is also the port set to connect to for a
00048      *      thread that is designated as a client. 
00049      */
00050     int m_port;
00051 
00052     /* m_type:
00053      *      - This specifies whether this is a Connector thread
00054      *      or whether this is a Waiter thread.
00055      *      - The Waiter is a server.
00056      *      - The Connector is a client.
00057      */
00058     #define phNodeController_Waiter  1
00059     #define phNodeController_Connector 2
00060     int m_type;
00061    
00062     /* m_host:
00063      *      - This stores the current host tag for the server.
00064      *      - This stores the host to be connected to for the 
00065      *      client
00066      */
00067     char    *m_host;
00068     int     m_host_size;
00069 
00070     /* m_id: */
00071     int m_id;
00072     /* m_other_side_id: */
00073     int m_other_side_id;
00074     
00075     /* --------------------------------------------------------- */
00076     /* 2.) Comm variables */
00077     
00078     /* m_server:
00079      *      - The server object that implements the server
00080      *      listening to allow the client Node Controllers
00081      *      to connect and establish a connection according to
00082      *      the startup-comm algorithm 
00083     */
00084     phServerSocket *m_server;
00085     
00086     /* m_node_sock:
00087      *      - This is the connection that has been established
00088      *      between the node controllers 
00089      */
00090     phSocket *m_node_sock;
00091     
00092     /* m_buffer: 
00093      *      - This is used for incoming data. 
00094      */
00095     uint8_t *m_buffer;
00096     
00097     /* m_buffer_size: 
00098      *      - This stores the size used when allocating the 
00099      *      buffer 
00100      */
00101     int     m_buffer_size;
00102 
00103  
00104     int     m_connected;
00105    
00106     phLamportSystem *m_system;
00107     
00108     /* 3.) Connection methods */
00109     int Waiter();
00110     int Connector();
00111     int comm_loop();
00112     
00113 public:
00114     phNodeComm(int id                   = -1,
00115                int other_id             = -1, 
00116                int port                 = 0, 
00117                char *host               = NULL,
00118                int type                 = -1,
00119                phLamportSystem *system  = NULL );
00120     virtual ~phNodeComm();
00121 
00122     /* member variable access methods */
00123     int setPort(int port = 0);
00124     int getPort();
00125     
00126     int setConnectionType(int type = phNodeController_Connector);
00127     int getConnectionType();
00128     
00129     int setHost(char *host);
00130     char *getHost();
00131 
00132     int setId(int id);
00133     int getId();
00134     
00135     int setOtherSideId(int other_side_id);
00136     int getOtherSideId();
00137     
00138     int setConnected(int connected);
00139     int isConnected();
00140     
00141     int setSystem( phLamportSystem *system );
00142     phLamportSystem *getSystem();
00143    
00144     phSocket *getSocket();
00145     
00146     /* run: where the server object is used to listen for requests and
00147      * spawn phClientHandlers to handle those requests */
00148     virtual int run();
00149     /* wakeup: tries to get the waiting server accepts to return and
00150      * also sets variables so that the thread can wakeup and finish */
00151     virtual int wakeup();
00152     /* cleanup: delete, reset any variables to allow reuse of this object */
00153     virtual int cleanup();
00154     /* error: this doesn't do much, it's here if anything needs to be
00155      * done if the thread has an error condition starting up */
00156     virtual int error();
00157 };
00158 
00159 
00160 #endif /* PHSERVERTHREAD_H */




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:05 2007 for phission by  doxygen 1.4.4