|
@@ -4,7 +4,7 @@
|
|
|
bool CSATDevices::s_bEnableAndroid = true;
|
|
|
ULONGLONG CSATDevices::s_ulEraseDuration = 30000;
|
|
|
ThreadSection CSATDevices::s_ThreadSection;
|
|
|
-std::vector<STAndroid> CSATDevices::s_vtAndroids;
|
|
|
+std::vector<STDevice> CSATDevices::s_vtDevices;
|
|
|
|
|
|
void Split(vector<std::string>& vtLine, std::string strLines, const std::string strSplit)
|
|
|
{
|
|
@@ -123,24 +123,24 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
|
|
|
continue;
|
|
|
|
|
|
// 刷新当前设备列表;
|
|
|
- std::vector<STAndroid> vtAndroids;
|
|
|
+ std::vector<STDevice> vtDevices;
|
|
|
printf("GetCurrentDevices\n");
|
|
|
// 获取当前设备列表;
|
|
|
- GetCurrentDevices(vtAndroids);
|
|
|
+ GetCurrentDevices(vtDevices);
|
|
|
|
|
|
// 遍历设备列表是否有下线设备;
|
|
|
- std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
|
|
|
- for ( ;it != s_vtAndroids.end(); ) {
|
|
|
+ std::vector<STDevice>::iterator it = s_vtDevices.begin();
|
|
|
+ for ( ;it != s_vtDevices.end(); ) {
|
|
|
if ( it->nType == Virtual ) {
|
|
|
it++;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if ( IsAndroidOffline(*it, vtAndroids) ) {
|
|
|
+ if ( IsAndroidOffline(*it, vtDevices) ) {
|
|
|
printf("IsAndroidOffline\n");
|
|
|
if ( GetTickCount64() - it->ulOfflineTime > s_ulEraseDuration ) {
|
|
|
// 移除设备(需要线程加锁);
|
|
|
- it = s_vtAndroids.erase(it);
|
|
|
+ it = s_vtDevices.erase(it);
|
|
|
} else {
|
|
|
if ( it->nType == Reticle ) {
|
|
|
// 设备下线,尝试重新连接;
|
|
@@ -168,34 +168,34 @@ DWORD CSATDevices::WorkThread(LPVOID lpVoid)
|
|
|
|
|
|
void CSATDevices::AddReticleDevices(std::string ip)
|
|
|
{
|
|
|
- STAndroid stAndroid;
|
|
|
- stAndroid.nType = Reticle;
|
|
|
- stAndroid.strName = ip;
|
|
|
- stAndroid.ulOfflineTime = 0;
|
|
|
+ STDevice stDevice;
|
|
|
+ stDevice.nType = Reticle;
|
|
|
+ stDevice.strName = ip;
|
|
|
+ stDevice.ulOfflineTime = 0;
|
|
|
|
|
|
AutoThreadSection ats(&s_ThreadSection);
|
|
|
- if (!IsDeviceExist(stAndroid))
|
|
|
- s_vtAndroids.push_back(stAndroid);
|
|
|
+ if (!IsDeviceExist(stDevice))
|
|
|
+ s_vtDevices.push_back(stDevice);
|
|
|
}
|
|
|
|
|
|
void CSATDevices::AddVirtualDevices(std::string name)
|
|
|
{
|
|
|
- STAndroid stAndroid;
|
|
|
- stAndroid.nType = Virtual;
|
|
|
- stAndroid.strName = name;
|
|
|
- stAndroid.ulOfflineTime = 0;
|
|
|
+ STDevice stDevice;
|
|
|
+ stDevice.nType = Virtual;
|
|
|
+ stDevice.strName = name;
|
|
|
+ stDevice.ulOfflineTime = 0;
|
|
|
|
|
|
AutoThreadSection ats(&s_ThreadSection);
|
|
|
- if (!IsDeviceExist(stAndroid))
|
|
|
- s_vtAndroids.push_back(stAndroid);
|
|
|
+ if (!IsDeviceExist(stDevice))
|
|
|
+ s_vtDevices.push_back(stDevice);
|
|
|
}
|
|
|
|
|
|
-bool CSATDevices::IsDeviceExist(STAndroid &stAndroid)
|
|
|
+bool CSATDevices::IsDeviceExist(STDevice &stDevice)
|
|
|
{
|
|
|
bool bExist = false;
|
|
|
- std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
|
|
|
- for(; it != s_vtAndroids.end(); it++ ) {
|
|
|
- if ( _tcscmp(it->strName.c_str(), stAndroid.strName.c_str()) == 0 ) {
|
|
|
+ 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 ) {
|
|
|
bExist = true;
|
|
|
break;
|
|
|
}
|
|
@@ -204,40 +204,40 @@ bool CSATDevices::IsDeviceExist(STAndroid &stAndroid)
|
|
|
return bExist;
|
|
|
}
|
|
|
|
|
|
-bool CSATDevices::IsAndroidOffline(STAndroid &stAndroid, std::vector<STAndroid> &vtAndroids )
|
|
|
+bool CSATDevices::IsAndroidOffline(STDevice &stDevice, std::vector<STDevice> &vtDevices )
|
|
|
{
|
|
|
bool bOffline = true;
|
|
|
// 在当前设备列表查询;
|
|
|
- std::vector<STAndroid>::iterator it = vtAndroids.begin();
|
|
|
- for(; it != vtAndroids.end(); it++ ) {
|
|
|
- if ( _tcscmp(it->strName.c_str(), stAndroid.strName.c_str()) == 0 ) {
|
|
|
+ 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;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if ( bOffline ) {
|
|
|
- if ( stAndroid.ulOfflineTime == 0 ) {
|
|
|
+ if ( stDevice.ulOfflineTime == 0 ) {
|
|
|
// 首次检测到离线;
|
|
|
- stAndroid.ulOfflineTime = GetTickCount64();
|
|
|
+ stDevice.ulOfflineTime = GetTickCount64();
|
|
|
}
|
|
|
} else {
|
|
|
// 若重新连接,重置离线时间;
|
|
|
- if ( stAndroid.ulOfflineTime ) {
|
|
|
- stAndroid.ulOfflineTime = 0;
|
|
|
+ if ( stDevice.ulOfflineTime ) {
|
|
|
+ stDevice.ulOfflineTime = 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return bOffline;
|
|
|
}
|
|
|
|
|
|
-bool CSATDevices::IsAndroidOffline(std::string strAndroidName, std::vector<STAndroid> &vtAndroids )
|
|
|
+bool CSATDevices::IsAndroidOffline(std::string strDeviceName, std::vector<STDevice> &vtDevices )
|
|
|
{
|
|
|
bool bOffline = true;
|
|
|
// 在当前设备列表查询;
|
|
|
- std::vector<STAndroid>::iterator it = vtAndroids.begin();
|
|
|
- for(; it != vtAndroids.end(); it++ ) {
|
|
|
- if ( _tcscmp(it->strName.c_str(), strAndroidName.c_str()) == 0 ) {
|
|
|
+ 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;
|
|
|
}
|
|
@@ -258,12 +258,12 @@ bool CSATDevices::IsAndroidOffline(std::string strAndroidName, std::vector<STAnd
|
|
|
return bOffline;
|
|
|
}
|
|
|
|
|
|
-bool CSATDevices::IsNewAndroid(STAndroid &stAndroid)
|
|
|
+bool CSATDevices::IsNewAndroid(STDevice &stDevice)
|
|
|
{
|
|
|
bool bNewAndroid = true;
|
|
|
- std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
|
|
|
- for(; it != s_vtAndroids.end(); it++ ) {
|
|
|
- if ( _tcscmp(it->strName.c_str(), stAndroid.strName.c_str()) == 0 ) {
|
|
|
+ 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;
|
|
|
}
|
|
@@ -272,23 +272,23 @@ bool CSATDevices::IsNewAndroid(STAndroid &stAndroid)
|
|
|
// 如果是新设备(一般是usb连接)
|
|
|
if ( bNewAndroid ) {
|
|
|
AutoThreadSection ats(&s_ThreadSection);
|
|
|
- s_vtAndroids.push_back(stAndroid);
|
|
|
+ s_vtDevices.push_back(stDevice);
|
|
|
}
|
|
|
|
|
|
return bNewAndroid;
|
|
|
}
|
|
|
|
|
|
-bool CSATDevices::IsNewUsbAndroid(STAndroid &stAndroid)
|
|
|
+bool CSATDevices::IsNewUsbAndroid(STDevice &stDevice)
|
|
|
{
|
|
|
- if ( stAndroid.nType != Usb )
|
|
|
+ if ( stDevice.nType != Usb )
|
|
|
return false;
|
|
|
|
|
|
bool bNewAndroid = true;
|
|
|
- std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
|
|
|
- for(; it != s_vtAndroids.end(); it++ ) {
|
|
|
+ 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(), stAndroid.strName.c_str()) == 0 ) {
|
|
|
+ if ( _tcscmp(it->strName.c_str(), stDevice.strName.c_str()) == 0 ) {
|
|
|
bNewAndroid = false;
|
|
|
break;
|
|
|
}
|
|
@@ -297,13 +297,13 @@ bool CSATDevices::IsNewUsbAndroid(STAndroid &stAndroid)
|
|
|
// 如果是新设备(一般是usb连接)
|
|
|
if ( bNewAndroid ) {
|
|
|
AutoThreadSection ats(&s_ThreadSection);
|
|
|
- s_vtAndroids.push_back(stAndroid);
|
|
|
+ s_vtDevices.push_back(stDevice);
|
|
|
}
|
|
|
|
|
|
return bNewAndroid;
|
|
|
}
|
|
|
|
|
|
-void CSATDevices::GetCurrentDevices(std::vector<STAndroid> &vtAndroids)
|
|
|
+void CSATDevices::GetCurrentDevices(std::vector<STDevice> &vtDevices)
|
|
|
{
|
|
|
std::string strLines = ExecuteCMD("adb devices");
|
|
|
std::vector<std::string> vtLine;
|
|
@@ -313,16 +313,16 @@ void CSATDevices::GetCurrentDevices(std::vector<STAndroid> &vtAndroids)
|
|
|
for ( std::vector<std::string>::iterator it = vtLine.begin(); it != vtLine.end(); it++ ) {
|
|
|
// 只获取在线设备,离线设备过滤;
|
|
|
if ( (npos = it->find(" device")) != std::string::npos ) {
|
|
|
- STAndroid stAndroid;
|
|
|
+ STDevice stDevice;
|
|
|
if ( it->find(":5555") == std::string::npos )
|
|
|
- stAndroid.nType = Usb;
|
|
|
+ stDevice.nType = Usb;
|
|
|
else
|
|
|
- stAndroid.nType = Reticle;
|
|
|
- stAndroid.ulOfflineTime = 0;
|
|
|
- stAndroid.strName = it->substr(0, npos);
|
|
|
+ stDevice.nType = Reticle;
|
|
|
+ stDevice.ulOfflineTime = 0;
|
|
|
+ stDevice.strName = it->substr(0, npos);
|
|
|
// 新设备否(一般用于usb设备)
|
|
|
- IsNewAndroid(stAndroid);
|
|
|
- vtAndroids.push_back(stAndroid);
|
|
|
+ IsNewAndroid(stDevice);
|
|
|
+ vtDevices.push_back(stDevice);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -330,8 +330,8 @@ void CSATDevices::GetCurrentDevices(std::vector<STAndroid> &vtAndroids)
|
|
|
void CSATDevices::ReConnectAllDevices()
|
|
|
{
|
|
|
std::string str;
|
|
|
- std::vector<STAndroid>::iterator it = s_vtAndroids.begin();
|
|
|
- for ( ;it != s_vtAndroids.end(); it++ ) {
|
|
|
+ std::vector<STDevice>::iterator it = s_vtDevices.begin();
|
|
|
+ for ( ;it != s_vtDevices.end(); it++ ) {
|
|
|
if ( it->nType == Reticle ) {
|
|
|
str = "adb connect ";
|
|
|
str.append(it->strName);
|