Files
pip/libs/main/cloud/picloudtcp.h
2021-04-06 15:24:58 +03:00

81 lines
1.8 KiB
C++

/*! \file picloudtcp.h
* \brief PICloud TCP transport
*/
/*
PIP - Platform Independent Primitives
PICloud TCP transport
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PICLOUDTCP_H
#define PICLOUDTCP_H
#include "pip_cloud_export.h"
#include "pistring.h"
class PIEthernet;
namespace PICloud {
class PIP_CLOUD_EXPORT TCP {
public:
enum Version {
Version_1 = 1,
};
enum Role {
Server = 1,
Client = 2,
};
enum Type {
Invalid = 0,
Connect = 1,
Disconnect = 2,
Data = 3,
};
TCP();
void setRole(Role r);
Role role() const {return (Role)header.role;}
void setServerName(const PIString & server_name);
void sendStart(PIEthernet * eth);
void sendConnected(PIEthernet * eth, uint client_id);
void sendData(PIEthernet * eth, const PIByteArray & data);
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> parseHeader(PIByteArray & ba);
PIByteArray parseData(PIByteArray & ba);
PIString parseConnect(PIByteArray & ba);
private:
struct Header {
Header();
uchar version; // PICloud::Version
uchar type; // PICloud::Type
uchar role; // PICloud::Role
};
Header header;
PIString sname;
};
}
#endif // PICLOUDTCP_H