Main Page | Namespace List | Alphabetical List | Class List | Directories | File List | Class Members | File Members

TCPSynchronizedClient.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Simulation                                                *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 #ifndef TCPSYNCHRONIZEDCLIENT_H
00024 #define TCPSYNCHRONIZEDCLIENT_H
00025 
00026 #include "PerformanceTimer.h"
00027 
00028 //Other includes
00029 #include <arpa/inet.h>
00030 #include <string>
00031 using namespace std;
00032 
00033 
00034 //-------------------- TCP Synchronized Client ----------------------------
00035 /*! Client that requests data from an external device using TCP
00036         This client blocks until it receives the data. */
00037 
00038 /* FIXME BLOCKING RECEIVE THROWS AN EXCEPTION WHEN OTHER SOCKET IS CLOSED
00039         NEED TO TEST THIS MORE AND SHUT DOWN CLEANLY
00040         FIXME MAKE OPEN SOCKET RUN AS A SEPARATE THREAD TO AVOID BLOCKING. */
00041 //-------------------------------------------------------------------------
00042 
00043 class TCPSynchronizedClient {
00044 
00045         public:
00046                 TCPSynchronizedClient(unsigned int neurGrpWidth, unsigned int neurGrpLength);
00047                 ~TCPSynchronizedClient();
00048                 bool closeDevice();
00049                 bool deviceOpen();
00050                 bool fetchData();
00051                 bool openSocket(string groupAddress, int port);
00052                 void setTwoByteCoords(bool);
00053 
00054 
00055                 //========================== VARIABLES ==============================
00056                 /*! Holds the number of spikes in the spike buffer.*/
00057                 unsigned int spikeCount;
00058 
00059                 /*! Holds the spikes that have been received from the network.*/
00060                 unsigned int* spikeBuffer;
00061         
00062                 /*! Integer used to access the socket.*/
00063                 int socketHandle;
00064 
00065                 /*! Address of the socket.*/
00066                 struct sockaddr_in externalDevAddr;
00067 
00068                 /*! Records whether socket has been successfully connected.*/
00069                 bool socketConnected;
00070 
00071         private:
00072                 //========================== VARIABLES ==============================
00073                 /*! Neuron group width.*/
00074                 unsigned int neuronGrpWidth;
00075 
00076                 /*! Neuron group length.*/
00077                 unsigned int neuronGrpLength;
00078 
00079                 /*! Buffer to unpack message into.*/
00080                 unsigned char *msgBuffer;
00081 
00082                 /*! Records whether the socket has been opened.*/
00083                 bool socketOpen;
00084 
00085                 /*! Array holding the request for data from the device. This is sent
00086                         to the device to request the data. */
00087                 unsigned char requestDataMsgArray[1];
00088 
00089                 /*! Vision coordinates are too big to fit in a single byte. Set this
00090                         to true when it is a vision connection. */
00091                 bool twoByteCoordinates;
00092 
00093 
00094                 //=========================== METHODS ===============================
00095                 /*! Declare copy constructor private so it cannot be used inadvertently.*/
00096                 TCPSynchronizedClient (const TCPSynchronizedClient&);
00097 
00098                 /*! Declare assignment private so it cannot be used.*/
00099                 TCPSynchronizedClient operator = (const TCPSynchronizedClient&);
00100 
00101                 void printMessageBuffer(unsigned char* msgBuf, unsigned int msgBufSize);
00102 
00103 };
00104 
00105 
00106 #endif//TCPSYNCHRONIZEDCLIENT_H
00107 

Generated on Mon Sep 3 22:24:34 2007 for SpikeStream Simulation by  doxygen 1.4.4