Ejemplo n.º 1
0
/*!
  Connect to the configured port and host for the device and setting up
  the socket.
*/
void DeviceConnector::connect()
{
    if ( mSocket )  // already connected
        return;
    emit startingConnect();
    loginDone = false;
    mSocket = new QTcpSocket();
    QObject::connect( mSocket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(socketError()) );
    mSocket->connectToHost( QHostAddress( "10.10.10.20" ), 4245 );
    if ( !mSocket->waitForConnected() )
    {
        emit deviceConnMessage( tr( "Error connecting to device:" ) +
                mSocket->errorString() );
        delete mSocket;
        mSocket = 0;
        return;
    }
    QObject::connect( mSocket, SIGNAL(readyRead()),
            this, SLOT(socketReadyRead()) );
    QObject::connect( mSocket, SIGNAL(disconnected()),
            this, SLOT(socketDisconnected()) );
    emit deviceConnMessage( tr( "Device connected" ) );
    emit finishedConnect();
}
Ejemplo n.º 2
0
/*!
  Respond to an error signal from the socket, by
  deleting and setting the socket instance to zero, to indicate a
  new call to connect() is required.
*/
void DeviceConnector::socketError()
{
    if ( mSocket == 0 )
        return;
    QString err = mSocket->errorString();
    emit deviceConnMessage( tr( "Device connection problem:" ) + err );
    qDebug() << "socketError()" << err;
    teardown();
}
Ejemplo n.º 3
0
/*!
  Construct a new \c PackageScanner object, which will scan the \a dir
  directory, when the refresh() call is made.
*/
PackageScanner::PackageScanner( const QString &dir, QObject *parent )
    : QAbstractListModel( parent )
    , mDir( dir )
    , mScanner( 0 )
    , mConnector( 0 )
{
    refresh();
    mConnector = new DeviceConnector();
    QObject::connect( mConnector, SIGNAL(finishedConnect()),
            this, SLOT(connectorComplete()) );
    QObject::connect( mConnector, SIGNAL(deviceConnMessage(QString)),
            this, SIGNAL(progressMessage(QString)) );
    QObject::connect( mConnector, SIGNAL(sendProgress(int)),
            this, SIGNAL(progressValue(int)) );
}
Ejemplo n.º 4
0
void DeviceConnector::processMessages()
{
    if ( messageQueue.isEmpty() )
        return;
    MessageRecord *msg = messageQueue.first();
    switch ( msg->state )
    {
        case NoMessage:
            connect();
            if ( !mSocket )
            {
                qDebug() << "No socket, retrying...";
                QTimer::singleShot( 500, this, SLOT(processMessages()) );
                return;
            }
            if ( loginDone )
                msg->state = Message;
            else
                msg->state = WaitForWelcome;
            QTimer::singleShot( 0, this, SLOT(processMessages()) );
            emit sendProgress( 10 );
            break;

        case WaitForWelcome:
            qDebug() << "wait for welcome";
            emit sendProgress( 20 );
            break;

        case User:
            // send user name
            // TODO this name comes in the 220 message!
            sendMessage( QString("USER %1").arg(loginName) );
            msg->state = WaitForUserOk;
            emit sendProgress( 30 );
            break;

        case WaitForUserOk:
            qDebug() << "wait for user ok";
            emit sendProgress( 40 );
            break;

        case Password:
            // send password
            sendMessage( "PASS Qtopia::deviceupdater" );
            msg->state = WaitForPasswordOk;
            emit sendProgress( 50 );
            break;

        case WaitForPasswordOk:
            qDebug() << "wait for user ok";
            emit sendProgress( 60 );
            break;

        case Message:
            // Now send the message
            emit sendProgress( 70 );
            {
                QTextStream os( mSocket );
                os << "CALLB " << msg->channel << " " << msg->message << " "
                   << msg->data.toBase64() << endl;
            }
            qDebug() << "send:" << msg->channel << "...";
            msg->state = WaitForMessageOk;
            break;

        case WaitForMessageOk:
            qDebug() << "wait for message ok";
            emit sendProgress( 80 );
            break;

        case MessageDelivered:
        case MessageFailed:
            emit sendProgress( 100 );
            if ( msg->state == MessageDelivered )
                emit deviceConnMessage( tr( "Device update message delivered" ));
            else
                emit deviceConnMessage( tr( "Device update message failed" ));
            if ( messageQueue.isEmpty() )
                teardown();
            Q_ASSERT( msg == messageQueue.first() );
            messageQueue.removeFirst();
            delete msg;
            break;

        default:
            qFatal( "Unknown state!" );
    }
}