3 #include <Poco/AtomicCounter.h> 
    4 #include <Poco/AutoPtr.h> 
    5 #include <Poco/Event.h> 
    6 #include <Poco/Mutex.h> 
    7 #include <Poco/Net/WebSocket.h> 
    8 #include <Poco/SharedPtr.h> 
    9 #include <Poco/Thread.h> 
   10 #include <Poco/Timespan.h> 
   11 #include <Poco/Timestamp.h> 
   12 #include <Poco/Util/Timer.h> 
   14 #include "commands/NewDeviceCommand.h" 
   15 #include "commands/ServerDeviceListCommand.h" 
   16 #include "commands/ServerLastValueCommand.h" 
   17 #include "core/CommandHandler.h" 
   18 #include "core/CommandSender.h" 
   19 #include "core/Exporter.h" 
   20 #include "core/GatewayInfo.h" 
   21 #include "gwmessage/GWAck.h" 
   22 #include "gwmessage/GWDeviceAcceptRequest.h" 
   23 #include "gwmessage/GWListenRequest.h" 
   24 #include "gwmessage/GWMessage.h" 
   25 #include "gwmessage/GWMessage.h" 
   26 #include "gwmessage/GWRequest.h" 
   27 #include "gwmessage/GWResponse.h" 
   28 #include "gwmessage/GWSensorDataConfirm.h" 
   29 #include "gwmessage/GWSetValueRequest.h" 
   30 #include "gwmessage/GWUnpairRequest.h" 
   31 #include "loop/StoppableLoop.h" 
   32 #include "server/GWMessageContext.h" 
   33 #include "server/GWSOutputQueue.h" 
   34 #include "server/GWContextPoll.h" 
   35 #include "ssl/SSLClient.h" 
   36 #include "util/Loggable.h" 
   56         typedef Poco::SharedPtr<GWServerConnector> Ptr;
 
   60         void start() 
override;
 
   63         void setHost(
const std::string &host);
 
   64         void setPort(
int port);
 
   65         void setPollTimeout(
const Poco::Timespan &timeout);
 
   66         void setReceiveTimeout(
const Poco::Timespan &timeout);
 
   67         void setSendTimeout(
const Poco::Timespan &timeout);
 
   68         void setRetryConnectTimeout(
const Poco::Timespan &timeout);
 
   69         void setBusySleep(
const Poco::Timespan &timeout);
 
   70         void setResendTimeout(
const Poco::Timespan &timeout);
 
   71         void setMaxMessageSize(
int size);
 
   72         void setGatewayInfo(Poco::SharedPtr<GatewayInfo> info);
 
   73         void setSSLConfig(Poco::SharedPtr<SSLClient> config);
 
   74         void setInactiveMultiplier(
int multiplier);
 
   76         bool accept(
const Command::Ptr cmd) 
override;
 
   77         void handle(Command::Ptr cmd, Answer::Ptr answer) 
override;
 
  109         bool connectUnlocked();
 
  114         bool registerUnlocked();
 
  119         void connectAndRegisterUnlocked();
 
  124         void disconnectUnlocked();
 
  135         void markDisconnected();
 
  146         void forwardContext(GWMessageContext::Ptr context);
 
  151         void forwardOutputQueue();
 
  152         void sendMessage(
const GWMessage::Ptr message);
 
  153         void sendMessageUnlocked(
const GWMessage::Ptr message);
 
  155         void doNewDeviceCommand(NewDeviceCommand::Ptr cmd, Answer::Ptr answer);
 
  156         void doDeviceListCommand(ServerDeviceListCommand::Ptr cmd, Answer::Ptr answer);
 
  157         void doLastValueCommand(ServerLastValueCommand::Ptr cmd, Answer::Ptr answer);
 
  159         void dispatchServerCommand(Command::Ptr cmd, 
const GlobalID &
id, GWResponse::Ptr response);
 
  165         void handleRequest(GWRequest::Ptr request);
 
  167         void handleDeviceAcceptRequest(GWDeviceAcceptRequest::Ptr request);
 
  168         void handleListenRequest(GWListenRequest::Ptr request);
 
  169         void handleSetValueRequest(GWSetValueRequest::Ptr request);
 
  170         void handleUnpairRequest(GWUnpairRequest::Ptr request);
 
  176         void handleResponse(GWResponse::Ptr response);
 
  182         void handleAck(GWAck::Ptr ack);
 
  188         void handleSensorDataConfirm(GWSensorDataConfirm::Ptr confirm);
 
  194         void handleMessage(GWMessage::Ptr msg);
 
  196         void enqueueFinishedAnswers();
 
  203         bool connectionSeemsBroken();
 
  204         void updateLastReceived();
 
  206         GWMessage::Ptr receiveMessageUnlocked();
 
  208         Poco::Event &readyToSendEvent();
 
  213         Poco::Timespan m_pollTimeout;
 
  214         Poco::Timespan m_receiveTimeout;
 
  215         Poco::Timespan m_sendTimeout;
 
  216         Poco::Timespan m_retryConnectTimeout;
 
  217         Poco::Timespan m_busySleep;
 
  218         Poco::Timespan m_resendTimeout;
 
  219         size_t m_maxMessageSize;
 
  220         Poco::SharedPtr<GatewayInfo> m_gatewayInfo;
 
  221         Poco::SharedPtr<SSLClient> m_sslConfig;
 
  222         Poco::Timestamp m_lastReceived;
 
  223         Poco::FastMutex m_lastReceivedMutex;
 
  224         int m_inactiveMultiplier;
 
  226         Poco::FastMutex m_dispatchLock;
 
  228         Poco::Buffer<char> m_receiveBuffer;
 
  229         Poco::SharedPtr<Poco::Net::WebSocket> m_socket;
 
  230         Poco::FastMutex m_receiveMutex;
 
  231         Poco::FastMutex m_sendMutex;
 
  232         Poco::Thread m_senderThread;
 
  233         Poco::Thread m_receiverThread;
 
  235         Poco::AtomicCounter m_isConnected;
 
  236         Poco::Event m_connectedEvent;
 
  238         Poco::AtomicCounter m_stop;
 
  239         Poco::Event m_stopEvent;
 
  243         Poco::Util::Timer m_timer;
 
void start() override
Definition: GWServerConnector.cpp:67
The GWServerConnector allows the BeeeOn Gateway to communicate with the BeeeOn Server using WebSocket...
Definition: GWServerConnector.h:49
GWContextPoll stores contexts of sent messages. This is used for messages that expects the answer...
Definition: GWContextPoll.h:17
Definition: SensorData.h:20
Definition: GlobalID.h:10
Definition: StoppableLoop.h:17
Definition: CommandHandler.h:18
Definition: Exporter.h:11
Queue for all outgoing messages. Must be initialized with Poco::Event reference, which is notified on...
Definition: GWSOutputQueue.h:18
void stop() override
Definition: GWServerConnector.cpp:77
Definition: CommandSender.h:20
Definition: Loggable.h:19
bool ship(const SensorData &data) override
Definition: GWServerConnector.cpp:522