本文整理汇总了C++中NF_SHARE_PTR::DoHeartBeatEvent方法的典型用法代码示例。如果您正苦于以下问题:C++ NF_SHARE_PTR::DoHeartBeatEvent方法的具体用法?C++ NF_SHARE_PTR::DoHeartBeatEvent怎么用?C++ NF_SHARE_PTR::DoHeartBeatEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NF_SHARE_PTR
的用法示例。
在下文中一共展示了NF_SHARE_PTR::DoHeartBeatEvent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
bool NFCHeartBeatManager::Execute()
{
NF_SHARE_PTR<NFCHeartBeatElement> pElement = mHeartBeatElementMapEx.First();
while (pElement.get())
{
//millisecond
NFINT64 nTime = NFTime::GetNowTimeMille();
if (nTime > pElement->nNextTriggerTime && pElement->nCount > 0)
{
pElement->nCount--;
pElement->DoHeartBeatEvent();
if (pElement->nCount <= 0)
{
//等待删除
mRemoveListEx.Add(pElement->strBeatName);
}
else
{
//Do Event
pElement->nNextTriggerTime = nTime + NFINT64(pElement->fBeatTime * 1000);
}
}
pElement = mHeartBeatElementMapEx.Next();
}
//删除所有过时心跳
std::string strHeartBeatName;
bool bRet = mRemoveListEx.First(strHeartBeatName);
while (bRet)
{
mHeartBeatElementMapEx.RemoveElement(strHeartBeatName);
bRet = mRemoveListEx.Next(strHeartBeatName);
}
mRemoveListEx.ClearAll();
//////////////////////////////////////////////////////////////////////////
//添加新心跳也是延时添加的
for (std::list<NFCHeartBeatElement>::iterator iter = mAddListEx.begin(); iter != mAddListEx.end(); ++iter)
{
if (NULL == mHeartBeatElementMapEx.GetElement(iter->strBeatName))
{
NF_SHARE_PTR<NFCHeartBeatElement> pHeartBeatEx(NF_NEW NFCHeartBeatElement());
*pHeartBeatEx = *iter;
mHeartBeatElementMapEx.AddElement(pHeartBeatEx->strBeatName, pHeartBeatEx);
}
}
mAddListEx.clear();
return true;
}
示例2: Execute
bool NFCHeartBeatManager::Execute(const float fLastTime, const float fAllTime)
{
NF_SHARE_PTR<NFCHeartBeatElement> pElement = mHeartBeatElementMapEx.First();
while (pElement.get())
{
int nCount = pElement->nCount;
float fTime = pElement->fTime;
if (fTime > 0.000000f)
{
fTime -= fLastTime;
}
if (fTime <= 0.001f)
{
nCount--;
}
else
{
pElement->fTime = fTime;
}
if (nCount <= 0)
{
//Do Event
pElement->DoHeartBeatEvent();
//等待删除
mRemoveListEx.Add(pElement->strBeatName);
}
else
{
if (pElement->nCount != nCount)
{
pElement->nCount = nCount;
//Do Event
pElement->DoHeartBeatEvent();
pElement->fTime = pElement->fBeatTime;
}
}
pElement = mHeartBeatElementMapEx.Next();
}
//删除所有过时心跳
std::string strHeartBeatName;
bool bRet = mRemoveListEx.First(strHeartBeatName);
while (bRet)
{
mHeartBeatElementMapEx.RemoveElement(strHeartBeatName);
bRet = mRemoveListEx.Next(strHeartBeatName);
}
mRemoveListEx.ClearAll();
//////////////////////////////////////////////////////////////////////////
//添加新心跳也是延时添加的
for (std::list<NFCHeartBeatElement>::iterator iter = mAddListEx.begin(); iter != mAddListEx.end(); ++iter)
{
if (NULL == mHeartBeatElementMapEx.GetElement(iter->strBeatName))
{
NF_SHARE_PTR<NFCHeartBeatElement> pHeartBeatEx(NF_NEW NFCHeartBeatElement());
*pHeartBeatEx = *iter;
mHeartBeatElementMapEx.AddElement(pHeartBeatEx->strBeatName, pHeartBeatEx);
}
}
mAddListEx.clear();
return true;
}
示例3: Execute
bool NFCScheduleModule::Execute()
{
//execute every schedule
NF_SHARE_PTR<NFMapEx <std::string, NFCScheduleElement >> xObjectSchedule = mObjectScheduleMap.First();
while (xObjectSchedule)
{
std::string str;
NF_SHARE_PTR<NFCScheduleElement> pSchedule = xObjectSchedule->First();
while (pSchedule)
{
NFINT64 nNow = NFGetTime();
if (nNow > pSchedule->mnNextTriggerTime)
{
std::map<NFGUID, std::string>::iterator itRet = mObjectRemoveList.find(pSchedule->self);
if (itRet != mObjectRemoveList.end())
{
if (itRet->second != pSchedule->mstrScheduleName)
{
if (pSchedule->mnRemainCount > 0 || pSchedule->mbForever == true)
{
pSchedule->mnRemainCount--;
pSchedule->DoHeartBeatEvent();
if (pSchedule->mnRemainCount <= 0 && pSchedule->mbForever == false)
{
mObjectRemoveList.insert(std::map<NFGUID, std::string>::value_type(pSchedule->self, pSchedule->mstrScheduleName));
}
else
{
NFINT64 nNextCostTime = NFINT64(pSchedule->mfIntervalTime * 1000) * (pSchedule->mnAllCount - pSchedule->mnRemainCount);
pSchedule->mnNextTriggerTime = pSchedule->mnStartTime + nNextCostTime;
}
}
}
}
}
pSchedule = xObjectSchedule->Next();
}
xObjectSchedule = mObjectScheduleMap.Next();
}
//remove schedule
for (std::map<NFGUID, std::string>::iterator it = mObjectRemoveList.begin(); it != mObjectRemoveList.end(); ++it)
{
NFGUID self = it->first;
std::string scheduleName = it->second;
auto findIter = mObjectScheduleMap.GetElement(self);
if (NULL != findIter)
{
findIter->RemoveElement(scheduleName);
if (findIter->Count() == 0)
{
mObjectScheduleMap.RemoveElement(self);
}
}
}
mObjectRemoveList.clear();
//add schedule
for (std::list<NFCScheduleElement>::iterator iter = mObjectAddList.begin(); iter != mObjectAddList.end(); ++iter)
{
NF_SHARE_PTR< NFMapEx <std::string, NFCScheduleElement >> xObjectScheduleMap = mObjectScheduleMap.GetElement(iter->self);
if (NULL == xObjectScheduleMap)
{
xObjectScheduleMap = NF_SHARE_PTR< NFMapEx <std::string, NFCScheduleElement >>(NF_NEW NFMapEx <std::string, NFCScheduleElement >());
mObjectScheduleMap.AddElement(iter->self, xObjectScheduleMap);
}
NF_SHARE_PTR<NFCScheduleElement> xScheduleElement = xObjectScheduleMap->GetElement(iter->mstrScheduleName);
if (NULL == xScheduleElement)
{
xScheduleElement = NF_SHARE_PTR<NFCScheduleElement>(NF_NEW NFCScheduleElement());
*xScheduleElement = *iter;
xObjectScheduleMap->AddElement(iter->mstrScheduleName, xScheduleElement);
}
}
mObjectAddList.clear();
////////////////////////////////////////////
//execute every schedule
NF_SHARE_PTR< NFCScheduleElement > xModuleSchedule = mModuleScheduleMap.First();
while (xModuleSchedule)
{
NFINT64 nNow = NFGetTime();
if (nNow > xModuleSchedule->mnNextTriggerTime)
{
if (xModuleSchedule->mnRemainCount > 0 || xModuleSchedule->mbForever == true)
{
xModuleSchedule->mnRemainCount--;
xModuleSchedule->DoHeartBeatEvent();
if (xModuleSchedule->mnRemainCount <= 0 && xModuleSchedule->mbForever == false)
{
mModuleRemoveList.push_back(xModuleSchedule->mstrScheduleName);
}
else
//.........这里部分代码省略.........