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  //<tfromm date="22.05.2009">
48  //#include <string>
49  #include <cstring>
50  #include <cstdlib>
51  //</tfromm>
52 //-------------------------------------------------------//
53 #endif //WIN32 else LINUX
54 //-------------------------------------------------------//
55 
56 
57 //--------------------------------------------------------------------------//
65 class DLLDIR CCdlSocket : public CCdlBase {
66 private:
68 
69  char* _ipAddr;
71  int _port;
73  int _len;
74 //-------------------------------------------------------//
75 #ifdef WIN32
76 //-------------------------------------------------------//
77  //Windows specific socket handles:
78  SOCKET _socketfd;
79  SOCKADDR_IN _socketAddr;
80 
81 //-------------------------------------------------------//
82 #else //LINUX
83 //-------------------------------------------------------//
84  //Unix specific socket handles:
86  int _socketfd;
88  struct sockaddr_in _socketAddr;
89 //-------------------------------------------------------//
90 #endif //WIN32 else LINUX
91 //-------------------------------------------------------//
92 
93 protected:
94 
97  static char digit(const int _val) {
98  return (char)((int)'0' + _val);
99  }
100 
101 public:
109  CCdlSocket(char* adress, int port);
110 
113  virtual ~CCdlSocket();
114 
117  virtual int send(const void* _buf, int _size);
118 
121  virtual int recv(void* _buf, int _size);
122 
125  virtual int disconnect();
126 };
127 
128 
129 #endif //_CDLSOCKET_H_
130 
virtual int recv(void *_buf, int _sz)=0
Pure function to receive data.
#define DLLDIR
Definition: dllexport.h:30
virtual int send(const void *_buf, int _sz)=0
Pure function to send data.
int _port
Port number of the KNI communication socket.
Definition: cdlSocket.h:71
int _len
Length of the message.
Definition: cdlSocket.h:73
Encapsulates the socket communication device.
Definition: cdlSocket.h:65
char * _ipAddr
IP Address of the Robot or simulation environment.
Definition: cdlSocket.h:69
static char digit(const int _val)
Converts an integer to a char.
Definition: cdlSocket.h:97
Abstract base class for devices.
Definition: cdlBase.h:47
int _socketfd
File handler for the socket.
Definition: cdlSocket.h:86


kni
Author(s): Martin Günther
autogenerated on Fri Jun 7 2019 22:06:44