예제 #1
0
void QLocalSocket::close()
{
    Q_D(QLocalSocket);
    if (state() == UnconnectedState)
        return;

    QIODevice::close();
    d->state = ClosingState;
    emit stateChanged(d->state);
    if (!d->pipeClosed)
        emit readChannelFinished();
    d->serverName = QString();
    d->fullServerName = QString();

    if (state() != UnconnectedState && bytesToWrite() > 0) {
        disconnectFromServer();
        return;
    }
    d->readSequenceStarted = false;
    d->pendingReadyRead = false;
    d->pipeClosed = false;
    d->destroyPipeHandles();
    d->handle = INVALID_HANDLE_VALUE;
    ResetEvent(d->overlapped.hEvent);
    d->state = UnconnectedState;
    emit stateChanged(d->state);
    emit disconnected();
    if (d->pipeWriter) {
        delete d->pipeWriter;
        d->pipeWriter = 0;
    }
}
예제 #2
0
DWORD WINAPI startOddcast(LPVOID lpParameter) 
{

	
	initializeencoder();
	if (connectToServer()) {
		setCurrentSongTitle("");
		UpdateWhatsPlaying();
	}
	else {
		MessageBox(NULL, "Unable to Connect", NULL, MB_OK);
		return(0);
	}
	if (getLiveRecordingSetFlag()) {
		if (!initLiveRecording()) {
			MessageBox(NULL, "Fail to open input device", NULL, MB_OK);
			disconnectFromServer();
			return 0;
		}
		else {
			char	buf[255] = "";
			sprintf(buf, "%dHz/Stereo PCM", getLiveInSamplerate());
			setSourceDescription(buf);
			int songChange = setCurrentSongTitle(getServerDesc());
			startRecording();
		}
	}
	return 1;
}
void ShipSelectionScreen::update(float delta)
{
    if (game_client && game_client->getStatus() == GameClient::Disconnected)
    {
        destroy();
        disconnectFromServer();
        returnToMainMenu();
        return;
    }
    
    for(int n=0; n<GameGlobalInfo::max_player_ships; n++)
    {
        P<PlayerSpaceship> ship = gameGlobalInfo->getPlayerShip(n);
        if (ship)
        {
            if (player_ship_list->indexByValue(string(n)) == -1)
            {
                int index = player_ship_list->addEntry(ship->ship_type_name + " " + ship->getCallSign(), string(n));
                if (my_spaceship == ship)
                    player_ship_list->setSelectionIndex(index);
            }
        }else{
            if (player_ship_list->indexByValue(string(n)) != -1)
                player_ship_list->removeEntry(player_ship_list->indexByValue(string(n)));
        }
    }
    if (player_ship_list->entryCount() > 0)
    {
        no_ships_label->hide();
    }else{
        no_ships_label->show();
    }
}
예제 #4
0
void RemoteClient::readData()
{
	QByteArray data = socket->readAll();
	qDebug() << data;
	xmlReader->addData(data);
	lastDataReceived = timeRunning;

	while (!xmlReader->atEnd()) {
		xmlReader->readNext();
		if (topLevelItem)
			topLevelItem->readElement(xmlReader);
		else if (xmlReader->isStartElement() && (xmlReader->name().toString() == "cockatrice_server_stream")) {
			int serverVersion = xmlReader->attributes().value("version").toString().toInt();
			if (serverVersion != ProtocolItem::protocolVersion) {
				emit protocolVersionMismatch(ProtocolItem::protocolVersion, serverVersion);
				disconnectFromServer();
				return;
			}
			xmlWriter->writeStartDocument();
			xmlWriter->writeStartElement("cockatrice_client_stream");
			xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion));
			xmlWriter->writeAttribute("comp", "1");
			
			topLevelItem = new TopLevelProtocolItem;
			connect(topLevelItem, SIGNAL(protocolItemReceived(ProtocolItem *)), this, SLOT(processProtocolItem(ProtocolItem *)));
			
			setStatus(StatusLoggingIn);
			Command_Login *cmdLogin = new Command_Login(userName, password);
			connect(cmdLogin, SIGNAL(finished(ProtocolResponse *)), this, SLOT(loginResponse(ProtocolResponse *)));
			sendCommand(cmdLogin);
		}
	}
