DESERT 3.5.1
Loading...
Searching...
No Matches
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
Class UwConnector allows to specify an interface between the UwDriver object and the device.
Definition uwconnector.h:52
Class that implements a TCP or UDP socket.
Definition uwsocket.h:59
bool isClient
Bool value that defines the role of the socket.
Definition uwsocket.h:157
UwSocket()
Constructor of the UwSocket class.
Definition uwsocket.cpp:40
virtual int writeToDevice(const std::string &msg)
Method that writes a command to the modem interface.
Definition uwsocket.cpp:286
virtual bool openConnection(const std::string &path)
Method that opens a TCP or UDP connection, accordinto to UwSocket::proto variable: the behavior depen...
Definition uwsocket.cpp:60
int socketfd
Integer value that stores the socket descriptor as generated by the function UwSocket::openConnection...
Definition uwsocket.h:149
Transport
Enum structure thet represents the transport protocol being used.
Definition uwsocket.h:66
virtual void setTCP()
Method that sets TCP as transport protocol.
Definition uwsocket.h:122
virtual void setServer()
Method that sets SERVER role.
Definition uwsocket.h:139
virtual const bool isConnected()
Returns true if socket fd differs from -1, that means the connection is up.
Definition uwsocket.cpp:54
Transport proto
Transport protocol to be used: either Transport::TCP or Transport::UDP.
Definition uwsocket.h:153
virtual int readFromDevice(void *wpos, int maxlen)
Function that dumps data from the device's memory to a backup buffer.
Definition uwsocket.cpp:317
virtual void setUDP()
Method that sets UDP as transport protocol.
Definition uwsocket.h:130
virtual ~UwSocket()
Destructor of the UwSocket class.
Definition uwsocket.cpp:49
virtual bool closeConnection()
Method that closes an active connection to a device.
Definition uwsocket.cpp:273
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