Example #1
0
void ChessEngine::setDevice(QIODevice* device)
{
	Q_ASSERT(device != 0);

	m_ioDevice = device;
	m_ioDevice->setParent(this);

	connect(m_ioDevice, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
	connect(m_ioDevice, SIGNAL(readChannelFinished()), this, SLOT(onCrashed()));
}
Example #2
0
void MainWindow::connectedToHost()
{
	isserver = FALSE;
	ui->statusBar->showMessage("Connected to Player1. Waiting for Player1's move...");
	turn = FALSE;
	ui->gameBox->setEnabled(TRUE);
	ui->playButton->setEnabled(FALSE);
//	connect(ui->tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(gameStatus()));
	connect(socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
}
Example #3
0
OMProcess::OMProcess(QObject *parent) :
    QProcess(parent)
{

    _dispOut = true;

    setProcessChannelMode(MergedChannels);
    if(_dispOut)
        connect(this,SIGNAL(readyReadStandardOutput()),this,SLOT(onReadyRead()));
}
Example #4
0
File: glove.cpp Project: Tatk/hand
void Glove::startSendingData()
{
	if (!mPort->open(QIODevice::ReadWrite)) {
		return;
	}

	setPortSettings();

	QObject::connect(mPort, SIGNAL(readyRead()), this, SLOT(onReadyRead()));\
}
Example #5
0
void SocketThread::run()
{
    Socket=new QTcpSocket();
    Socket->setSocketDescriptor(SocketDescriptor);

    connect (Socket,SIGNAL(readyRead()),this,SLOT(onReadyRead()),Qt::DirectConnection);
    connect (Socket,SIGNAL(disconnected()),this,SLOT(onDisconnected()),Qt::DirectConnection);

    exec();
}
HttpServerRequest::HttpServerRequest(QAbstractSocket &socket, QObject *parent) :
    QObject(parent),
    priv(new Priv(this, socket))
{
    connect(&socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(&socket, SIGNAL(disconnected()), this, SIGNAL(close()));

    connect(priv->timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
    if (priv->timeout)
        priv->timer->start(priv->timeout);
}
void Connection::connectToServer() {
    Q_ASSERT(!m_host.isEmpty());
    Q_ASSERT(m_port);

    connect(this, SIGNAL(connected()), SLOT(onConnected()), Qt::UniqueConnection);
    connect(this, SIGNAL(disconnected()), SLOT(onDisconnected()), Qt::UniqueConnection);
    connect(this, SIGNAL(readyRead()), SLOT(onReadyRead()), Qt::UniqueConnection);
    connect(this, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onError(QAbstractSocket::SocketError)), Qt::UniqueConnection);

    connectToHost(m_host, m_port);
}
Example #8
0
void MainWindow::onReadyRead() {
    static QByteArray buffer = "";
    QByteArray b = ioDev->readAll();
    save+=b;
    buffer += b;
    if(b.length()) QTimer::singleShot(500, this, SLOT(onReadyRead()));
    else {
        processData(buffer);
        buffer = "";
    }
}
Example #9
0
void Sender::onNewConnection() {
    socket = server->nextPendingConnection();
    connect(socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    label->setText(tr("Sending..."));
    // send file name
    QString filename = QFileInfo(filepath).fileName();
    socket->write(filename.toUtf8());
    socket->flush();
    // set next step
    step = SEND_SIZE;
}
Example #10
0
void OftSocket::init()
{
	connect(this, SIGNAL(readyRead()), SLOT(onReadyRead()));
	connect(this, SIGNAL(connected()), this, SLOT(connected()));
	m_state = ReadHeader;
	m_len = 0;
	m_hostReqId = 0;
	m_timer.setInterval(FILETRANSFER_WAITING_TIMEOUT);
	m_timer.setSingleShot(true);
	connect(&m_timer, SIGNAL(timeout()), SLOT(onTimeout()));
}
Example #11
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;
}
void DownloadFragmnet::Download(QString fileURL,int start,int end)
{
    setBoubdaries(start,end);
    QNetworkRequest request;
    request.setUrl(QUrl(fileURL));
    QByteArray rangeHeaderValue = "bytes=" + QByteArray::number(startByte) + "-"+ QByteArray::number(endByte);
    request.setRawHeader("Range",rangeHeaderValue);
    reply = manager->get(request);
    connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(onDownloadProgress(qint64,qint64)));
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(onFinished(QNetworkReply*)));
    connect(reply,SIGNAL(readyRead()),this,SLOT(onReadyRead()));
}
/*! Constructs a coap access manager with the given \a parent and \a port. */
CoapNetworkAccessManager::CoapNetworkAccessManager(QObject *parent, const quint16 &port) :
    QObject(parent),
    m_port(port)
{
    m_socket = new QUdpSocket(this);

    if (!m_socket->bind(QHostAddress::Any, m_port, QAbstractSocket::ShareAddress))
        qCWarning(dcCoap) << "Could not bind to port" << m_port << m_socket->errorString();

    connect(m_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
}
Example #14
0
SerialMonitor::SerialMonitor(const QString& portName, QWidget *parent) :
    QFrame(parent),
    mPortName(portName)
{
    setupUi(this);

    sendHexEdit = new QHexEdit();
    gridLayoutSend->addWidget(sendHexEdit, 1, 0, 1, 1);

    recvHexEdit = new QHexEdit();
    gridLayoutRecv->addWidget(recvHexEdit, 1, 0, 1, 1);

    recvHexEdit->setAddressArea(false);
    recvHexEdit->setOverwriteMode(false);
    recvHexEdit->setReadOnly(true);

    sendHexEdit->setAddressArea(false);
    sendHexEdit->setAsciiArea(false);
    sendHexEdit->setOverwriteMode(false);

    settingMenu = 0;

    serialPort = new QextSerialPort(portName, QextSerialPort::EventDriven);

    connect(btnConnect, SIGNAL(clicked()), this, SLOT(openDevice()));

    connect(serialPort, SIGNAL(readyRead()), this, SLOT(onReadyRead()));

    connect(btnSendData, SIGNAL(clicked()), this, SLOT(wirteData()));

    settingMapper = new QSignalMapper();

    connect(settingMapper, SIGNAL(mapped(QString)), this, SLOT(updateSetting(QString)));

    connect(btnSendFile, SIGNAL(clicked()),this, SLOT(sendFile()));

    connect(btnClearRecv, SIGNAL(clicked()), textRecv, SLOT(clear()));

    connect(btnClearRecv, SIGNAL(clicked()), recvHexEdit, SLOT(clear()));

    connect(btnRecvTextMode, SIGNAL(clicked()), this, SLOT(switchRecvTextMode()));

    connect(btnSendTextMode, SIGNAL(clicked()), this, SLOT(switchSendTextMode()));

    recvTextModeHex = false;

    sendTextModeHex = false;

    updateUI();

    updateTextMode();
}
Example #15
0
GpsReceiver::GpsReceiver(QObject* parent) : QObject(parent),m_port(0)
{
    m_port = new QSerialPort("/dev/ttyUSB0");
    m_port->setBaudRate(QSerialPort::Baud9600);
    m_port->setDataBits(QSerialPort::Data8);
    m_port->setParity(QSerialPort::NoParity);
    m_port->setStopBits(QSerialPort::OneStop);
    bool isSuccess = m_port->open(QIODevice::ReadOnly);
    if (!isSuccess) {
        qDebug() << "port open() error code: " << m_port->error();
    }

    connect(m_port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
}
SerialComponent::SerialComponent(QGraphicsItem *parent):
    Component(parent)
{
    setupComponent();

    m_settingDialog = new SerialSettingsDialog();
    m_settingDialog->setConnection(&m_connection);

    connect(&m_connection, SIGNAL(readyRead()), this, SLOT(onReadyRead()));

    //    QMenu *menu = new QMenu();
    //    menu->addAction(new QAction("Open", menu));
    //    setMenu(menu);
}
Example #17
0
/** Main thread implementation. Creates and connects a control socket, then
 * spins up an event loop. */
void
ControlConnection::run()
{
  /* Create a new control socket */
  _connMutex.lock();
  _sock = new ControlSocket(_method);

  _connectTimer = new QTimer();
  _connectTimer->setSingleShot(true);
  
  QObject::connect(_sock, SIGNAL(readyRead()), this, SLOT(onReadyRead()),
                   Qt::DirectConnection);
  QObject::connect(_sock, SIGNAL(disconnected()), this, SLOT(onDisconnected()),
                   Qt::DirectConnection);
  QObject::connect(_sock, SIGNAL(connected()), this, SLOT(onConnected()),
                   Qt::DirectConnection);
  QObject::connect(_sock, SIGNAL(error(QAbstractSocket::SocketError)), 
                   this, SLOT(onError(QAbstractSocket::SocketError)),
                   Qt::DirectConnection);
  QObject::connect(_connectTimer, SIGNAL(timeout()), this, SLOT(connect()),
                   Qt::DirectConnection);

  _connMutex.unlock();
  
  /* Attempt to connect to Tor */
  connect();
  tc::debug("Starting control connection event loop.");
  exec();
  tc::debug("Exited control connection event loop.");

  /* Clean up the socket */
  _connMutex.lock();
  _sock->disconnect(this);
  delete _sock;
  delete _connectTimer;
  _sock = 0;
  _connMutex.unlock();

  /* If there are any messages waiting for a response, clear them. */
  if (_sendWaiter->status() == SendCommandEvent::SendWaiter::Waiting)
    _sendWaiter->setResult(false, tr("Control socket is not connected."));

  _recvMutex.lock();
  while (!_recvQueue.isEmpty()) {
    ReceiveWaiter *w = _recvQueue.dequeue();
    w->setResult(false, ControlReply(), 
                 tr("Control socket is not connected."));
  }
  _recvMutex.unlock();
}
    void         createSocket(qintptr sokDesc, TBackend bend) {
        isocket.ibackendType = bend;

        if        ( bend == ETcpSocket ) {
            QTcpSocket* sok    = new QTcpSocket( q_func() );
            isocket.itcpSocket = sok;
            sok->setSocketDescriptor(sokDesc);

            QObject::connect(sok,       &QTcpSocket::readyRead, [this](){
                onReadyRead();
            });
            QObject::connect(sok,       &QTcpSocket::bytesWritten, [this](){
                if ( isocket.itcpSocket->bytesToWrite() == 0  &&  ilastResponse )
                    emit ilastResponse->allBytesWritten();
            });
            QObject::connect(sok,       &QTcpSocket::disconnected,
                             q_func(),  &QHttpConnection::disconnected,
                             Qt::QueuedConnection);

        } else if ( bend == ELocalSocket ) {
            QLocalSocket* sok    = new QLocalSocket( q_func() );
            isocket.ilocalSocket = sok;
            sok->setSocketDescriptor(sokDesc);

            QObject::connect(sok,       &QLocalSocket::readyRead, [this](){
                onReadyRead();
            });
            QObject::connect(sok,       &QLocalSocket::bytesWritten, [this](){
                if ( isocket.ilocalSocket->bytesToWrite() == 0  &&  ilastResponse )
                    emit ilastResponse->allBytesWritten();
            });
            QObject::connect(sok,       &QLocalSocket::disconnected,
                             q_func(),  &QHttpConnection::disconnected,
                             Qt::QueuedConnection);
        }

    }
Example #19
0
// --------------------------------------------------------------------------
Client::Client(QObject* parent)
   : QObject(parent)
   , m_sock(0)
   , m_buf(0)
   , m_bufsize(4096)
   , m_timerId(0)
{
    m_sock = new QTcpSocket(this);

    m_buf = new char[m_bufsize];

    if (m_sock) {
        connect(m_sock, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    }
}
Example #20
0
int PortListener::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: onReadyRead(); break;
        case 1: onDsrChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 2;
    }
    return _id;
}
NjsProcess::NjsProcess( QObject *parent ) :
   QProcess( parent )
{
    connect( this, SIGNAL( readyRead() ), this, SLOT( onReadyRead() ) );
    this->setProcessChannelMode( QProcess::MergedChannels );
    this->setWorkingDirectory( QDir::toNativeSeparators( qApp->applicationDirPath() + QDir::separator() + "chromecast" ) );
    QString node = QDir::toNativeSeparators( qApp->applicationDirPath() + QDir::separator()
                                             + "chromecast" + QDir::separator()
#ifdef Q_OS_MAC
                                             + "node" );
#else
                                             + "node.exe" );
#endif
    this->setProgram( node );
}
// returns the sessionId, empty string if request fails
bool
PlaydarCometRequest::issueRequest(lastfm::NetworkAccessManager* wam, PlaydarApi& api)
{
    QNetworkReply* reply = wam->get(QNetworkRequest(api.comet(m_sessionId)));
    if (!reply) {
        return false;
    }

    m_parser = new CometParser(this);
    connect(m_parser, SIGNAL(haveObject(QVariantMap)), SIGNAL(receivedObject(QVariantMap)));
    connect(reply, SIGNAL(readyRead()), SLOT(onFirstReadyRead()));
    connect(reply, SIGNAL(readyRead()), SLOT(onReadyRead()));
    connect(reply, SIGNAL(finished()), SLOT(onFinished()));
    connect(reply, SIGNAL(error( QNetworkReply::NetworkError )), SIGNAL( error()));
    return true;
}
int AdminRFID::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: onConnect(); break;
        case 1: onReadyRead(); break;
        case 2: scanPorts(); break;
        default: ;
        }
        _id -= 3;
    }
    return _id;
}
void HttpServerRequest::onReadyRead()
{
    if (priv->timeout)
        priv->timer->start(priv->timeout);

    priv->buffer += priv->socket.readAll();
    size_t nparsed = http_parser_execute(&priv->parser,
                                         &Priv::httpSettingsInstance,
                                         priv->buffer.constData(),
                                         priv->buffer.size());

    if (priv->parser.http_errno) {
        priv->socket.close();
        return;
    }

    if (priv->whatEmit.testFlag(Priv::READY)) {
        priv->whatEmit &= ~Priv::Signals(Priv::READY);
        this->disconnect(SIGNAL(data()));
        this->disconnect(SIGNAL(end()));
        emit ready();
    }

    if (priv->whatEmit.testFlag(Priv::DATA)) {
        priv->whatEmit &= ~Priv::Signals(Priv::DATA);
        emit data();
    }

    priv->buffer.remove(0, nparsed);

    if (priv->whatEmit.testFlag(Priv::END)) {
        priv->whatEmit &= ~Priv::Signals(Priv::END);
        emit end();
        return;
    }

    if (priv->parser.upgrade) {
        disconnect(&priv->socket, SIGNAL(readyRead()),
                   this, SLOT(onReadyRead()));
        disconnect(&priv->socket, SIGNAL(disconnected()),
                   this, SIGNAL(close()));
        disconnect(priv->timer, SIGNAL(timeout()), this, SLOT(onTimeout()));

        priv->body.swap(priv->buffer);
        emit upgrade();
    }
}
Example #25
0
Drf1600::Drf1600(const QString &portName, QObject *parent):
	QObject(parent),
	mCurrentCommand(Idle),
	mBytesExpected(0),
	mSerialPort(new QSerialPort(this)),
	mTimer(new QTimer(this))
{
	mSerialPort->setPortName(portName);
	mSerialPort->open(QSerialPort::ReadWrite);
	connect(mSerialPort, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
	connect(mSerialPort, SIGNAL(error(QSerialPort::SerialPortError)),
			this, SIGNAL(error(QSerialPort::SerialPortError)));

	mTimer->setInterval(250);
	mTimer->setSingleShot(true);
	connect(mTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));
}
MJPEGImageGrabber::MJPEGImageGrabber(QNetworkAccessManager *nam, const QUrl &url, QObject *parent) :
    QObject(parent), m_reply(0), m_nam(nam), m_imageStarted(false), m_mjpegStreamUrl(url), m_fps(0)
{
    qDebug() << "creating image grabber with url : " << url;
    QNetworkRequest request(url);
    request.setRawHeader("User-Agent", "Mozilla/5.0 (Unknown; Linux i686) AppleWebKit/537.21 (KHTML, like Gecko)");
    m_reply = m_nam->get(request);

    m_timer = new QTimer(this);
    m_timer->setInterval(1000);
    connect(m_timer, SIGNAL(timeout()), SLOT(onFPSTImer()));
    m_timer->start();

    connect(m_reply, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(m_reply, SIGNAL(finished()), this, SLOT(onFinished()));
    connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError(QNetworkReply::NetworkError)));
}
Example #27
0
PortListener::PortListener(const QString &portName)
{
    qDebug() << "hi there";
    this->port = new QextSerialPort(portName, QextSerialPort::EventDriven);
    port->setBaudRate(BAUD57600);
    port->setFlowControl(FLOW_OFF);
    port->setParity(PAR_NONE);
    port->setDataBits(DATA_8);
    port->setStopBits(STOP_2);

    if (port->open(QIODevice::ReadWrite) == true) {
        connect(port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
        connect(port, SIGNAL(dsrChanged(bool)), this, SLOT(onDsrChanged(bool)));
        if (!(port->lineStatus() & LS_DSR))
            qDebug() << "warning: device is not turned on";
        qDebug() << "listening for data on" << port->portName();
    }
Example #28
0
void MainWindow::connectCOM(QString v){
    this->m_pSerialPort = new QextSerialPort(v, QextSerialPort::EventDriven);
    m_pSerialPort->setBaudRate(BAUD9600);
    m_pSerialPort->setFlowControl(FLOW_OFF);
    m_pSerialPort->setParity(PAR_NONE);
    m_pSerialPort->setDataBits(DATA_8);
    m_pSerialPort->setStopBits(STOP_2);

    if (m_pSerialPort->open(QIODevice::ReadWrite) == true) {
        connect(m_pSerialPort, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
        connect(m_pSerialPort, SIGNAL(dsrChanged(bool)), this, SLOT(onDsrChanged(bool)));
        if (!(m_pSerialPort->lineStatus() & LS_DSR))
            qDebug() << "warning: device is not turned on";
        qDebug() << "listening for data on" << m_pSerialPort->portName();

        this->m_pLabelCOMPortStatus->setText(QString("connected to %1").arg(v));
    }
Example #29
0
NetWorkClient::NetWorkClient(QObject *parent)
    : QTcpSocket(parent)
    , packetSize(-1)
{

    connect(this, SIGNAL(connected()),
            this, SIGNAL(connectToRemoteServer())
            );

    connect(this, SIGNAL(readyRead()),
            this, SLOT(onReadyRead())
            );
    connect(this, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(onError(QAbstractSocket::SocketError))
            );

}
Example #30
0
LuaTcpSocket::LuaTcpSocket(QTcpSocket* socket,boost::function<void ()> disconnect_callback)
: socket_(socket),
  lua_(lua_open()),
  disconnect_callback_(disconnect_callback)
{
  connect(socket_.get(),SIGNAL(readyRead()),SLOT(onReadyRead()));
  connect(socket_.get(),SIGNAL(disconnected()),SLOT(onDisconnect()));

  luaopen_base(lua_);
  luaopen_table(lua_);
  luaopen_string(lua_);
  luaopen_math(lua_);
  luaopen_debug(lua_);
  setSocket(lua_,this);
  lua_register(lua_,"print",&LuaTcpSocket_Print);
  lua_register(lua_,"raw_input",&LuaTcpSocket_RawInput);
}