|
@@ -111,7 +111,22 @@ void CSATDevices::StartWork()
|
|
|
|
|
|
void CSATDevices::EndofWork()
|
|
|
{
|
|
|
+ // 设置事件有信号;
|
|
|
+ if ( m_hEvent )
|
|
|
+ SetEvent(m_hEvent);
|
|
|
+
|
|
|
+ // 等待线程结束;
|
|
|
+ if ( m_hWorkThread ) {
|
|
|
+ WaitForSingleObject(m_hWorkThread, INFINITE);
|
|
|
+ CloseHandle(m_hWorkThread);
|
|
|
+ m_hWorkThread = NULL;
|
|
|
+ }
|
|
|
|
|
|
+ // 关闭事件句柄;
|
|
|
+ if ( m_hEvent ) {
|
|
|
+ CloseHandle(m_hEvent);
|
|
|
+ m_hEvent = NULL;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
DWORD CSATDevices::WorkThread(LPVOID lpVoid)
|
|
@@ -124,7 +139,9 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
|
|
|
|
|
|
// 刷新当前设备列表;
|
|
|
std::vector<STDevice> vtDevices;
|
|
|
+#ifdef _DEBUG
|
|
|
printf("GetCurrentDevices\n");
|
|
|
+#endif
|
|
|
// 获取当前设备列表;
|
|
|
GetCurrentDevices(vtDevices);
|
|
|
|
|
@@ -136,17 +153,26 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if ( IsAndroidOffline(*it, vtDevices) ) {
|
|
|
- printf("IsAndroidOffline\n");
|
|
|
+ if ( IsDevicesOffline(*it, vtDevices) ) {
|
|
|
+#ifdef _DEBUG
|
|
|
+ printf("IsDevicesOffline\n");
|
|
|
+#endif
|
|
|
if ( GetTickCount64() - it->ulOfflineTime > s_ulEraseDuration ) {
|
|
|
// 移除设备(需要线程加锁);
|
|
|
it = s_vtDevices.erase(it);
|
|
|
} else {
|
|
|
if ( it->nType == Reticle ) {
|
|
|
- // 设备下线,尝试重新连接;
|
|
|
- std::string str = "adb connect ";
|
|
|
- str.append(it->strName);
|
|
|
- WinExec(str.c_str(), SW_HIDE);
|
|
|
+ if ( it->nStatus == Offline ) {
|
|
|
+ // offline只能reconnect才能重连;
|
|
|
+ std::string str = "adb reconnect ";
|
|
|
+ str.append(it->strName);
|
|
|
+ WinExec(str.c_str(), SW_HIDE);
|
|
|
+ }
|
|
|
+ else if ( it->nStatus == Dropline ) {
|
|
|
+ std::string str = "adb connect ";
|
|
|
+ str.append(it->strName);
|
|
|
+ WinExec(str.c_str(), SW_HIDE);
|
|
|
+ }
|
|
|
} else if ( it->nType == Usb ) {
|
|
|
// 如果是usb的话,可能要kill-server,再全部重连接;
|
|
|
WinExec("adb kill-server", SW_HIDE);
|
|
@@ -192,7 +218,8 @@ void CSATDevices::AddReticleDevices(std::string ip)
|
|
|
stDevice.nType = Reticle;
|
|
|
stDevice.strName = ip;
|
|
|
stDevice.ulOfflineTime = 0;
|
|
|
- stDevice.nStatus = 0;
|
|
|
+ stDevice.nStatus = Online;
|
|
|
+ stDevice.nUsageState = Idle;
|
|
|
|
|
|
AutoThreadSection ats(&s_ThreadSection);
|
|
|
if (!IsDeviceExist(stDevice))
|
|
@@ -205,7 +232,8 @@ void CSATDevices::AddVirtualDevices(std::string name)
|
|
|
stDevice.nType = Virtual;
|
|
|
stDevice.strName = name;
|
|
|
stDevice.ulOfflineTime = 0;
|
|
|
- stDevice.nStatus = 0;
|
|
|
+ stDevice.nStatus = Online;
|
|
|
+ stDevice.nUsageState = Idle;
|
|
|
|
|
|
AutoThreadSection ats(&s_ThreadSection);
|
|
|
if (!IsDeviceExist(stDevice))
|
|
@@ -226,14 +254,18 @@ bool CSATDevices::IsDeviceExist(STDevice &stDevice)
|
|
|
return bExist;
|
|
|
}
|
|
|
|
|
|
-bool CSATDevices::IsAndroidOffline(STDevice &stDevice, std::vector<STDevice> &vtDevices )
|
|
|
+bool CSATDevices::IsDevicesOffline(STDevice &stDevice, std::vector<STDevice> &vtDevices )
|
|
|
{
|
|
|
bool bOffline = true;
|
|
|
// 在当前设备列表查询;
|
|
|
std::vector<STDevice>::iterator it = vtDevices.begin();
|
|
|
for(; it != vtDevices.end(); it++ ) {
|
|
|
if ( _tcscmp(it->strName.c_str(), stDevice.strName.c_str()) == 0 ) {
|
|
|
- bOffline = false;
|
|
|
+ // 同步状态;
|
|
|
+ stDevice.nStatus = it->nStatus;
|
|
|
+ // 设备是否offline或dropline;
|
|
|
+ if ( it->nStatus != Offline && it->nStatus != Dropline)
|
|
|
+ bOffline = false;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -241,11 +273,14 @@ bool CSATDevices::IsAndroidOffline(STDevice &stDevice, std::vector<STDevice> &vt
|
|
|
if ( bOffline ) {
|
|
|
if ( stDevice.ulOfflineTime == 0 ) {
|
|
|
// 首次检测到离线;
|
|
|
+ if ( stDevice.nStatus != Offline )
|
|
|
+ stDevice.nStatus = Dropline;
|
|
|
stDevice.ulOfflineTime = GetTickCount64();
|
|
|
}
|
|
|
} else {
|
|
|
// 若重新连接,重置离线时间;
|
|
|
if ( stDevice.ulOfflineTime ) {
|
|
|
+ stDevice.nStatus = Online;
|
|
|
stDevice.ulOfflineTime = 0;
|
|
|
}
|
|
|
}
|
|
@@ -253,76 +288,24 @@ bool CSATDevices::IsAndroidOffline(STDevice &stDevice, std::vector<STDevice> &vt
|
|
|
return bOffline;
|
|
|
}
|
|
|
|
|
|
-bool CSATDevices::IsAndroidOffline(std::string strDeviceName, std::vector<STDevice> &vtDevices )
|
|
|
-{
|
|
|
- bool bOffline = true;
|
|
|
- // 在当前设备列表查询;
|
|
|
- std::vector<STDevice>::iterator it = vtDevices.begin();
|
|
|
- for(; it != vtDevices.end(); it++ ) {
|
|
|
- if ( _tcscmp(it->strName.c_str(), strDeviceName.c_str()) == 0 ) {
|
|
|
- bOffline = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ( bOffline ) {
|
|
|
- if ( it->ulOfflineTime == 0 ) {
|
|
|
- // 首次检测到离线;
|
|
|
- it->ulOfflineTime = GetTickCount64();
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 若重新连接,重置离线时间;
|
|
|
- if ( it->ulOfflineTime ) {
|
|
|
- it->ulOfflineTime = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return bOffline;
|
|
|
-}
|
|
|
-
|
|
|
-bool CSATDevices::IsNewAndroid(STDevice &stDevice)
|
|
|
-{
|
|
|
- bool bNewAndroid = true;
|
|
|
- std::vector<STDevice>::iterator it = s_vtDevices.begin();
|
|
|
- for(; it != s_vtDevices.end(); it++ ) {
|
|
|
- if ( _tcscmp(it->strName.c_str(), stDevice.strName.c_str()) == 0 ) {
|
|
|
- bNewAndroid = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 如果是新设备(一般是usb连接)
|
|
|
- if ( bNewAndroid ) {
|
|
|
- AutoThreadSection ats(&s_ThreadSection);
|
|
|
- s_vtDevices.push_back(stDevice);
|
|
|
- }
|
|
|
-
|
|
|
- return bNewAndroid;
|
|
|
-}
|
|
|
-
|
|
|
-bool CSATDevices::IsNewUsbAndroid(STDevice &stDevice)
|
|
|
+bool CSATDevices::IsNewDevices(STDevice &stDevice)
|
|
|
{
|
|
|
- if ( stDevice.nType != Usb )
|
|
|
- return false;
|
|
|
-
|
|
|
- bool bNewAndroid = true;
|
|
|
+ bool bNewDevices = true;
|
|
|
std::vector<STDevice>::iterator it = s_vtDevices.begin();
|
|
|
for(; it != s_vtDevices.end(); it++ ) {
|
|
|
- if ( it->nType != Usb )
|
|
|
- continue;
|
|
|
if ( _tcscmp(it->strName.c_str(), stDevice.strName.c_str()) == 0 ) {
|
|
|
- bNewAndroid = false;
|
|
|
+ bNewDevices = false;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 如果是新设备(一般是usb连接)
|
|
|
- if ( bNewAndroid ) {
|
|
|
+ if ( bNewDevices ) {
|
|
|
AutoThreadSection ats(&s_ThreadSection);
|
|
|
s_vtDevices.push_back(stDevice);
|
|
|
}
|
|
|
|
|
|
- return bNewAndroid;
|
|
|
+ return bNewDevices;
|
|
|
}
|
|
|
|
|
|
void CSATDevices::GetCurrentDevices(std::vector<STDevice> &vtDevices)
|
|
@@ -331,21 +314,26 @@ void CSATDevices::GetCurrentDevices(std::vector<STDevice> &vtDevices)
|
|
|
std::vector<std::string> vtLine;
|
|
|
Split(vtLine, strLines, "\r\n");
|
|
|
int npos = -1;
|
|
|
- // 需要在此处过滤掉offline的usb设备,不要加入vt中;
|
|
|
+ // offline设备也要加入,不区分usb或reticle;
|
|
|
for ( std::vector<std::string>::iterator it = vtLine.begin(); it != vtLine.end(); it++ ) {
|
|
|
- // 只获取在线设备,离线设备过滤;
|
|
|
- if ( (npos = it->find(" device")) != std::string::npos ) {
|
|
|
- STDevice stDevice;
|
|
|
- if ( it->find(":5555") == std::string::npos )
|
|
|
- stDevice.nType = Usb;
|
|
|
- else
|
|
|
- stDevice.nType = Reticle;
|
|
|
- stDevice.ulOfflineTime = 0;
|
|
|
- stDevice.strName = it->substr(0, npos);
|
|
|
- // 新设备否(一般用于usb设备)
|
|
|
- IsNewAndroid(stDevice);
|
|
|
- vtDevices.push_back(stDevice);
|
|
|
- }
|
|
|
+ STDevice stDevice;
|
|
|
+ // 设备类型;
|
|
|
+ if ( it->find(":5555") == std::string::npos )
|
|
|
+ stDevice.nType = Usb;
|
|
|
+ else
|
|
|
+ stDevice.nType = Reticle;
|
|
|
+ stDevice.ulOfflineTime = 0;
|
|
|
+ // 设备状态;
|
|
|
+ if ( (npos = it->find(" device")) != std::string::npos )
|
|
|
+ stDevice.nStatus = Online;
|
|
|
+ else if ( (npos = it->find(" offline")) != std::string::npos )
|
|
|
+ stDevice.nStatus = Offline;
|
|
|
+ // 获取设备名;
|
|
|
+ stDevice.strName = it->substr(0, npos);
|
|
|
+ // 新设备否(一般用于usb设备)
|
|
|
+ IsNewDevices(stDevice);
|
|
|
+ // 压入容器保存;
|
|
|
+ vtDevices.push_back(stDevice);
|
|
|
}
|
|
|
}
|
|
|
|