예제 #5
0
파일: GSM.cpp 프로젝트: cihstar/ProjectLono
/* Send an HTTP Post request */
string GSM::httpPost(string url1, string url2, string data)
{
    waitForLongOperationToFinish();
    longOperationInProg = true;            
    if (!connectToServer(url1))
    {
        longOperationInProg = false;
        return "ERROR_NOT_CONNECTED";
    }  
            
    wait(2); 
    ptr_GSM_msg m;
    
    /* The command to send: */
    string str("AT^HTTPCMD=0,POST,"+url1+url2+","+util::ToString(data.length())+",\"application/x-www-form-urlencoded\"");   
    m = sendCommand(str);
    
    /* If successful, return connect. Then need to send the data to send */
    if (m->getMessage(0).find("CONNECT") != string::npos)
    {     
        m = sendCommand(data,3);
        if (m->getMessage(1).find("OK") != string::npos)
        {          
            /* Success */
            longOperationInProg = false;
            
            /* Return the reply from server */           
            return m->getMessage(0);
        }
    }    
    /* Failure */
    disconnectFromServer();
    longOperationInProg = false;
    return "ERROR_CONNECT_FAILED";
}
예제 #6
0
파일: main.cpp 프로젝트: bedahr/recomment
int main(int argc, char *argv[])
{
    QCoreApplication::addLibraryPath("app/native/plugins");
    QApplication app(argc, argv);

    bool voiceControlled = true;
    SimondConnector *connector;
    if (voiceControlled)
        connector = new SimondConnector;
    else
        connector = 0;

    Recomment recomment;
    QMLRecommentView view(&recomment, voiceControlled);

    if (voiceControlled) {
        QObject::connect(&view, SIGNAL(connectToServer()), connector, SLOT(connectToServer()));
        QObject::connect(&view, SIGNAL(disconnectFromServer()), connector, SLOT(disconnectFromServer()));
        QObject::connect(&view, SIGNAL(startRecording()), connector, SLOT(startRecording()));
        QObject::connect(&view, SIGNAL(commitRecording()), connector, SLOT(commitRecording()));
        QObject::connect(&view, SIGNAL(configurationChanged()), connector, SLOT(configurationChanged()));

        QObject::connect(connector, SIGNAL(connectionState(ConnectionState)), &view, SLOT(displayConnectionState(ConnectionState)));
        QObject::connect(connector, SIGNAL(status(QString)), &view, SLOT(displayStatus(QString)));
        QObject::connect(connector, SIGNAL(error(QString)), &view, SLOT(displayError(QString)));
        QObject::connect(connector, SIGNAL(listening()), &view, SLOT(displayListening()));
        QObject::connect(connector, SIGNAL(recognizing()), &view, SLOT(displayRecognizing()));
        QObject::connect(connector, SIGNAL(microphoneLevel(int,int,int)), &view, SLOT(displayMicrophoneLevel(int,int,int)));
        //QObject::connect(connector, SIGNAL(recognized(QString)), &view, SLOT(displayExecutedAction(QString)));
        QObject::connect(connector, SIGNAL(recognized(QString)), &recomment, SLOT(critique(QString)));
    }

    QObject::connect(&recomment, SIGNAL(recommend(const Offer*, QString)), &view, SLOT(displayRecommendation(const Offer*, QString)));
    QObject::connect(&recomment, SIGNAL(noMatchFor(QString)), &view, SLOT(displayNoMatch(QString)));

    view.show();
    if (voiceControlled)
        connector->init();
    if (!recomment.init()) {
        qWarning() << "Failed to initialize Recomment; Aborting";
        return -1;
    }

    int ret = app.exec();
    delete connector;
    return ret;
}
예제 #7
0
static void sigintServHandler(int signo) {

	companyWorking = FALSE;
	disconnectFromServer(client);
	freeCompanyResources();

	exit(0);
}
예제 #8
0
XmppClient::XmppClient() :
    _xmppClient(),
    _xmppMUCManager()
{
    AccountManager& accountManager = AccountManager::getInstance();
    connect(&accountManager, SIGNAL(profileChanged()), this, SLOT(connectToServer()));
    connect(&accountManager, SIGNAL(logoutComplete()), this, SLOT(disconnectFromServer()));
}
void MainWindow::quitProgram()
{
    if (!okToClose())
        return;
    writeSettings();
    disconnectFromServer();
    qApp->quit();
}
예제 #10
0
void TutorialGame::finish()
{
    script->destroy();
    destroy();
    
    disconnectFromServer();
    returnToMainMenu();
}
예제 #11
0
// Получение данных от сервера
int Client::slotReceiveData()
{
    bool result = false;
    QByteArray data;
    quint16 sizeOfPackage = 0;
    quint8 packageType = 0;

    while (true)
    {
	if (mClientSocket != 0)
	    mReceivedData.append(mClientSocket->readAll());

	if (mReceivedData.size() < (quint16)sizeof(quint16))
	    break;

	memcpy(&sizeOfPackage,
	       mReceivedData.data(),
	       sizeof(quint16));

	if (mReceivedData.size() < sizeOfPackage || sizeOfPackage == 0)
	    break;

	memcpy(&packageType,
	       mReceivedData.data() + sizeof(quint16),
	       sizeof (quint8));

	const quint16 specialData = sizeof(quint16) + sizeof(quint8);
	data = mReceivedData.mid(specialData,
				 sizeOfPackage - specialData);

	mReceivedData = mReceivedData.mid(sizeOfPackage);

	// Обработка пакета
	switch (packageType)
	{
	case PackageType::Command:
	    result = this->parseCommandPackage(data);
	    break;
	case PackageType::Data:
	    result = this->parseDataPackage(data);
	    break;
	case PackageType::DescriptionResponse:
	    result = this->parseDBResponsePackage(data);
	    break;
	default:
	    result = true;
	}

	if (!result)
	    break;
    }

    if (!result)
	disconnectFromServer();

    return 0;
}
예제 #12
0
/* DESTRUCTOR */
MainWindow::~MainWindow() {

    if(log_ == true) {
        close_log_file(logfd_);
    }
    disconnectFromServer();
    pthread_cancel(tid_);
    delete MainWindow::ui_;

}
예제 #13
0
void CrewStationScreen::update(float delta)
{
    if (game_client && game_client->getStatus() == GameClient::Disconnected)
    {
        destroy();
        disconnectFromServer();
        returnToMainMenu();
        return;
    }
}
예제 #14
0
void ClientWidget::keyReleaseEvent(QKeyEvent *e){
    qDebug()<<ENCAPS(tr("keyReleaseEvent() with key: "))<<e->key();
    QByteArray qba;
    QDataStream stream(&qba,QIODevice::WriteOnly);
    bool send=false;
    switch(e->key()){
    case Qt::Key_PageUp:
        stream <<QString("SET_VELOCITY");
        stream << 0;
        stream << me.velocity+QVector3D(0,0,0.01f);
        send=true;
        break;
    case Qt::Key_PageDown:
        stream <<QString("SET_VELOCITY");
        stream << 0;
        stream << me.velocity-QVector3D(0,0,0.01f);
        send=true;
        break;
    case Qt::Key_Left:
        stream <<QString("SET_VELOCITY");
        stream << 0;
        stream << me.velocity+QVector3D(0.01f,0,0);
        send=true;
        break;
    case Qt::Key_Right:
        stream <<QString("SET_VELOCITY");
        stream << 0;
        stream << me.velocity-QVector3D(0.01f,0,0);
        send=true;
        break;
    case Qt::Key_Up:
        stream <<QString("SET_VELOCITY");
        stream << 0;
        stream << me.velocity+QVector3D(0,0.01f,0);
        send=true;
        break;
    case Qt::Key_Down:
        stream <<QString("SET_VELOCITY");
        stream << 0;
        stream << me.velocity-QVector3D(0,0.01f,0);
        send=true;
        break;
    case Qt::Key_Escape:
        if(e->modifiers() == Qt::ControlModifier){
            qApp->exit();
        }else{
            qDebug()<<ENCAPS(tr("disconnecting from server..."));
            emit disconnectFromServer();
        }
        break;
    }
    if(send)
        emit sendToServer(qba);
}
void MainWindow::disconnectPressed()
{
    if (irc->isConnected() || irc->isRunning())
    {
        if (irc->isConnected())
            playSound(SND_QUIT);
        disconnectFromServer();
        setWindowTitle(tr("Hydrochat"));
        return;
    }
    sltMessage("PROGRAM", tr("Not connected"));
}
예제 #16
0
void XmppClient::connectToServer() {
    disconnectFromServer();

    if (_xmppClient.addExtension(&_xmppMUCManager)) {
        connect(&_xmppClient, SIGNAL(connected()), this, SLOT(xmppConnected()));
        connect(&_xmppClient, SIGNAL(error(QXmppClient::Error)), this, SLOT(xmppError(QXmppClient::Error)));
    }
    AccountManager& accountManager = AccountManager::getInstance();
    QString user = accountManager.getAccountInfo().getUsername();
    const QString& password = accountManager.getAccountInfo().getXMPPPassword();
    _xmppClient.connectToServer(user + "@" + DEFAULT_XMPP_SERVER, password);
}
예제 #17
0
void Manager::connectToServer(const QString &_host, int _port)
{
    disconnectFromServer();
    Q_EMIT message(QString(tr("Attempting connect to host %1 (%2).")).arg(_host).arg(_port));
    m_tcpSocket->connectToHost(_host, _port);
    if(m_tcpSocket->waitForConnected()) {
        Q_EMIT message(QString(tr("Connected to host %1 (%2).")).arg(_host).arg(_port));
        setStatus(tr("Connected"));
    } else {
        Q_EMIT message(tr("Connect failed."));
    }
}
예제 #18
0
   void CServerManager::slotTimeStartOut()
   {
      qDebug("Network - stop timer");

      m_timerConfirm.stop();

      Message::CMessageInformationPtr ptr(new Message::CMessageInformation);
      ptr->m_typeInformation = Message::CMessageInformation::eConnectionToServer;
      ptr->m_strInformation = "Error, time wait confirmation from server - out";

      emit SendInInformation(ptr);

      disconnectFromServer();
   }
