Skip to content

Commit 57c62c1

Browse files
committed
* fix instrument to follow new flow
1 parent ae43eb0 commit 57c62c1

4 files changed

Lines changed: 74 additions & 59 deletions

File tree

Src/devicebridge.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ enum MobileOperation {
9595
INSTALL_APP,
9696
UNINSTALL_APP,
9797
SYSLOG,
98-
DEBUGGER
98+
DEBUGGER,
99+
SYSTEM_MONITOR,
100+
FPS_MONITOR,
101+
GET_PROCESS,
102+
GET_ATTRIBUTES
99103
};
100104

101105
class DeviceBridge : public QObject
@@ -276,10 +280,6 @@ class DeviceBridge : public QObject
276280
void GetProcessList();
277281
void StartFPS(unsigned int interval_ms);
278282
void StopFPS();
279-
private:
280-
DTXTransport* m_transport;
281-
DTXConnection* m_connection;
282-
std::shared_ptr<DTXChannel> m_sysmontapChannel, m_openglChannel;
283283
signals:
284284
};
285285

Src/devicebridge_instrument.cpp

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ using namespace idevice;
99

1010
QStringList DeviceBridge::GetAttributes(AttrType type)
1111
{
12+
MobileOperation op = MobileOperation::GET_ATTRIBUTES;
1213
QStringList list;
13-
if (!m_connection) {
14-
m_transport = new DTXTransport(m_device, false);
15-
m_connection = new DTXConnection(m_transport);
16-
m_connection->Connect();
17-
}
1814

19-
auto channel = m_connection->MakeChannelWithIdentifier("com.apple.instruments.server.services.deviceinfo");
15+
if (!CreateClient(op))
16+
return list;
17+
18+
m_clients[op]->transport = new DTXTransport(m_clients[op]->device, false);
19+
m_clients[op]->connection = new DTXConnection(m_clients[op]->transport);
20+
m_clients[op]->connection->Connect();
21+
22+
auto channel = m_clients[op]->connection->MakeChannelWithIdentifier("com.apple.instruments.server.services.deviceinfo");
2023
std::string selector = std::string("sysmon") + (type == AttrType::PROCESS ? "Process" : "System") + "Attributes";
2124
std::shared_ptr<DTXMessage> message = DTXMessage::CreateWithSelector(selector.c_str());
2225
auto response = channel->SendMessageSync(message);
@@ -26,16 +29,19 @@ QStringList DeviceBridge::GetAttributes(AttrType type)
2629
list.append(value.toString(""));
2730
}
2831
channel->Cancel();
32+
RemoveClient(op);
2933
return list;
3034
}
3135

