Ejemplo n.º 1
0
void XYTCPSocketLayer::Disconnect(XYNetworkErrorCode code)
{
	if(_stat == States_Connected)
	{
		_stat = States_Disconnected;
		_IsReadThreadRunning = false;
	}
	else if(_stat == States_Connecting)
	{
		pthread_mutex_lock(&_mutex);

		_stat = States_Disconnected;
		_IsReadThreadRunning = false;

		pthread_mutex_unlock(&_mutex);
	}

    XYThreadManager::ShareIntance()->Stop();
    
	if(shutdown(_fd, SHUT_WR) != 0)
	{
		//dispatch shutdown error
        onError(XYNetworkErrorCode(XYNetworkErrorCode::eXYNetworkErrorCode::SHOWDOWN_ERROR));
	}
    
    onDisconnect(code);
}
Ejemplo n.º 2
0
 void
 BasicDeviceDriver::disconnect(void)
 {
   debug("disconnecting");
   onDisconnect();
   debug("disconnected");
 }
Ejemplo n.º 3
0
void MasterServer::onNewConnection()
{
    socket = server->nextPendingConnection();
    print ("New incoming connection - " + socket->peerAddress().toString());
    connect(socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(socket, SIGNAL(disconnected()), this, SLOT(onDisconnect()));
}
Ejemplo n.º 4
0
void ChunckReceiver::run()
{
    if(mCollector == nullptr){
        return;
    }

	mEventLoop = QEventLoopPtr(new QEventLoop());
	mSocket = QTcpSocketPtr(new QTcpSocket());
    connect(mSocket.get(),
            SIGNAL(disconnected()),
            this,
            SLOT(onDisconnect()),Qt::DirectConnection);

    connect(mSocket.get(),
            SIGNAL(readyRead()),
            this,
            SLOT(onReadyRead()), Qt::DirectConnection);

    if(!mSocket->setSocketDescriptor(mSocketDescriptor)){
            emit error(mSocket->error());
    }

    mEventLoop->exec();

    emit finished();
}
void ARTSPConnection::onMessageReceived(const sp<AMessage> &msg) {
    switch (msg->what()) {
        case kWhatConnect:
            onConnect(msg);
            break;

        case kWhatDisconnect:
            onDisconnect(msg);
            break;

        case kWhatCompleteConnection:
            onCompleteConnection(msg);
            break;

        case kWhatSendRequest:
            onSendRequest(msg);
            break;

        case kWhatReceiveResponse:
            onReceiveResponse();
            break;

        case kWhatObserveBinaryData:
        {
            CHECK(msg->findMessage("reply", &mObserveBinaryMessage));
            break;
        }

        default:
            TRESPASS();
            break;
    }
}
void WebSocket::listen() {
	EthernetClient cli;
    if (cli = server.available()) {
        if (cli == true) {
            if (state == DISCONNECTED ) {
				client = cli;
                if (doHandshake() == true) {
                    state = CONNECTED;
                    if (onConnect) {
                        onConnect(*this);
                    }
                }
            } else {
                if (getFrame() == false) {
                    // Got unhandled frame, disconnect
	            	#ifdef DEBUG
	                	Serial.println("Disconnecting");
	            	#endif
                    disconnectStream();
                    state = DISCONNECTED;
                    if (onDisconnect) {
                        onDisconnect(*this);
                    }
                }
            }
        }
    }
}
Ejemplo n.º 7
0
void BooRedisAsync::onError(const boost::system::error_code &error)
{
    if (error == boost::asio::error::operation_aborted)
        return;

    if (error!=boost::system::error_code()) //If not decode error
        onLogMessage("Connection to Redis " + endpointToString(m_endpointIterator) + " failed: "
                     + error.message(),LOG_LEVEL_ERR);

    m_writeInProgress = false;
    m_connected = false;
    m_connectTimer->cancel();

    try {
        closeSocket(); //close socket and cleanup
    } catch (...) {}

    m_decoder.reset();

    onDisconnect();

    boost::asio::ip::tcp::resolver::iterator it = getEndpointIterator();
    if (!onceConnected() && !isLastEndpoint(it)) { //try another address
        setEndpointIterator(++it); //switch to the next endpoint
        onLogMessage("Trying next Redis address: " + endpointToString(it),LOG_LEVEL_DEBUG);
    } else
        sleep(1);

    onLogMessage("Reconnecting to Redis " + endpointToString(it),LOG_LEVEL_INFO);

    connect(it);
}
Ejemplo n.º 8
0
		void ONIKinectDevice::onDeviceDisconnected(const DeviceInfo* pInfo)
		{
			onDisconnect();
			std::ostringstream out; 
			out << "Device \"" << pInfo->getUri() << "\" disconnected\n";
			onMessage(out.str());
		}
Ejemplo n.º 9
0
void IRC::input() {
    string line_buffer = "";
    char buffer[RCVBUFSIZE + 1];
    while(true) {
        int bytesReceived = 0;

        //this thread is used for Socket IO
        if((bytesReceived = (socket->read(buffer, RCVBUFSIZE))) <= 0) {
            //We have been disconnected
            break;
        }

        buffer[bytesReceived] = '\0';
        line_buffer += buffer;

        //if the line buffer has a new line, flush it to read
        size_t line = line_buffer.find("\n");
        if(line != string::npos) {
            input_buffer.push(line_buffer.substr(0, line));
            line_buffer = line_buffer.substr(line + 1);
        }

        mpSleep(SLEEP_TIME);
    }

    onDisconnect();
}
Ejemplo n.º 10
0
SyntroZigbeeGateway::SyntroZigbeeGateway(QSettings *settings, QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags), m_settings(settings)
{
	ui.setupUi(this);
	initStatusBar();
	initStatTable();

	loadNodeIDList();

	connect(ui.actionExit, SIGNAL(triggered()), this, SLOT(close()));
	connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT(onAbout()));
	connect(ui.actionConnect, SIGNAL(triggered()), this, SLOT(onConnect()));
	connect(ui.actionDisconnect, SIGNAL(triggered()), this, SLOT(onDisconnect()));
	connect(ui.actionConfigure, SIGNAL(triggered()), this, SLOT(onConfigure()));

	ui.actionDisconnect->setEnabled(false);

	m_controller = NULL;
	m_refreshTimer = 0;

	m_client = new ZigbeeGWClient(this, settings);
	m_client->resumeThread();

	m_syntroStatusTimer = startTimer(3000);

	restoreWindowState();
}
Ejemplo n.º 11
0
unsigned short ZmqSocket::disconnect(const char* endpoint)
{
	CHECK_RET_CODE(sock != 0, ERR_CLOSE);
	CHECK_API_RET(zmq_disconnect(sock, endpoint) != -1);
	onDisconnect();
	return NO_ERR;
}
Ejemplo n.º 12
0
 TcpClient::~TcpClient()
 {
     m_socket->disconnect(m_socket, SIGNAL(disconnected()), this, SLOT(onDisconnect()));
     m_socket->disconnect(m_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
     m_socket->close();
     m_socket = nullptr;
 }
Ejemplo n.º 13
0
void AndroidBluetooth::listen() {
    if(available()){//check if there's any data sent from the remote bluetooth shield
        recvChar = read();
        //      Serial.print(recvChar);
        if(message.length() < MESSAGE_LENGTH) {
            message.concat(recvChar);
        }
    } else if(message.length() > 0){
            if(message.indexOf("+BTSTATE:1") >= 0) {
                state = DISCONNECTED;
                if(onDisconnect) onDisconnect();
            } else if(message.indexOf("+BTSTATE:4") >= 0) {
                state = CONNECTED;
                if(onConnect) onConnect();
                String temp = "blpins:D";
                temp.concat(rxPin);
                temp.concat("&D");
                temp.concat(txPin);
                send(temp);
                temp = "";
            } else if(message.indexOf("+BTSTATE:3") >= 0) {
            
            } else if(message.indexOf("CONNECT:OK") >= 0) {
                
            } else if(message.indexOf("ERROR") >= 0) {
                
            } else if(message.indexOf("pRQST") >= 0) {
                //Get Type Analog vs Digital
                (message.charAt(5) == 'A') ? type = 1 : type = 0;
                //Get state HIGH vs LOW
                if(message.indexOf("false") >= 0) isHigh = 0;
                else isHigh = 1;
                //Get Pin Number
                char *buffer = {"h"};
                message.substring(6,8).toCharArray(buffer, 3);
                pin = atoi(buffer);
                //Send data to callback
                if(onPin) onPin(type, pin, isHigh);
                if(type == 0) {
                    Serial.print("Requested:");
                    Serial.print("Digital Pin ");
                    Serial.print(pin);
                    Serial.print(" to ");
                    if(isHigh) Serial.println("HIGH");
                    else Serial.println("LOW");
                }
                else {
                    send((String)analogRead(pin));
                    Serial.print("Analog Pin ");
                    Serial.print(pin);
                    Serial.print(" Read ");
                    Serial.println(analogRead(pin));
                }
                buffer = NULL;
            }
            else if (onData) onData(message);
            message = "";
    }
}
Ejemplo n.º 14
0
void TelemetryManager::onStart()
{
    utalk = new UAVTalk(device, objMngr);
    telemetry = new Telemetry(utalk, objMngr);
    telemetryMon = new TelemetryMonitor(objMngr, telemetry);
    connect(telemetryMon, SIGNAL(connected()), this, SLOT(onConnect()));
    connect(telemetryMon, SIGNAL(disconnected()), this, SLOT(onDisconnect()));
}
void CustomServerNetworkHandler::disconnectClient(ServerNetworkHandler *real, const RakNet::RakNetGUID &guid, const std::string &message)
{
	DisconnectPacket pk;
	pk.message = message;
	real->sender->send(guid, pk);

	onDisconnect(real, guid, message);
}
Ejemplo n.º 16
0
unsigned short ZmqSocket::close()
{
	CHECK_RET_CODE(sock != 0, ERR_CLOSE);
	CHECK_API_RET(zmq_close(sock) == 0);
	onDisconnect();
	sock = 0;
	return NO_ERR;
}
Ejemplo n.º 17
0
void SocketComm::connectToServer(QString host, qint16 port){
    socket = new QTcpSocket();

    socket->connectToHost(host,port);
    socket->waitForConnected(2000);
    connect(socket,SIGNAL(connected()),this,SLOT(onConnect()),Qt::DirectConnection);
    connect(socket,SIGNAL(disconnected()),this,SLOT(onDisconnect()),Qt::DirectConnection);

}
Ejemplo n.º 18
0
void kul::https::Server::loop() throw(kul::tcp::Exception){
    KUL_DBG_FUNC_ENTER
    int32_t newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
    if(newsockfd < 0) KEXCEPTION("HTTPS Server error on accept");

    ssl = SSL_new(ctx);
    SSL_set_fd(ssl, newsockfd);
    //Here is the SSL Accept portion.  Now all reads and writes must use SSL
    int16_t ssl_err = SSL_accept(ssl);
    if(ssl_err <= 0){
        short se = 0;
        SSL_get_error(ssl, se);
        KERR << "HTTPS Server SSL ERROR on SSL_ACCEPT error: " << se;
        close(newsockfd);
        return;
    }

    KLOG(DBG) << "SSL_get_cipher: " << SSL_get_cipher(ssl);
    cc = SSL_get_peer_certificate (ssl);

    if(cc != NULL) {
        KLOG(DBG) << "Client certificate:";
        KLOG(DBG) << "\t subject: " << X509_NAME_oneline (X509_get_subject_name (cc), 0, 0);
        KLOG(DBG) << "\t issuer: %s\n" << X509_NAME_oneline (X509_get_issuer_name  (cc), 0, 0);
        X509_free(cc);
    }else KLOG(ERR) << "Client does not have certificate.";

    KOUT(DBG) << "New connection , socket fd is " << newsockfd << ", is : " << inet_ntoa(cli_addr.sin_addr) << ", port : "<< ntohs(cli_addr.sin_port);
    onConnect(inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port));
    int16_t e;
    char buffer[_KUL_HTTPS_READ_BUFFER_];
    std::stringstream cnt;
    do{
        bzero(buffer,_KUL_HTTPS_READ_BUFFER_);
        e = SSL_read(ssl, buffer, _KUL_HTTPS_READ_BUFFER_ - 1);
        if(e) cnt << buffer;
    }while(e == (_KUL_HTTPS_READ_BUFFER_ - 1));
    if (e < 0){ 
        short se = 0;
        SSL_get_error(ssl, se);
        if(se) KLOG(ERR) << "SSL_get_error: " << se;
        e = -1;
    }else
        try{
            std::string res;
            std::shared_ptr<kul::http::ARequest> req = handleRequest(cnt.str(), res);
            const kul::http::AResponse& rs(respond(*req.get()));
            std::string ret(rs.toString());
            e = SSL_write(ssl, ret.c_str(), ret.length());
        }catch(const kul::http::Exception& e1){
            KERR << e1.what(); 
            e = -1;
        }
    close(newsockfd);
    KOUT(DBG) << "Disconnect , socket fd is " << newsockfd << ", is : " << inet_ntoa(cli_addr.sin_addr) << ", port : "<< ntohs(cli_addr.sin_port);
    onDisconnect(inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port));
}
Ejemplo n.º 19
0
void tstMainWindow::onDisconnected(const QUrl& server)
{
    Q_UNUSED(server);

    d->host_button->setText("Connect");

    QObject::disconnect(d->host_button, SIGNAL(clicked()), this, SLOT(onDisconnect()));
       QObject::connect(d->host_button, SIGNAL(clicked()), this, SLOT(onConnect()));
}
Ejemplo n.º 20
0
void RTAutomationManager::closeEvent(QCloseEvent *)
{
    onDisconnect();
    if (m_client) {
        m_client->exitThread();
        m_client = NULL;
    }
    saveWindowState();
}
Ejemplo n.º 21
0
void UDPConnection::receivedDisconnect(){
	auto udp_interface = std::static_pointer_cast<UDPInterface>(getParent());

	conn_send_timer.cancel();
	conn_receive_timeout.cancel();

	udp_interface->getDisconnectCallback()((int)P2PError::connection_reset, shared_from_this());
	m_connected = false;
	onDisconnect();
}
Ejemplo n.º 22
0
void SocketBase::disconnect()
{
	if (_handle != INVALID_SOCKET)
	{
		closesocket(_handle);
		_handle = INVALID_SOCKET;

		onDisconnect();
	}
}
Ejemplo n.º 23
0
void Server::newConnection()
{
    socket = server->nextPendingConnection();
    connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
    connect(socket, SIGNAL(disconnected()), this, SLOT(onDisconnect()));

    /* No more connections, pleeeease */
    server->close();
    std::cout << "Connection established!";
    emit connectionEstablished();
}
Ejemplo n.º 24
0
ServerClient::ServerClient(qintptr socketDescriptor, ServerCore *server, QObject *parent) : QObject(parent)
{
    mainSocket = new QTcpSocket();

    mainSocket->setSocketDescriptor(socketDescriptor);

    connect(mainSocket,SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(mainSocket,SIGNAL(disconnected()), this, SLOT(onDisconnect()));

    servPtr = server;
}
Ejemplo n.º 25
0
MainController::MainController(ProjectorWindow &target) :
		ProjectorController(target), m_net(new ProjectorNet(this)), m_stageDataCounter(0),
		m_connected(false), m_view(TemplateManager::INDEX),
		m_activeQuestionIndex(0), m_activeRound (0) {
	connect(m_net, SIGNAL(onConnect()), this, SLOT(onConnect()));
	connect(m_net, SIGNAL(onContestState(ushort,CONTEST_STATUS)), this, SLOT(onContestState(ushort,CONTEST_STATUS)));
	connect(m_net, SIGNAL(onContestTime(ushort)), this, SLOT(onContestTime(ushort)));
	connect(m_net, SIGNAL(onDisconnect()), this, SLOT(onDisconnect()));
	connect(m_net, SIGNAL(onError(QString)), this, SLOT(onError(QString)));
	connect(m_net, SIGNAL(onQuestionState(ushort,ushort,QUESTION_STATUS)), this, SLOT(onQuestionState(ushort,ushort,QUESTION_STATUS)));
	connect(m_net, SIGNAL(onShowAnswer()), this, SLOT(onShowAnswer()));
	connect(m_net, SIGNAL(onHideAnswer()), this, SLOT(onHideAnswer()));
	connect(m_net, SIGNAL(onShowContestRanks(vector<RankData>)), this, SLOT(onShowContestRanks(vector<RankData>)));
	connect(m_net, SIGNAL(onShowContestTime()), this, SLOT(onShowContestTime()));
	connect(m_net, SIGNAL(onShowMainScreen()), this, SLOT(onShowMainScreen()));
	connect(m_net, SIGNAL(onStageData(ushort, QString)), this, SLOT(onStageData(ushort, QString)));
	connect(m_net, SIGNAL(onNumRounds(ushort)), this, SLOT(onRoundsReceived(ushort)));

	QTimer::singleShot(CONNECT_DELAY, this, SLOT(connectToServer()));
}
Ejemplo n.º 26
0
void MainController::onError( const QString& error ) {
	(qDebug() << "MainController::onError");
	m_lastError = error;
	if ( m_connected ) {
		//assume onDisconnect will get called...
		m_target.displayError("Connection error.", error.toStdString().c_str());
	} else {
		onDisconnect();
	}

}
Ejemplo n.º 27
0
void RTAutomationManager::clientConnected()
{
    QSettings settings;

    m_brokerStatus->setText("Connected to " + settings.value(RTAUTOMATION_PARAMS_BROKERADDRESS).toString());
    m_serverName->setText(QString("Using automation server: ") + settings.value(RTAUTOMATION_PARAMS_SERVERID).toString());
    m_dialog = new DialogMenu(settings.value(RTAUTOMATION_PARAMS_SERVERID).toString(), this);
    connect(m_dialog, SIGNAL(sendAppData(QJsonObject)), m_client, SLOT(sendCommandData(QJsonObject)));
    connect(m_client, SIGNAL(receiveCommandData(QJsonObject)), m_dialog, SLOT(receiveAppData(QJsonObject)));
    m_dialog->exec();
    onDisconnect();
}
void ParupaintClientInstance::message(const QString & id, const QByteArray & bytes)
{
	const QJsonObject object = QJsonDocument::fromJson(bytes).object();

	if(id == "connect"){
		emit onConnect();
		if(this->url().host() != "localhost"){
			emit onSpectateChange(!(client_joined = false));
		}

		this->doName();
		if(this->url().host() == "localhost"){
			this->doJoin();
		}

	} else if(id == "disconnect"){
		emit onDisconnect(bytes);
		pool->clearCursors();

	// we got confirmation
	} else if(id == "join"){
		emit onSpectateChange(!(client_joined = true));

		// TODO clean this up??
		// this is to make sure that, even if you reconnect
		// you will send fresh data to the new server
		shadow_brush.setPressure(0);
		shadow_brush.setColor(QColor(-1, -1, -1, -1));
		shadow_brush.setSize(-1);
		shadow_brush.setTool(-1);
		shadow_brush.setDrawing(false);

	} else if(id == "leave"){
		emit onSpectateChange(!(client_joined = false));

	} else if(id == "info") {
		if(object["painters"].isDouble()){
			emit onPlayerCountChange(object["painters"].toInt());
		}
		if(object["spectators"].isDouble()){
			emit onSpectatorCountChange(object["spectators"].toInt());
		}
		if(object["password"].isBool()){
			remote_password = object["password"].toBool(false);
		}
		foreach(const QString & key, object.keys()){
			QVariant val = object[key].toVariant();
			if(key == "project-bgc" && val.type() == QVariant::String) val = QColor(val.toString());
			ParupaintCommonOperations::CanvasAttributeOp(pool->canvas(), key, val);
		}

	} else if(id == "brush"){
Ejemplo n.º 29
0
void UDPConnection::receivedKeepAlive() {
	auto udp_interface = std::static_pointer_cast<UDPInterface>(getParent());

	conn_receive_timeout.expires_from_now(std::chrono::seconds(udp_interface->getInactivityTimeout()));
	conn_receive_timeout.async_wait([&, this](const boost::system::error_code& error){
		if(error != boost::asio::error::operation_aborted){
			udp_interface->getDisconnectCallback()((int)P2PError::timed_out, shared_from_this());
			m_connected = false;
			onDisconnect();
		}
	});
	m_connected = true;
}
Ejemplo n.º 30
0
/*! \brief Create the context menu for the connections tree. */
void ApplicationViewWidget::createConnectionsViewContextMenu()
{
    connContex = new QMenu(ui->connectionList);
    connSubMenu =  new QMenu("Inspect",connContex);

    connConnectAction = new QAction("Connect",connContex);
    connDisconnectAction = new QAction("Disconnect",connContex);
    connSeparatorAction = new QAction(connContex);
    connSeparatorAction->setSeparator(true);
    connRefreshAction = new QAction("Refresh Status",connContex);
    connSelectAllAction = new QAction("Select All Connections",connContex);
    conn1SeparatorAction = new QAction(connContex);
    conn1SeparatorAction->setSeparator(connContex);

    connYARPViewAction = new QAction("yarpview",connSubMenu);
    connYARPReadAction = new QAction("yarpread",connSubMenu);
    connYARPHearAction = new QAction("yarphear",connSubMenu);
    connYARPScopeAction = new QAction("yarpscope",connSubMenu);

    connSelectAllAction->setIcon(QIcon(":/select-all22.svg"));
    connRefreshAction->setIcon(QIcon(":/refresh22.svg"));
    connConnectAction->setIcon(QIcon(":/connect22.svg"));
    connDisconnectAction->setIcon(QIcon(":/disconnect22.svg"));

    connect(connConnectAction,SIGNAL(triggered()),this,SLOT(onConnect()));
    connect(connDisconnectAction,SIGNAL(triggered()),this,SLOT(onDisconnect()));
    connect(connRefreshAction,SIGNAL(triggered()),this,SLOT(onRefresh()));
    connect(connSelectAllAction,SIGNAL(triggered()),this,SLOT(selectAllConnections()));

    connect(connYARPViewAction,SIGNAL(triggered()),this,SLOT(onYARPView()));
    connect(connYARPReadAction,SIGNAL(triggered()),this,SLOT(onYARPRead()));
    connect(connYARPHearAction,SIGNAL(triggered()),this,SLOT(onYARPHear()));
    connect(connYARPScopeAction,SIGNAL(triggered()),this,SLOT(onYARPScope()));

    connContex->addAction(connConnectAction);
    connContex->addAction(connDisconnectAction);
    connContex->addAction(connSeparatorAction);
    connContex->addAction(connRefreshAction);
    connContex->addAction(connSelectAllAction);
    connContex->addAction(conn1SeparatorAction);
    connContex->addMenu(connSubMenu);

    connSubMenu->addAction(connYARPViewAction);
    connSubMenu->addAction(connYARPReadAction);
    connSubMenu->addAction(connYARPHearAction);
    connSubMenu->addAction(connYARPScopeAction);


    ui->connectionList->setContextMenu(connContex);

}