예제 #19
0
void TopDownScreen::update(float delta)
{
    // If this is a client and it is disconnected, exit.
    if (game_client && game_client->getStatus() == GameClient::Disconnected)
    {
        destroy();
        disconnectFromServer();
        returnToMainMenu();
        return;
    }

    // Enable mouse wheel zoom.
    float mouse_wheel_delta = InputHandler::getMouseWheelDelta();
    if (mouse_wheel_delta != 0.0)
    {
        camera_position.z = camera_position.z * (1.0 - (mouse_wheel_delta) * 0.1f);
        if (camera_position.z > 10000)
            camera_position.z = 10000;
        if (camera_position.z < 1000)
            camera_position.z = 1000;
    }

    // Add and remove entries from the player ship list.
    for(int n=0; n<GameGlobalInfo::max_player_ships; n++)
    {
        P<PlayerSpaceship> ship = gameGlobalInfo->getPlayerShip(n);
        if (ship)
        {
            if (camera_lock_selector->indexByValue(string(n)) == -1)
                camera_lock_selector->addEntry(ship->getTypeName() + " " + ship->getCallSign(), string(n));
        }else{
            if (camera_lock_selector->indexByValue(string(n)) != -1)
                camera_lock_selector->removeEntry(camera_lock_selector->indexByValue(string(n)));
        }
    }

    // Enforce a top-down view with up pointing toward heading 0.
    camera_yaw = -90.0f;
    camera_pitch = 90.0f;

    // If locked onto a player ship, move the camera along with it.
    if (camera_lock_toggle->getValue() && target)
    {
        sf::Vector2f target_position = target->getPosition();

        camera_position.x = target_position.x;
        camera_position.y = target_position.y;
    }
}
예제 #20
0
/*
 * Close connection to remote host.
 */
