增加以太网变化时检测网络是否断连

streaming
Matthew 4 months ago
parent b7f6631672
commit 31954a3f17

@ -318,7 +318,7 @@ Java_com_xypower_mpapp_MicroPhotoService_init(
CTerminal* pTerminal = NewTerminal(protocol); CTerminal* pTerminal = NewTerminal(protocol);
CPhoneDevice* device = new CPhoneDevice(vm, pThis, MakeString(appPathStr), NETID_UNSET, versionCode, MakeString(nativeLibraryDirStr)); CPhoneDevice* device = new CPhoneDevice(vm, pThis, MakeString(appPathStr), (uint64_t)netHandle, versionCode, MakeString(nativeLibraryDirStr));
device->SetListener(pTerminal); device->SetListener(pTerminal);
device->UpdateSignalLevel(signalLevel); device->UpdateSignalLevel(signalLevel);
device->SetBuildTime(buildTime / 1000); device->SetBuildTime(buildTime / 1000);
@ -1346,7 +1346,12 @@ Java_com_xypower_mpapp_MicroPhotoService_updateEhernet(
CPhoneDevice* device = (CPhoneDevice*)pTerminal->GetDevice(); CPhoneDevice* device = (CPhoneDevice*)pTerminal->GetDevice();
if (device != NULL) if (device != NULL)
{ {
device->UpdateNetwork(static_cast<net_handle_t>(networkHandle), available != JNI_FALSE, false); bool changed = false;
device->UpdateNetwork(static_cast<net_handle_t>(networkHandle), available != JNI_FALSE, false, changed);
if (changed)
{
pTerminal->ResetNetwork();
}
} }
return JNI_TRUE; return JNI_TRUE;
@ -1366,7 +1371,8 @@ Java_com_xypower_mpapp_MicroPhotoService_updateActiveNetwork(
CPhoneDevice* device = (CPhoneDevice*)pTerminal->GetDevice(); CPhoneDevice* device = (CPhoneDevice*)pTerminal->GetDevice();
if (device != NULL) if (device != NULL)
{ {
device->UpdateNetwork(static_cast<net_handle_t>(networkHandle), available != JNI_FALSE, true); bool changed = false;
device->UpdateNetwork(static_cast<net_handle_t>(networkHandle), available != JNI_FALSE, true, changed);
} }
return JNI_TRUE; return JNI_TRUE;

@ -478,8 +478,8 @@ int32_t CPhoneDevice::CJpegCamera::getOutputFormat() const
return AIMAGE_FORMAT_JPEG; return AIMAGE_FORMAT_JPEG;
} }
CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId, unsigned int versionCode, const std::string& nativeLibDir) CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, uint64_t activeNetHandle, unsigned int versionCode, const std::string& nativeLibDir)
: mVersionCode(versionCode), m_nativeLibraryDir(nativeLibDir), m_network(NULL), m_defNetHandle(NETWORK_UNSPECIFIED), m_ethnetHandle(NETWORK_UNSPECIFIED) : mVersionCode(versionCode), m_nativeLibraryDir(nativeLibDir), m_network(NULL), m_defNetHandle(activeNetHandle), m_ethnetHandle(NETWORK_UNSPECIFIED)
{ {
mCamera = NULL; mCamera = NULL;
m_listener = NULL; m_listener = NULL;
@ -490,8 +490,6 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
m_javaService = NULL; m_javaService = NULL;
m_appPath = appPath; m_appPath = appPath;
mNetId = netId;
m_signalLevel = 0; m_signalLevel = 0;
m_signalLevelUpdateTime = time(NULL); m_signalLevelUpdateTime = time(NULL);
mBuildTime = 0; mBuildTime = 0;
@ -647,7 +645,6 @@ void CPhoneDevice::SetRecognizationCfg(const IDevice::CFG_RECOGNIZATION* pRecogn
bool CPhoneDevice::BindNetwork(int sock) bool CPhoneDevice::BindNetwork(int sock)
{ {
m_devLocker.lock(); m_devLocker.lock();
net_handle_t defNetHandle = m_defNetHandle; net_handle_t defNetHandle = m_defNetHandle;
m_devLocker.unlock(); m_devLocker.unlock();
@ -3760,13 +3757,16 @@ void CPhoneDevice::UpdateSimcard(const std::string& simcard)
m_simcard = simcard; m_simcard = simcard;
} }
void CPhoneDevice::UpdateNetwork(net_handle_t nethandle, bool available, bool defaultOrEthernet) void CPhoneDevice::UpdateNetwork(net_handle_t nethandle, bool available, bool defaultOrEthernet, bool& changed)
{ {
if (defaultOrEthernet) if (defaultOrEthernet)
{ {
net_handle_t oldHandle = NETWORK_UNSPECIFIED;
m_devLocker.lock(); m_devLocker.lock();
oldHandle = m_defNetHandle;
m_defNetHandle = available ? nethandle : NETWORK_UNSPECIFIED; m_defNetHandle = available ? nethandle : NETWORK_UNSPECIFIED;
m_devLocker.unlock(); m_devLocker.unlock();
changed = (oldHandle != nethandle);
XYLOG(XYLOG_SEVERITY_WARNING, "Active Network Handle: %lld", available ? (uint64_t)nethandle : 0); XYLOG(XYLOG_SEVERITY_WARNING, "Active Network Handle: %lld", available ? (uint64_t)nethandle : 0);
} }
else else
@ -3785,7 +3785,6 @@ net_handle_t CPhoneDevice::GetEthnetHandle() const
nethandle = m_ethnetHandle; nethandle = m_ethnetHandle;
m_devLocker.unlock(); m_devLocker.unlock();
return nethandle; return nethandle;
} }
void CPhoneDevice::SetStaticIp(const std::string& iface, const std::string& ip, const std::string& netmask, const std::string& gateway) void CPhoneDevice::SetStaticIp(const std::string& iface, const std::string& ip, const std::string& netmask, const std::string& gateway)

@ -208,7 +208,7 @@ public:
uint64_t uid; uint64_t uid;
}; };
CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId, unsigned int versionCode, const std::string& nativeLibDir); CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, uint64_t activeNetHandle, unsigned int versionCode, const std::string& nativeLibDir);
virtual ~CPhoneDevice(); virtual ~CPhoneDevice();
virtual void SetListener(IListener* listener); virtual void SetListener(IListener* listener);
@ -260,7 +260,7 @@ public:
mBuildTime = buildTime; mBuildTime = buildTime;
} }
void UpdateSimcard(const std::string& simcard); void UpdateSimcard(const std::string& simcard);
void UpdateNetwork(net_handle_t nethandle, bool available, bool defaultOrEthernet); void UpdateNetwork(net_handle_t nethandle, bool available, bool defaultOrEthernet, bool& changed);
net_handle_t GetEthnetHandle() const; net_handle_t GetEthnetHandle() const;
@ -384,7 +384,6 @@ protected:
IListener* m_listener; IListener* m_listener;
const CFG_RECOGNIZATION* m_pRecognizationCfg; const CFG_RECOGNIZATION* m_pRecognizationCfg;
bool mAIInitialized; bool mAIInitialized;
unsigned int mNetId;
unsigned int mVersionCode; unsigned int mVersionCode;
time_t mBuildTime; time_t mBuildTime;

Loading…
Cancel
Save