picloud
This commit is contained in:
@@ -20,12 +20,13 @@
|
|||||||
#include "picloudclient.h"
|
#include "picloudclient.h"
|
||||||
|
|
||||||
|
|
||||||
PICloudClient::PICloudClient() {
|
PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode) : PIIODevice(path, mode), eth(PIEthernet::TCP_Client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PICloudClient::~PICloudClient() {
|
PICloudClient::~PICloudClient() {
|
||||||
|
stop();
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -38,3 +39,11 @@ bool PICloudClient::closeDevice() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PICloudClient::readDevice(void * read_to, int max_size) {
|
||||||
|
return eth.read(read_to, max_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int PICloudClient::writeDevice(const void * data, int max_size) {
|
||||||
|
return eth.write(data, max_size);
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ bool PICloudServer::openDevice() {
|
|||||||
piCout << "PICloudServer open device" << path();
|
piCout << "PICloudServer open device" << path();
|
||||||
bool op = eth.connect(path(), false);
|
bool op = eth.connect(path(), false);
|
||||||
if (op) {
|
if (op) {
|
||||||
// CONNECTL(ð, disconnected, [this](bool){opened_ = false;});
|
CONNECTL(ð, disconnected, [this](bool){opened_ = false;});
|
||||||
|
CONNECTU(ð, threadedReadEvent, this, readed);
|
||||||
|
eth.startThreadedRead();
|
||||||
|
sendStart();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
eth.close();
|
eth.close();
|
||||||
@@ -48,12 +51,27 @@ bool PICloudServer::closeDevice() {
|
|||||||
|
|
||||||
|
|
||||||
int PICloudServer::readDevice(void * read_to, int max_size) {
|
int PICloudServer::readDevice(void * read_to, int max_size) {
|
||||||
return eth.read(read_to, max_size);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int PICloudServer::writeDevice(const void * data, int max_size) {
|
int PICloudServer::writeDevice(const void * data, int max_size) {
|
||||||
return eth.write(data, max_size);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PICloudServer::sendStart() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PICloudServer::Client::Client(PICloudServer * srv) : server(srv) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PICloudServer::Client::openDevice() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ PIByteArray & operator >>(PIByteArray & s, PICloud::Header & v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PICloudTCP::PICloudTCP() {
|
PICloud::TCP::TCP() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,7 @@
|
|||||||
#define PICLOUDCLIENT_H
|
#define PICLOUDCLIENT_H
|
||||||
|
|
||||||
#include "pip_cloud_export.h"
|
#include "pip_cloud_export.h"
|
||||||
#include "piiodevice.h"
|
#include "piethernet.h"
|
||||||
|
|
||||||
class PIEthernet;
|
|
||||||
|
|
||||||
|
|
||||||
class PIP_CLOUD_EXPORT PICloudClient : public PIIODevice
|
class PIP_CLOUD_EXPORT PICloudClient : public PIIODevice
|
||||||
@@ -34,7 +32,7 @@ class PIP_CLOUD_EXPORT PICloudClient : public PIIODevice
|
|||||||
PIIODEVICE(PICloudClient)
|
PIIODEVICE(PICloudClient)
|
||||||
public:
|
public:
|
||||||
//!
|
//!
|
||||||
explicit PICloudClient();
|
explicit PICloudClient(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
virtual ~PICloudClient();
|
virtual ~PICloudClient();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -42,7 +40,10 @@ protected:
|
|||||||
bool closeDevice();
|
bool closeDevice();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PIEthernet * eth;
|
int readDevice(void * read_to, int max_size);
|
||||||
|
int writeDevice(const void * data, int max_size);
|
||||||
|
|
||||||
|
PIEthernet eth;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PICLOUDCLIENT_H
|
#endif // PICLOUDCLIENT_H
|
||||||
|
|||||||
@@ -26,8 +26,6 @@
|
|||||||
#include "pip_cloud_export.h"
|
#include "pip_cloud_export.h"
|
||||||
#include "piethernet.h"
|
#include "piethernet.h"
|
||||||
|
|
||||||
class PIEthernet;
|
|
||||||
|
|
||||||
|
|
||||||
class PIP_CLOUD_EXPORT PICloudServer : public PIIODevice
|
class PIP_CLOUD_EXPORT PICloudServer : public PIIODevice
|
||||||
{
|
{
|
||||||
@@ -37,6 +35,18 @@ public:
|
|||||||
explicit PICloudServer(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
explicit PICloudServer(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||||
virtual ~PICloudServer();
|
virtual ~PICloudServer();
|
||||||
|
|
||||||
|
class Client : public PIIODevice {
|
||||||
|
PIIODEVICE(PICloudServer::Client)
|
||||||
|
public:
|
||||||
|
Client(PICloudServer * srv = nullptr);
|
||||||
|
protected:
|
||||||
|
bool openDevice();
|
||||||
|
private:
|
||||||
|
PICloudServer * server;
|
||||||
|
};
|
||||||
|
|
||||||
|
EVENT1(newConnection, PICloudServer::Client * , client)
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool openDevice();
|
bool openDevice();
|
||||||
bool closeDevice();
|
bool closeDevice();
|
||||||
@@ -44,7 +54,11 @@ protected:
|
|||||||
int writeDevice(const void * data, int max_size);
|
int writeDevice(const void * data, int max_size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
EVENT_HANDLER2(void, readed, uchar * , data, int, size);
|
||||||
|
void sendStart();
|
||||||
|
|
||||||
PIEthernet eth;
|
PIEthernet eth;
|
||||||
|
PIVector<Client> clients;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "pip_cloud_export.h"
|
#include "pip_cloud_export.h"
|
||||||
#include "pistring.h"
|
#include "pistring.h"
|
||||||
|
|
||||||
|
|
||||||
namespace PICloud {
|
namespace PICloud {
|
||||||
|
|
||||||
enum Version {
|
enum Version {
|
||||||
@@ -45,20 +46,19 @@ struct PIP_CLOUD_EXPORT Header {
|
|||||||
uchar type; // PICloud::HeaderType
|
uchar type; // PICloud::HeaderType
|
||||||
PIString sname; // server name
|
PIString sname; // server name
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
PIP_CLOUD_EXPORT PIByteArray & operator <<(PIByteArray & s, const PICloud::Header & v);
|
|
||||||
PIP_CLOUD_EXPORT PIByteArray & operator >>(PIByteArray & s, PICloud::Header & v);
|
|
||||||
|
|
||||||
|
|
||||||
class PIP_CLOUD_EXPORT PICloudTCP {
|
class PIP_CLOUD_EXPORT TCP {
|
||||||
public:
|
public:
|
||||||
//!
|
TCP();
|
||||||
PICloudTCP();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PIP_CLOUD_EXPORT PIByteArray & operator <<(PIByteArray & s, const PICloud::Header & v);
|
||||||
|
PIP_CLOUD_EXPORT PIByteArray & operator >>(PIByteArray & s, PICloud::Header & v);
|
||||||
|
|
||||||
#endif // PICLOUDTCP_H
|
#endif // PICLOUDTCP_H
|
||||||
|
|||||||
Reference in New Issue
Block a user