KatanaNativeInterface  $VERSION$
cdlSocket.h
Go to the documentation of this file.
1 /*
2  * Katana Native Interface - A C++ interface to the robot arm Katana.
3  * Copyright (C) 2005 Neuronics AG
4  * Check out the AUTHORS file for detailed contact information.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 
22 
23 #ifndef _CDLSOCKET_H_
24 #define _CDLSOCKET_H_
25 
26 #include "common/dllexport.h"
27 #include "common/Timer.h"
28 
29 #include "KNI/cdlBase.h"
30 #include "KNI/cdlCOMExceptions.h"
31 
32 //-------------------------------------------------------//
33 #ifdef WIN32
34 //-------------------------------------------------------//
35  #include <windows.h>
36  #include <winsock.h>
37  #include <stdio.h>
38 //-------------------------------------------------------//
39 #else //LINUX
40 //-------------------------------------------------------//
41  #include <sys/types.h>
42  #include <sys/socket.h>
43  #include <netinet/in.h>
44  #include <arpa/inet.h>
45  #include <cerrno>
46  #include <unistd.h>
47  #include <string>
48 //-------------------------------------------------------//
49 #endif //WIN32 else LINUX
50 //-------------------------------------------------------//
51 
52 
53 //--------------------------------------------------------------------------//
61 class DLLDIR CCdlSocket : public CCdlBase {
62 private:
64 
65  char* _ipAddr;
67  int _port;
69  int _len;
70 //-------------------------------------------------------//
71 #ifdef WIN32
72 //-------------------------------------------------------//
73  //Windows specific socket handles:
74  SOCKET _socketfd;
75  SOCKADDR_IN _socketAddr;
76 
77 //-------------------------------------------------------//
78 #else //LINUX
79 //-------------------------------------------------------//
80  //Unix specific socket handles:
82  int _socketfd;
84  struct sockaddr_in _socketAddr;
85 //-------------------------------------------------------//
86 #endif //WIN32 else LINUX
87 //-------------------------------------------------------//
88 
89 protected:
90 
93  static char digit(const int _val) {
94  return (char)((int)'0' + _val);
95  }
96 
97 public:
105  CCdlSocket(char* adress, int port);
106 
109  virtual ~CCdlSocket();
110 
113  virtual int send(const void* _buf, int _size);
114 
117  virtual int recv(void* _buf, int _size);
118 
121  virtual int disconnect();
122 };
123 
124 
125 #endif //_CDLSOCKET_H_
126 
CCdlSocket::digit
static char digit(const int _val)
Converts an integer to a char.
Definition: cdlSocket.h:93
dllexport.h
cdlCOMExceptions.h
cdlBase.h
CCdlSocket::_socketfd
int _socketfd
File handler for the socket.
Definition: cdlSocket.h:82
CCdlSocket::_ipAddr
char * _ipAddr
IP Address of the Robot or simulation environment.
Definition: cdlSocket.h:65
CCdlBase::send
virtual int send(const void *_buf, int _sz)=0
Pure function to send data.
CCdlBase
Abstract base class for devices.
Definition: cdlBase.h:47
Timer.h
CCdlSocket::_port
int _port
Port number of the KNI communication socket.
Definition: cdlSocket.h:67
CCdlSocket::_len
int _len
Length of the message.
Definition: cdlSocket.h:69
CCdlSocket
Encapsulates the socket communication device.
Definition: cdlSocket.h:61
CCdlBase::recv
virtual int recv(void *_buf, int _sz)=0
Pure function to receive data.
DLLDIR
#define DLLDIR
Definition: dllexport.h:30