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