~ubuntu-branches/ubuntu/trusty/qtcreator-plugin-ubuntu/trusty

« back to all changes in this revision

Viewing changes to src/ubuntu/ubuntuemulatornotifier.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Benjamin Zeller
  • Date: 2014-04-10 16:54:54 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20140410165454-j9syoh0jx6azy7g1
Tags: 3.0.1+14.04.20140410.1-0ubuntu1
[ Benjamin Zeller ]
Added Toolchains and Kit support to automatically.   detect a
available click chroot Added Devicesupport, connected Ubuntu devices
are.   automatically registered in QtCreator and can be set   for
different kits Added Deploysupport(CMake), the projects contents are
uploaded.   automatically using SSH after running make install on a
local   directory Added Run and Debugsupport: the command that
should be run.   on the device is read from the desktop file in the
deployed   directory. This means C+and QML debugging work as well
as QML Profiling Dynamically forward ports, depending on adb
forward --list.   output. Adb Server is not restarted by default
anymore, only a press.   on the refresh button will trigger the
restart. That will fix   problems with failing adb scripts Added
local run support for Ubuntu projects .

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation; version 2.1.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Author: Benjamin Zeller <benjamin.zeller@canonical.com>
 
17
 */
 
18
#include "ubuntuemulatornotifier.h"
 
19
 
 
20
#include <QTimer>
 
21
#include <QRegularExpression>
 
22
 
 
23
namespace Ubuntu {
 
24
namespace Internal {
 
25
 
 
26
/*!
 
27
 * \class UbuntuEmulatorNotifier
 
28
 * Polls adb if a specific
 
29
 */
 
30
 
 
31
UbuntuEmulatorNotifier::UbuntuEmulatorNotifier(QObject *parent) :
 
32
    IUbuntuDeviceNotifier(parent)
 
33
{
 
34
    m_pollTimout  = new QTimer(this);
 
35
    m_pollProcess = new QProcess(this);
 
36
 
 
37
    connect(m_pollTimout,SIGNAL(timeout()),this,SLOT(pollTimeout()));
 
38
    connect(m_pollProcess,SIGNAL(readyRead()),this,SLOT(pollProcessReadyRead()));
 
39
    connect(m_pollProcess,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(pollProcessFinished(int,QProcess::ExitStatus)));
 
40
}
 
41
 
 
42
void UbuntuEmulatorNotifier::startMonitoring(const QString &serialNumber)
 
43
{
 
44
    m_serial = serialNumber;
 
45
    m_pollTimout->setInterval(5000);
 
46
    m_pollTimout->start();
 
47
}
 
48
 
 
49
void UbuntuEmulatorNotifier::stopMonitoring()
 
50
{
 
51
    m_pollTimout->stop();
 
52
    m_pollProcess->kill();
 
53
}
 
54
 
 
55
bool UbuntuEmulatorNotifier::isConnected() const
 
56
{
 
57
    return (m_lastState == QLatin1String("device"));
 
58
}
 
59
 
 
60
void UbuntuEmulatorNotifier::pollTimeout()
 
61
{
 
62
    m_buffer.clear();
 
63
    m_pollProcess->start(QLatin1String("adb"),
 
64
                         QStringList()
 
65
                             <<QLatin1String("-s")
 
66
                             <<m_serial
 
67
                             <<QLatin1String("get-state"));
 
68
}
 
69
 
 
70
void UbuntuEmulatorNotifier::pollProcessReadyRead()
 
71
{
 
72
    m_buffer.append(m_pollProcess->readAllStandardOutput());
 
73
}
 
74
 
 
75
void UbuntuEmulatorNotifier::pollProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
 
76
{
 
77
    if (exitCode == 0 && exitStatus == QProcess::NormalExit) {
 
78
        QString str = QString::fromLocal8Bit(m_buffer.data());
 
79
 
 
80
        QRegularExpression expr(QLatin1String("(device|unknown|offline|bootloader)"));
 
81
        QRegularExpressionMatch match = expr.match(str);
 
82
        if(match.hasMatch()) {
 
83
            bool wasConnected = isConnected();
 
84
            QString newState = match.captured(1);
 
85
            if(newState != m_lastState) {
 
86
                m_lastState = newState;
 
87
                if(isConnected() && !wasConnected)
 
88
                    emit deviceConnected();
 
89
                else if(!isConnected() && wasConnected)
 
90
                    emit deviceDisconnected();
 
91
            }
 
92
        }
 
93
 
 
94
    }
 
95
}
 
96
 
 
97
} // namespace Internal
 
98
} // namespace Ubuntu