Skip to content

Commit

Permalink
Start work on cross gateway communication (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
manup committed Sep 11, 2016
1 parent bae38ec commit fd62c1a
Show file tree
Hide file tree
Showing 8 changed files with 752 additions and 17 deletions.
37 changes: 21 additions & 16 deletions de_web.pro
Original file line number Diff line number Diff line change
Expand Up @@ -73,55 +73,60 @@ else {
QMAKE_CXXFLAGS += -Wno-attributes

HEADERS = bindings.h \
de_web_plugin.h \
de_web_widget.h \
connectivity.h \
json.h \
colorspace.h \
sqlite3.h \
de_web_plugin.h \
de_web_plugin_private.h \
rest_node_base.h \
light_node.h \
de_web_widget.h \
gateway.h \
gateway_scanner.h \
group.h \
group_info.h \
json.h \
light_node.h \
sqlite3.h \
rest_node_base.h \
rule.h \
scene.h \
sensor.h

SOURCES = authentification.cpp \
atmel_wsndemo_sensor.cpp \
bindings.cpp \
change_channel.cpp \
connectivity.cpp \
colorspace.cpp \
database.cpp \
discovery.cpp \
de_web_plugin.cpp \
de_web_widget.cpp \
de_otau.cpp \
firmware_update.cpp \
gateway.cpp \
gateway_scanner.cpp \
group.cpp \
group_info.cpp \
gw_uuid.cpp \
json.cpp \
colorspace.cpp \
light_node.cpp \
sqlite3.c \
rest_lights.cpp \
rest_configuration.cpp \
rest_gateways.cpp \
rest_groups.cpp \
rest_lights.cpp \
rest_node_base.cpp \
rest_rules.cpp \
rest_sensors.cpp \
rest_schedules.cpp \
rest_touchlink.cpp \
rule.cpp \
upnp.cpp \
zcl_tasks.cpp \
gw_uuid.cpp \
permitJoin.cpp \
rest_node_base.cpp \
light_node.cpp \
group.cpp \
group_info.cpp \
scene.cpp \
sensor.cpp \
atmel_wsndemo_sensor.cpp \
reset_device.cpp \
rest_userparameter.cpp
rest_userparameter.cpp \
zcl_tasks.cpp

win32:DESTDIR = ../../debug/plugins # TODO adjust
unix:DESTDIR = ..
Expand Down
16 changes: 15 additions & 1 deletion de_web_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "de_web_plugin.h"
#include "de_web_plugin_private.h"
#include "de_web_widget.h"
#include "gateway_scanner.h"
#include "json.h"

const char *HttpStatusOk = "200 OK"; // OK
Expand Down Expand Up @@ -89,6 +90,12 @@ DeRestPluginPrivate::DeRestPluginPrivate(QObject *parent) :
connect(databaseTimer, SIGNAL(timeout()),
this, SLOT(saveDatabaseTimerFired()));


gwScanner = new GatewayScanner(this);
connect(gwScanner, SIGNAL(foundGateway(quint32,quint16,QString,QString)),
this, SLOT(foundGateway(quint32,quint16,QString,QString)));
gwScanner->startScan();

db = 0;
saveDatabaseItems = 0;
sqliteDatabaseName = deCONZ::getStorageLocation(deCONZ::ApplicationsDataLocation) + QLatin1String("/zll.db");
Expand Down Expand Up @@ -6913,6 +6920,7 @@ bool DeRestPlugin::isHttpTarget(const QHttpRequestHeader &hdr)
(ls[2] == QLatin1String("touchlink")) ||
(ls[2] == QLatin1String("rules")) ||
(ls[2] == QLatin1String("userparameter")) ||
(ls[2] == QLatin1String("gateways")) ||
(hdr.path().at(4) != '/') /* Bug in some clients */)
{
return true;
Expand Down Expand Up @@ -7010,8 +7018,10 @@ int DeRestPlugin::handleHttpRequest(const QHttpRequestHeader &hdr, QTcpSocket *s
stream << "Access-Control-Allow-Credentials: true\r\n";
stream << "Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE\r\n";
stream << "Access-Control-Allow-Headers: Content-Type\r\n";
stream << "Content-type: text/html\r\n";
stream << "Content-Type: text/html\r\n";
stream << "Content-Length: 0\r\n";
stream << "Gateway-Name: " << d->gwName << "\r\n";
stream << "Gateway-Uuid: " << d->gwUuid << "\r\n";
stream << "\r\n";
req.sock->flush();
return 0;
Expand Down Expand Up @@ -7083,6 +7093,10 @@ int DeRestPlugin::handleHttpRequest(const QHttpRequestHeader &hdr, QTcpSocket *s
{
ret = d->handleUserparameterApi(req, rsp);
}
else if (path[2] == QLatin1String("gateways"))
{
ret = d->handleGatewaysApi(req, rsp);
}
}

if (ret == REQ_NOT_HANDLED)
Expand Down
13 changes: 13 additions & 0 deletions de_web_plugin_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ extern const char *HttpContentJPG;
extern const char *HttpContentSVG;

// Forward declarations
class Gateway;
class GatewayScanner;
class QUdpSocket;
class QTcpSocket;
class DeRestPlugin;
Expand Down Expand Up @@ -497,6 +499,10 @@ class DeRestPluginPrivate : public QObject
bool checkApikeyAuthentification(const ApiRequest &req, ApiResponse &rsp);
QString encryptString(const QString &str);

// REST API gateways
int handleGatewaysApi(const ApiRequest &req, ApiResponse &rsp);
int getGateways(const ApiRequest &req, ApiResponse &rsp);

// REST API configuration
int handleConfigurationApi(const ApiRequest &req, ApiResponse &rsp);
int createUser(const ApiRequest &req, ApiResponse &rsp);
Expand Down Expand Up @@ -732,6 +738,9 @@ public Q_SLOTS:
void checkWifiState();
void restoreWifiState();

// gateways
void foundGateway(quint32 ip, quint16 port, const QString &uuid, const QString &name);

public:
void checkRfConnectState();
bool isInNetwork();
Expand Down Expand Up @@ -868,6 +877,10 @@ public Q_SLOTS:
QTimer *databaseTimer;
QString emptyString;

// gateways
std::vector<Gateway*> gateways;
GatewayScanner *gwScanner;

// authentification
QTime apiAuthSaveDatabaseTime;
std::vector<ApiAuth> apiAuths;
Expand Down
Loading

0 comments on commit fd62c1a

Please sign in to comment.