void
SamrftDisconnect(
	SamrftImpl_t *rftd)
{
	if (rftd == NULL) {
		return;
	}

	Trace(TR_RFT, "Samrft [%d] disconnect", traceRftd(rftd));

	if (rftd->remotehost) {
		disconnectFromServer(rftd);
	}
	SamFree(rftd);
}
예제 #21
0
ChatWindow::ChatWindow(QWidget *parent)
: QWidget(parent), ui(new Ui::ChatWindowClass) {
    
    ui->setupUi(this);
    ui->splitter->hide();

    connect(ui->buttonConnect, SIGNAL(clicked()), this, SLOT(connecte()));
    connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close()));
    connect(ui->actionCloseTab, SIGNAL(triggered()), this, SLOT(closeTab()));
    connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(sendCommand()));
    connect(ui->disconnect, SIGNAL(clicked()), this, SLOT(disconnectFromServer()));
    connect(ui->tab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
    connect(ui->tab, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosing(int)));
    
    connect(ui->userView, SIGNAL(clicked(const QModelIndex &) ), this, SLOT( userClicked() ) );
}
void ConnectionClient::finishProcess()
{
    TIME_SCOPE_DURATION("ConnectionClient::finishProcess");

    processAliveTimer.stop();

    disconnectProcessFinished();
    endProcess();
    disconnectFromServer();
    terminateProcess();
    killProcess();

    process_.reset();

    serverProxy_.resetCounter();
}
예제 #23
0
파일: gpsd.cpp 프로젝트: buelowp/startrac
void Gpsd::connectToServer(const QString &h, quint16 p, Gpsd::StreamMode m)
{
    if (isConnected()) {          // We're connected
        disconnectFromServer();   // disconnect first
    }

    host = h;
    port = p;
    if (gps_open(h.toLatin1().data(), QString().setNum(p).toLatin1().data(), &gpsdata) == 0) {
        notifier = new QSocketNotifier(gpsdata.gps_fd, QSocketNotifier::Read);
        notifier->setEnabled(true);
        connect(notifier, SIGNAL(activated(int)), this, SLOT(handleInput(int)));
        emit connectionStatus(true);

        gps_stream(&gpsdata, WATCH_ENABLE|m, NULL);
    } else {
예제 #24
0
void RemoteClient::loginResponse(ProtocolResponse *response)
{
	if (response->getResponseCode() == RespOk) {
		Response_Login *resp = qobject_cast<Response_Login *>(response);
		if (!resp) {
			disconnectFromServer();
			return;
		}
		setStatus(StatusLoggedIn);
		emit userInfoChanged(resp->getUserInfo());
		emit buddyListReceived(resp->getBuddyList());
		emit ignoreListReceived(resp->getIgnoreList());
	} else {
		emit serverError(response->getResponseCode());
		setStatus(StatusDisconnecting);
	}
}
void MainWindow::closeEvent(QCloseEvent *event)
{
    if (settings.trayicon && settings.minimizeonclose)
    {
        hide();
        ui->actionShowHide->setText(tr("Show"));
        event->ignore();
        return;
    }
    if (okToClose())
    {
        writeSettings();
        disconnectFromServer();
        qApp->quit();
        return;
    }
    event->ignore();
}
예제 #26
0
void Client::menuTool()
{
    menu = menuBar()->addMenu(tr("Menu"));

    connectToServerAction = new QAction("Connect", this);
    connect(connectToServerAction, SIGNAL(triggered()), this, SLOT(showWindowOfConnection()));
    menu->addAction(connectToServerAction);

    disconnectFromServerAction = new QAction("Disconnect", this);
    connect(disconnectFromServerAction, SIGNAL(triggered()), this, SLOT(disconnectFromServer()));
    menu->addAction(disconnectFromServerAction);

    menu->addSeparator();

    quitProgramAction = new QAction("Exit", this);
    connect(quitProgramAction, SIGNAL(triggered()), this, SLOT(exitProgram()));
    menu->addAction(quitProgramAction);
}
예제 #27
0
void QLocalSocket::close()
{
    Q_D(QLocalSocket);
    if (openMode() == NotOpen)
        return;

    QIODevice::close();
    d->serverName = QString();
    d->fullServerName = QString();

    if (state() != UnconnectedState) {
        if (bytesToWrite() > 0) {
            disconnectFromServer();
            return;
        }

        d->_q_pipeClosed();
    }
}
예제 #28
0
void Client::btnConnectOnClick() {
	if (connectionState == ConnectionState::STATE_DISCONNECTED) {
		if ((serverConfiguration == nullptr) || (clientConfiguration == nullptr)) {
			QMessageBox::warning(this, "Can not connect", "Please choose a valid client configuration file first.");
			return;
		}

		setupProtocolClient();

		ui.btnConnect->setEnabled(false);
		ui.btnConnect->setText("Connecting...");
		QTimer::singleShot(0, protocolClient, SLOT(connectToServer()));
	} else if (connectionState == ConnectionState::STATE_CONNECTING) {
		// No click should be possible in this state
		ui.btnConnect->setEnabled(false);
	} else if (connectionState == ConnectionState::STATE_CONNECTED) {
		ui.btnConnect->setEnabled(false);
		ui.btnConnect->setText("Disconnecting...");
		QTimer::singleShot(0, protocolClient, SLOT(disconnectFromServer()));
	}
}
예제 #29
0
void RemoteClient::ping()
{
    QMutableMapIterator<int, PendingCommand *> i(pendingCommands);
    while (i.hasNext()) {
        PendingCommand *pend = i.next().value();
        if (pend->tick() > maxTimeout) {
            i.remove();
            pend->deleteLater();
        }
    }

    int maxTime = timeRunning - lastDataReceived;
    emit maxPingTime(maxTime, maxTimeout);
    if (maxTime >= maxTimeout) {
        disconnectFromServer();
        emit serverTimeout();
    } else {
        sendCommand(prepareSessionCommand(Command_Ping()));
        ++timeRunning;
    }
}
예제 #30
0
void WindowScreen::update(float delta)
{
    if (game_client && game_client->getStatus() == GameClient::Disconnected)
    {
        destroy();
        disconnectFromServer();
        returnToMainMenu();
        return;
    }

    if (my_spaceship)
    {
        camera_yaw = my_spaceship->getRotation() + angle;
        camera_pitch = 0.0f;
        
        sf::Vector2f position = my_spaceship->getPosition() + sf::rotateVector(sf::Vector2f(my_spaceship->getRadius(), 0), camera_yaw);

        camera_position.x = position.x;
        camera_position.y = position.y;
        camera_position.z = 0.0;
    }
}