|
@@ -4,7 +4,7 @@
|
|
|
* @Autor: lishengyin
|
|
|
* @Date: 2022-01-11 11:47:46
|
|
|
* @LastEditors: lishengyin
|
|
|
- * @LastEditTime: 2022-01-11 14:51:57
|
|
|
+ * @LastEditTime: 2022-01-12 11:18:40
|
|
|
*/
|
|
|
#include "Manager.h"
|
|
|
|
|
@@ -12,6 +12,8 @@
|
|
|
namespace MIVA{
|
|
|
|
|
|
std::shared_ptr<Manager> m_manager = nullptr;
|
|
|
+ bool setFdEble = false;
|
|
|
+
|
|
|
Manager::Manager(){
|
|
|
}
|
|
|
|
|
@@ -47,6 +49,15 @@ namespace MIVA{
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @description: 设置fd阈值
|
|
|
+ * @param {int} fdThreshold
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ void Manager::setFdThreshold(int fdThreshold){
|
|
|
+ if(setFdEble) this->FdThreshold = fdThreshold;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* @description: 获得启动资格
|
|
|
* @param {*}
|
|
|
* @return {*}
|
|
@@ -57,22 +68,25 @@ namespace MIVA{
|
|
|
int result = ERR;
|
|
|
if(Infer == nullptr) return result;
|
|
|
if(m_deviceState->getDeviceState() != OK) return result;
|
|
|
- result = !Infer->Play ? OK : ERR;
|
|
|
- // 内存余量较少,避免内存在未清理完全的时候启动,避免死机
|
|
|
- if(m_deviceState->MemoryUsage < this-> MemoryThreshold) result = ERR;
|
|
|
+ // 从内存、温度、fd、播放是否停止一起来判定是否可以启动
|
|
|
+ if(decideMemoryResult() && decideTempResult() && decideFdResult() && decidePlayResult()) result = OK;
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @description: 获取停止资格
|
|
|
* @param {*}
|
|
|
* @return {*}
|
|
|
*/
|
|
|
int32_t Manager::getStopPower(){
|
|
|
+ static int num = 0;
|
|
|
+ if(num == 0){
|
|
|
+ setFdEble = true;
|
|
|
+ num++;
|
|
|
+ }
|
|
|
std::shared_ptr<Inference> Infer = Inference::CreateNew();
|
|
|
if(Infer == nullptr) return ERR;
|
|
|
- return Infer->Play ? OK : ERR;
|
|
|
- return OK;
|
|
|
+ return !decidePlayResult() ? OK : ERR;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -81,7 +95,6 @@ namespace MIVA{
|
|
|
* @return {*}
|
|
|
*/
|
|
|
int32_t Manager::getClearPower(){
|
|
|
-
|
|
|
return OK;
|
|
|
}
|
|
|
|
|
@@ -93,7 +106,7 @@ namespace MIVA{
|
|
|
int32_t Manager::getSyncDataPower(){
|
|
|
std::shared_ptr<Inference> Infer = Inference::CreateNew();
|
|
|
if(Infer == nullptr) return ERR;
|
|
|
- return !Infer->Play ? OK : ERR;
|
|
|
+ return decidePlayResult() ? OK : ERR;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -104,8 +117,60 @@ namespace MIVA{
|
|
|
int32_t Manager::getHostDataPower(){
|
|
|
std::shared_ptr<Inference> Infer = Inference::CreateNew();
|
|
|
if(Infer == nullptr) return ERR;
|
|
|
- return !Infer->Play ? OK : ERR;
|
|
|
- }
|
|
|
-
|
|
|
+ return decidePlayResult() ? OK : ERR;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 获取同步FdThreshold的资格
|
|
|
+ * @param {*}
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ int32_t Manager::getSyncFdThresholdPower(){
|
|
|
+ return setFdEble ? OK : ERR;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description:
|
|
|
+ * @param {*}
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ bool Manager::decideFdResult(){
|
|
|
+ if(!setFdEble) return true;
|
|
|
+ std::shared_ptr<deviceState> m_deviceState = deviceState::CreateNew();
|
|
|
+ if(m_deviceState->FdUsage >= this->FdThreshold){
|
|
|
+ int fd = m_deviceState->FdUsage - this->FdThreshold;
|
|
|
+ if(fd > 2) return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 获取内存的判定结果
|
|
|
+ * @param {*}
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ bool Manager::decideMemoryResult(){
|
|
|
+ std::shared_ptr<deviceState> m_deviceState = deviceState::CreateNew();
|
|
|
+ return m_deviceState->MemoryUsage < this-> MemoryThreshold ? false : true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 获取温度的判定结果
|
|
|
+ * @param {*}
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ bool Manager::decideTempResult(){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 获取播放的结果
|
|
|
+ * @param {*}
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ bool Manager::decidePlayResult(){
|
|
|
+ std::shared_ptr<Inference> Infer = Inference::CreateNew();
|
|
|
+ return !Infer->Play ? true : false;
|
|
|
+ }
|
|
|
}
|
|
|
|