Add an abstracted interface around android-specific handling

* This makes it easier to use the same kind of interface to manage other kinds
  of devices.
This commit is contained in:
baldurk
2019-07-29 16:54:36 +01:00
parent 06f2e61b8f
commit e2704fa2eb
34 changed files with 2340 additions and 1492 deletions
+35 -18
View File
@@ -259,15 +259,8 @@ void PersistantConfig::RemoveRemoteHost(RemoteHost host)
}
}
void PersistantConfig::AddAndroidHosts()
void PersistantConfig::UpdateEnumeratedProtocolDevices()
{
QMutexLocker autolock(&RemoteHostLock);
QMap<rdcstr, RemoteHost> oldHosts;
for(int i = RemoteHostList.count() - 1; i >= 0; i--)
if(RemoteHostList[i].IsADB())
oldHosts[RemoteHostList[i].Hostname()] = RemoteHostList.takeAt(i);
QString androidSDKPath = (!Android_SDKPath.isEmpty() && QFile::exists(Android_SDKPath))
? QString(Android_SDKPath)
: QString();
@@ -282,19 +275,39 @@ void PersistantConfig::AddAndroidHosts()
SetConfigSetting("MaxConnectTimeout", QString::number(Android_MaxConnectTimeout));
rdcstr androidHosts;
RENDERDOC_EnumerateAndroidDevices(androidHosts);
for(const QString &hostName :
QString(androidHosts).split(QLatin1Char(','), QString::SkipEmptyParts))
rdcarray<RemoteHost> enumeratedDevices;
rdcarray<rdcstr> protocols;
RENDERDOC_GetSupportedDeviceProtocols(&protocols);
for(const rdcstr &p : protocols)
{
RemoteHost host((rdcstr)hostName);
IDeviceProtocolController *protocol = RENDERDOC_GetDeviceProtocolController(p);
if(oldHosts.contains(hostName))
host = oldHosts.take(hostName);
rdcarray<rdcstr> devices = protocol->GetDevices();
rdcstr friendly;
RENDERDOC_GetAndroidFriendlyName(hostName.toUtf8().data(), friendly);
host.SetFriendlyName(friendly);
for(const rdcstr &d : devices)
{
RemoteHost newhost(protocol->GetProtocolName() + "://" + d);
enumeratedDevices.push_back(newhost);
}
}
QMutexLocker autolock(&RemoteHostLock);
QMap<rdcstr, RemoteHost> oldHosts;
for(int i = RemoteHostList.count() - 1; i >= 0; i--)
if(RemoteHostList[i].Protocol())
oldHosts[RemoteHostList[i].Hostname()] = RemoteHostList.takeAt(i);
for(RemoteHost host : enumeratedDevices)
{
// if we already had this host, use that one.
if(oldHosts.contains(host.Hostname()))
host = oldHosts.take(host.Hostname());
host.SetFriendlyName(host.Protocol()->GetFriendlyName(host.Hostname()));
// Just a command to display in the GUI and allow Launch() to be called.
host.SetRunCommand("Automatically handled");
RemoteHostList.push_back(host);
@@ -363,6 +376,10 @@ bool PersistantConfig::Load(const rdcstr &filename)
if(!host.IsValid())
continue;
// backwards compatibility - skip old adb hosts that were adb:
if(host.Hostname().find("adb:") > 0 && host.Protocol() == NULL)
continue;
RemoteHostList.push_back(host);
if(host.IsLocalhost())
+2 -2
View File
@@ -791,8 +791,8 @@ R)");
:param RemoteHost host: The remote host to remove.
R)");
void RemoveRemoteHost(RemoteHost host);
DOCUMENT("If configured, queries ``adb`` to add android hosts to :data:`RemoteHosts`.");
void AddAndroidHosts();
DOCUMENT("If configured, queries available device protocols to update auto-configured hosts.");
void UpdateEnumeratedProtocolDevices();
DOCUMENT("");
CONFIG_SETTINGS()
+10 -7
View File
@@ -60,6 +60,8 @@ RemoteHost::RemoteHost(const QVariant &var)
m_data->m_runCommand = map[lit("runCommand")].toString();
if(map.contains(lit("lastCapturePath")))
m_data->m_lastCapturePath = map[lit("lastCapturePath")].toString();
m_protocol = RENDERDOC_GetDeviceProtocolController(m_hostname);
}
RemoteHost::RemoteHost()
@@ -72,6 +74,8 @@ RemoteHost::RemoteHost(const rdcstr &host)
// create a new host
m_hostname = host;
m_data = new RemoteHostData();
m_protocol = RENDERDOC_GetDeviceProtocolController(m_hostname);
}
RemoteHost::RemoteHost(const RemoteHost &o)
@@ -82,6 +86,7 @@ RemoteHost::RemoteHost(const RemoteHost &o)
RemoteHost &RemoteHost::operator=(const RemoteHost &o)
{
m_hostname = o.m_hostname;
m_protocol = o.m_protocol;
// deref old data
if(m_data)
@@ -123,7 +128,7 @@ void RemoteHost::CheckStatus()
// to avoid doing complex work while holding the remote host lock, we check the status here then
// call into the internal function that will propagate that data to the proper storage if needed.
IRemoteServer *rend = NULL;
ReplayStatus status = RENDERDOC_CreateRemoteServerConnection(m_hostname.c_str(), 0, &rend);
ReplayStatus status = RENDERDOC_CreateRemoteServerConnection(m_hostname.c_str(), &rend);
if(rend)
rend->ShutdownConnection();
@@ -187,12 +192,10 @@ ReplayStatus RemoteHost::Launch()
{
ReplayStatus status = ReplayStatus::Succeeded;
int WAIT_TIME = 2000;
if(IsADB())
if(m_protocol)
{
status = RENDERDOC_StartAndroidRemoteServer(m_hostname.c_str());
QThread::msleep(WAIT_TIME);
// this is blocking
status = m_protocol->StartRemoteServer(m_hostname);
return status;
}
@@ -205,7 +208,7 @@ ReplayStatus RemoteHost::Launch()
RDProcess process;
process.start(run);
process.waitForFinished(WAIT_TIME);
process.waitForFinished(2000);
process.detach();
return status;
+5 -6
View File
@@ -93,6 +93,9 @@ public:
)");
void SetLastCapturePath(const rdcstr &path);
DOCUMENT(
"The :class:`DeviceProtocolController` for this host, or ``None`` if no protocol is in use");
IDeviceProtocolController *Protocol() const { return m_protocol; }
DOCUMENT(R"(
Returns the name to display for this host in the UI, either :meth:`FriendlyName` if it is valid, or
:meth:`Hostname` if not.
@@ -102,12 +105,6 @@ Returns the name to display for this host in the UI, either :meth:`FriendlyName`
rdcstr friendlyName = FriendlyName();
return !friendlyName.isEmpty() ? friendlyName : m_hostname;
}
DOCUMENT("Returns ``True`` if this host represents a connected ADB (Android) device.");
bool IsADB() const
{
return m_hostname.count() > 4 && m_hostname[0] == 'a' && m_hostname[1] == 'd' &&
m_hostname[2] == 'b' && m_hostname[3] == ':';
}
DOCUMENT("Returns ``True`` if this host represents the special localhost device.");
bool IsLocalhost() const { return m_hostname == "localhost"; }
DOCUMENT("Returns ``True`` if this host represents a valid remote host.");
@@ -117,6 +114,8 @@ private:
// are created with it
rdcstr m_hostname;
IDeviceProtocolController *m_protocol = NULL;
// self-deleting shared and locked data store
RemoteHostData *m_data = NULL;