// system includes #include // project includes #include #include "JsonClientConnection.h" JsonServer::JsonServer(uint16_t port) : QObject() , _server() , _hyperion(Hyperion::getInstance()) , _openConnections() , _log(Logger::getInstance("JSONSERVER")) { if (!_server.listen(QHostAddress::Any, port)) { throw std::runtime_error("JSONSERVER ERROR: could not bind to port"); } QList list = Hyperion::getInstance()->getForwarder()->getJsonSlaves(); for ( int i=0; ilocalAddress().toString().toStdString().c_str()); JsonClientConnection * connection = new JsonClientConnection(socket); _openConnections.insert(connection); // register for JSONClientConnection events connect(connection, SIGNAL(pushReq()), this, SLOT(pushReq())); // register slot for cleaning up after the connection closed connect(connection, SIGNAL(connectionClosed(JsonClientConnection*)), this, SLOT(closedConnection(JsonClientConnection*))); } } void JsonServer::closedConnection(JsonClientConnection *connection) { Debug(_log, "Connection closed"); _openConnections.remove(connection); // schedule to delete the connection object connection->deleteLater(); } void JsonServer::pushReq() { if(_blockTimer.isActive()) { _timer.start(250); } else { foreach (JsonClientConnection * connection, _openConnections) { connection->forceServerInfo(); } _blockTimer.start(250); } }