KatanaNativeInterface  $VERSION$
cdlSocket.h
Go to the documentation of this file.
00001 /*
00002  *   Katana Native Interface - A C++ interface to the robot arm Katana.
00003  *   Copyright (C) 2005 Neuronics AG
00004  *   Check out the AUTHORS file for detailed contact information.
00005  *
00006  *   This program is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with this program; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 
00022 
00023 #ifndef _CDLSOCKET_H_
00024 #define _CDLSOCKET_H_
00025 
00026 #include "common/dllexport.h"
00027 #include "common/Timer.h"
00028 
00029 #include "KNI/cdlBase.h"
00030 #include "KNI/cdlCOMExceptions.h"
00031 
00032 //-------------------------------------------------------//
00033 #ifdef WIN32
00034 //-------------------------------------------------------//
00035         #include <windows.h>
00036         #include <winsock.h>
00037         #include <stdio.h>
00038 //-------------------------------------------------------//
00039 #else //LINUX
00040 //-------------------------------------------------------//
00041         #include <sys/types.h>
00042         #include <sys/socket.h>
00043         #include <netinet/in.h>
00044         #include <arpa/inet.h>
00045         #include <cerrno>
00046         #include <unistd.h>
00047         #include <string>
00048 //-------------------------------------------------------//
00049 #endif //WIN32 else LINUX
00050 //-------------------------------------------------------//
00051 
00052 
00053 //--------------------------------------------------------------------------//
00061 class DLLDIR CCdlSocket : public CCdlBase {
00062 private:
00064 
00065         char* _ipAddr;
00067         int _port;
00069         int _len;
00070 //-------------------------------------------------------//
00071 #ifdef WIN32
00072 //-------------------------------------------------------//
00073         //Windows specific socket handles:
00074         SOCKET _socketfd;
00075         SOCKADDR_IN _socketAddr;
00076 
00077 //-------------------------------------------------------//
00078 #else //LINUX
00079 //-------------------------------------------------------//
00080         //Unix specific socket handles:
00082         int _socketfd;
00084         struct sockaddr_in _socketAddr;
00085 //-------------------------------------------------------//
00086 #endif //WIN32 else LINUX
00087 //-------------------------------------------------------//
00088 
00089 protected:
00090 
00093         static char digit(const int _val) {
00094                 return (char)((int)'0' + _val);
00095         }
00096 
00097 public:
00105         CCdlSocket(char* adress, int port);
00106 
00109         virtual ~CCdlSocket();
00110 
00113         virtual int  send(const void* _buf, int _size);
00114 
00117         virtual int  recv(void* _buf, int _size);
00118 
00121         virtual int  disconnect();
00122 };
00123 
00124 
00125 #endif //_CDLSOCKET_H_
00126