DESERT 4.0.0
uwsocket.h
Go to the documentation of this file.
1//
2// Copyright (c) 2018 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
37#ifndef MSOCKET_H
38#define MSOCKET_H
39
40#include <uwconnector.h>
41
42#include <arpa/inet.h>
43#include <netdb.h>
44#include <netinet/in.h>
45#include <string>
46#include <sys/socket.h>
47
48#include <iostream>
49
50constexpr char udp_init_string[] = "a";
51
58class UwSocket : public UwConnector
59{
60
61public:
66 enum class Transport { TCP = 0, UDP };
70 UwSocket();
71
75 virtual ~UwSocket();
76
89 virtual bool openConnection(const std::string &path);
90
95 virtual bool closeConnection();
96
102 virtual const bool isConnected();
103
108 virtual int writeToDevice(const std::string &msg);
109
116 virtual int readFromDevice(void *wpos, int maxlen);
117
121 virtual void
123 {
125 };
129 virtual void
131 {
133 std::cout << "UDP set" << std::endl;
134 };
138 virtual void
140 {
141 isClient = false;
142 };
143
144private:
158
162 struct sockaddr_in cl_addr;
163};
164
165#endif
Definition uwconnector.h:52
Definition uwsocket.h:59
bool isClient
Definition uwsocket.h:157
UwSocket()
Definition uwsocket.cpp:40
virtual int writeToDevice(const std::string &msg)
Definition uwsocket.cpp:302
virtual bool openConnection(const std::string &path)
Definition uwsocket.cpp:60
int socketfd
Definition uwsocket.h:149
Transport
Definition uwsocket.h:66
virtual void setTCP()
Definition uwsocket.h:122
virtual void setServer()
Definition uwsocket.h:139
virtual const bool isConnected()
Definition uwsocket.cpp:54
Transport proto
Definition uwsocket.h:153
virtual int readFromDevice(void *wpos, int maxlen)
Definition uwsocket.cpp:336
virtual void setUDP()
Definition uwsocket.h:130
virtual ~UwSocket()
Definition uwsocket.cpp:49
virtual bool closeConnection()
Definition uwsocket.cpp:289
struct sockaddr_in cl_addr
Definition uwsocket.h:162
Generic class that provides a method to interface with the devices. Will be specialized for,...
constexpr char udp_init_string[]
Definition uwsocket.h:50