3236
void DeviceBridge::StartMonitor(unsigned int interval_ms, QStringList system_attr, QStringList process_attr)
3337
{
34-
if (!m_connection) {
35-
m_transport = new DTXTransport(m_device, false);
36-
m_connection = new DTXConnection(m_transport);
37-
m_connection->Connect();
38-
}
38+
MobileOperation op = MobileOperation::SYSTEM_MONITOR;
39+
if (!CreateClient(op))
40+
return;
41+
42+
m_clients[op]->transport = new DTXTransport(m_clients[op]->device, false);
43+
m_clients[op]->connection = new DTXConnection(m_clients[op]->transport);
44+
m_clients[op]->connection->Connect();
3945

4046
nskeyedarchiver::KAArray proccessAttrs(nskeyedarchiver::KAArray("NSSet", {"NSSet", "NSObject"}));
4147
nskeyedarchiver::KAArray systemAttrs(nskeyedarchiver::KAArray("NSSet", {"NSSet", "NSObject"}));
@@ -46,7 +52,7 @@ void DeviceBridge::StartMonitor(unsigned int interval_ms, QStringList system_att
4652
foreach (const auto& value, system_attr)
4753
systemAttrs.push_back(nskeyedarchiver::KAValue(value.toUtf8().data()));
4854

49-
m_sysmontapChannel = m_connection->MakeChannelWithIdentifier("com.apple.instruments.server.services.sysmontap");
55+
m_clients[op]->channel = m_clients[op]->connection->MakeChannelWithIdentifier("com.apple.instruments.server.services.sysmontap");
5056
auto message = DTXMessage::CreateWithSelector("setConfig:");
5157
nskeyedarchiver::KAMap configs(nskeyedarchiver::KAMap("NSMutableDictionary", {"NSMutableDictionary", "NSDictionary", "NSObject"}));
5258
configs["ur"] = interval_ms;
@@ -56,82 +62,91 @@ void DeviceBridge::StartMonitor(unsigned int interval_ms, QStringList system_att
5662
configs["procAttrs"] = proccessAttrs;
5763
configs["sysAttrs"] = systemAttrs;
5864
message->AppendAuxiliary(nskeyedarchiver::KAValue(configs));
59-
auto response = m_sysmontapChannel->SendMessageSync(message);
65+
auto response = m_clients[op]->channel->SendMessageSync(message);
6066
response->Dump();
6167

62-
m_sysmontapChannel->SetMessageHandler([=](std::shared_ptr<DTXMessage> msg) {
68+
m_clients[op]->channel->SetMessageHandler([=](std::shared_ptr<DTXMessage> msg) {
6369
if (msg->PayloadObject()) {
6470
qDebug() << msg->PayloadObject()->ToJson().c_str();
6571
}
6672
});
6773

6874
message = DTXMessage::CreateWithSelector("start");
69-
response = m_sysmontapChannel->SendMessageSync(message);
75+
response = m_clients[op]->channel->SendMessageSync(message);
7076
response->Dump();
7177
}
7278

7379
void DeviceBridge::StopMonitor()
7480
{
75-
if (m_sysmontapChannel) {
81+
MobileOperation op = MobileOperation::SYSTEM_MONITOR;
82+
if (m_clients[op]->channel) {
7683
auto message = DTXMessage::CreateWithSelector("stop");
77-
m_sysmontapChannel->SendMessageSync(message);
78-
m_sysmontapChannel->Cancel();
84+
m_clients[op]->channel->SendMessageSync(message);
85+
m_clients[op]->channel->Cancel();
7986
}
87+
RemoveClient(op);
8088
}
8189

8290
void DeviceBridge::GetProcessList()
8391
{
84-
if (!m_connection) {
85-
m_transport = new DTXTransport(m_device, false);
86-
m_connection = new DTXConnection(m_transport);
87-
m_connection->Connect();
88-
}
92+
MobileOperation op = MobileOperation::GET_PROCESS;
93+
if (!CreateClient(op))
94+
return;
8995

90-
auto channel = m_connection->MakeChannelWithIdentifier("com.apple.instruments.server.services.deviceinfo");
96+
m_clients[op]->transport = new DTXTransport(m_clients[op]->device, false);
97+
m_clients[op]->connection = new DTXConnection(m_clients[op]->transport);
98+
m_clients[op]->connection->Connect();
99+
100+
m_clients[op]->channel = m_clients[op]->connection->MakeChannelWithIdentifier("com.apple.instruments.server.services.deviceinfo");
91101
std::shared_ptr<DTXMessage> message = DTXMessage::CreateWithSelector("runningProcesses");
92-
auto response = channel->SendMessageSync(message);
102+
auto response = m_clients[op]->channel->SendMessageSync(message);
93103
if (response->PayloadObject()) {
94104
qDebug() << response->PayloadObject()->ToJson().c_str();
95105
}
96-
channel->Cancel();
106+
m_clients[op]->channel->Cancel();
107+
RemoveClient(op);
97108
}
98109

99110
void DeviceBridge::StartFPS(unsigned int interval_ms)
100111
{
101-
if (!m_connection) {
102-
m_transport = new DTXTransport(m_device, false);
103-
m_connection = new DTXConnection(m_transport);
104-
m_connection->Connect();
105-
}
112+
MobileOperation op = MobileOperation::FPS_MONITOR;
113+
if (!CreateClient(op))
114+
return;
115+
116+
m_clients[op]->transport = new DTXTransport(m_clients[op]->device, false);
117+
m_clients[op]->connection = new DTXConnection(m_clients[op]->transport);
118+
m_clients[op]->connection->Connect();
106119

107-
m_openglChannel = m_connection->MakeChannelWithIdentifier("com.apple.instruments.server.services.graphics.opengl");
120+
m_clients[op]->channel = m_clients[op]->connection->MakeChannelWithIdentifier("com.apple.instruments.server.services.graphics.opengl");
108121
auto message = DTXMessage::CreateWithSelector("availableStatistics");
109-
m_openglChannel->SendMessageSync(message);
122+
m_clients[op]->channel->SendMessageSync(message);
110123

111124
message = DTXMessage::CreateWithSelector("driverNames");
112-
m_openglChannel->SendMessageSync(message);
125+
m_clients[op]->channel->SendMessageSync(message);
113126

114127
message = DTXMessage::CreateWithSelector("setSamplingRate:");
115128
message->AppendAuxiliary(nskeyedarchiver::KAValue((float)interval_ms / 100.f));
116-
m_openglChannel->SendMessageSync(message);
129+
m_clients[op]->channel->SendMessageSync(message);
117130

118-
m_openglChannel->SetMessageHandler([=](std::shared_ptr<DTXMessage> msg) {
131+
m_clients[op]->channel->SetMessageHandler([=](std::shared_ptr<DTXMessage> msg) {
119132
if (msg->PayloadObject()) {
120133
qDebug() << msg->PayloadObject()->ToJson().c_str();
121134
}
122135
});
123136

124137
message = DTXMessage::CreateWithSelector("startSamplingAtTimeInterval:");
125138
message->AppendAuxiliary(nskeyedarchiver::KAValue(0.0f));
126-
auto response = m_openglChannel->SendMessageSync(message);
139+
auto response = m_clients[op]->channel->SendMessageSync(message);
127140
response->Dump();
128141
}
129142

130143
void DeviceBridge::StopFPS()
131144
{
132-
if (m_openglChannel){
145+
MobileOperation op = MobileOperation::FPS_MONITOR;
146+
if (m_clients[op]->channel){
133147
auto message = DTXMessage::CreateWithSelector("stopSampling");
134-
m_openglChannel->SendMessageSync(message);
135-
m_openglChannel->Cancel();
148+
m_clients[op]->channel->SendMessageSync(message);
149+
m_clients[op]->channel->Cancel();
136150
}
151+
RemoveClient(op);
137152
}

Src/deviceclient.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ DeviceClient::DeviceClient()
66
, client(nullptr)
77
, lockdownd_error(LOCKDOWN_E_UNKNOWN_ERROR)
88
, device_error(IDEVICE_E_UNKNOWN_ERROR)
9-
, dtx_transport(nullptr)
10-
, dtx_connection(nullptr)
11-
, dtx_channel()
9+
, transport(nullptr)
10+
, connection(nullptr)
11+
, channel()
1212
, afc(nullptr)
1313
, house_arrest(nullptr)
1414
, installer(nullptr)
@@ -84,19 +84,19 @@ DeviceClient::DeviceClient(RemoteAddress address, QStringList service_ids, QStri
8484
DeviceClient::~DeviceClient()
8585
{
8686
// instruments
87-
if (dtx_channel)
87+
if (channel)
8888
{
89-
dtx_channel = nullptr;
89+
channel = nullptr;
9090
}
91-
if (dtx_connection)
91+
if (connection)
9292
{
93-
delete dtx_connection;
94-
dtx_connection = nullptr;
93+
delete connection;
94+
connection = nullptr;
9595
}
96-
if (dtx_transport)
96+
if (transport)
9797
{
98-
delete dtx_transport;
99-
dtx_transport = nullptr;
98+
delete transport;
99+
transport = nullptr;
100100
}
101101

102102
// services

Src/deviceclient.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class DeviceClient
3232
lockdownd_error_t lockdownd_error;
3333
idevice_error_t device_error;
3434

35-
DTXTransport* dtx_transport;
36-
DTXConnection* dtx_connection;
37-
std::unique_ptr<DTXChannel> dtx_channel;
35+
DTXTransport* transport;
36+
DTXConnection* connection;
37+
std::shared_ptr<DTXChannel> channel;
3838

3939
afc_client_t afc;
4040
house_arrest_client_t house_arrest;

0 commit comments

Comments
 (0)