Пример #1
0
boolean WAKEUP::wakeMeAfter( void (*sleeper)(void*), long ms, void *context, boolean treatAsISR) {
  unsigned long timeSinceLast;
   
  // Check the time requested and if there is a free bunk to store the sleeper
  if (ms == 0 || _numSleepers >= MAXSLEEPERS) return false;
 
  _oldSREG = SREG;
  cli();
  
  // If any already sleeping, then get the count from start of heartbeat and deduct from all active timers
  if (_numSleepers > 0 && (timeSinceLast = getElapsed()) > 0) {
    for (int i = 0; i < _numSleepers; i++) _bunks[i].timeToWake -= timeSinceLast; 
  }

  // Put new sleeper into top bunk and set alarm clock
  _bunks[_numSleepers].sleepDuration = ms;					// Save the delay to inform timerISR
  _bunks[_numSleepers].callback = sleeper;					// Put sleeper into bunk
  _bunks[_numSleepers].treatAsISR = treatAsISR;				// Interrupt on wake or put on pending queue
  _bunks[_numSleepers].context = context;					// Save its context
  _bunks[_numSleepers].timeToWake = (ms > 0) ? ms : -ms;	// Set the delay 

  _numSleepers++; 
  
  SREG = _oldSREG;  
      
  startHeartbeat();    // Set counter going with an appropriate heartbeat
     
  return true;  
}
Пример #2
0
void FileTransferSocket::onConnectDone()
{
	LOG__(APP, _T("FileTransferSocket::onConnected()"));
	startHeartbeat();

	TransferFileEntity info;
    if (!TransferFileEntityManager::getInstance()->getFileInfoByTaskId(m_sTaskId, info))
    {
        LOG__(APP, _T("Can't get the file info,task id:%s"),util::stringToCString(m_sTaskId));
        return;
    }
		
	//拉模式文件传输,传输taskid、token、client_mode
	IM::File::IMFileLoginReq imFileLoginReq;
	imFileLoginReq.set_user_id(module::getSysConfigModule()->userId());
	imFileLoginReq.set_task_id(info.sTaskID);
	imFileLoginReq.set_file_role(static_cast<IM::BaseDefine::ClientFileRole>(info.nClientMode));

    LOG__(APP, _T("IMFileLoginReq,sTaskID:%s,nClientMode:%d"), util::stringToCString(info.sTaskID), info.nClientMode);
	//send packet
    LOG__(APP, _T("IMFileLoginReq,taskId:%s"), util::stringToCString(info.sTaskID));
    sendPacket(IM::BaseDefine::ServiceID::SID_FILE, IM::BaseDefine::FileCmdID::CID_FILE_LOGIN_REQ, &imFileLoginReq);

	//CImPduClientFileLoginReq pduFileLoginReq(module::getSysConfigModule()->userID().c_str()
	//	, "", info.sTaskID.c_str(), );
	//sendPacket(&pduFileLoginReq);
}
Пример #3
0
QString Condition4Timer::updataConditionList()
{
	QMultiHash<QString, QString> tmpMHTim2Job;
	{
		QMutexLocker locker(&m_Mutex4Job);
		for (int iJobIndex = 0;iJobIndex < m_list4Job.size();iJobIndex++)
		{
			QString strCurJob = m_list4Job[iJobIndex];
			QStringList strlitTime = getConditionTime(strCurJob);
			for (int i = 0;i < strlitTime.size();i++)
			{
				tmpMHTim2Job.insert(strlitTime[0],strCurJob);
			}
		}
	}

	stopHeartbeat();
	{
		QMutexLocker lLocker(&m_Mutex4Tim2Job);
		m_hashTim2Job.clear();
		m_hashTim2Job = tmpMHTim2Job;
	}
	startHeartbeat(m_ibeatTime);

	return "Successful";
}
Пример #4
0
void FileTransferSocket::onConnectDone()
{
	APP_LOG(LOG_INFO, _T("FileTransferSocket::onConnected()"));
	startHeartbeat();

	TransferFileEntity info;
	if (!TransferFileEntityManager::getInstance()->getFileInfoByTaskId(m_sTaskId, info))
		return;

	//拉模式文件传输,传输taskid、token、client_mode
	CImPduClientFileLoginReq pduFileLoginReq(module::getSysConfigModule()->userID().c_str()
		, "", info.sTaskID.c_str(), info.nClientMode);
	sendPacket(&pduFileLoginReq);
}
Пример #5
0
void WAKEUP::timerISR() {							// Runs every heartbeat 
  unsigned int runNowPtr = MAXPENDING;		                // Pointer to top end of _pending to use as temporary scratchpad
  
  for (int i = 0; i < _numSleepers; i++) {
	  
	// If countdown has finished then put on pending queue and shuffle bunks (if needed)
	if ((_bunks[i].timeToWake -= _heartbeat) <= 0) {  

		  // Put in pending queue, either to wake in a few moments or from main program using runAnyPending
		  // If runAnyPending not run fast enough then bottom-up and top-down queues may clash, so check
		  if (_bunks[i].treatAsISR == TREAT_AS_ISR) {				// Wake later in this function
  			  if (--runNowPtr <= _numPending) runNowPtr++;
			  _pending[runNowPtr].callback = _bunks[i].callback;
			  _pending[runNowPtr].context = _bunks[i].context;
		  }
		  else {													// Wake in response to runAnyPending
			  _pending[_numPending].callback = _bunks[i].callback;
			  _pending[_numPending].context = _bunks[i].context;
			  if (++_numPending >= runNowPtr) _numPending--;			
		  }
		  
		  // If others left after one-shot sleeper removed, take sleeper in topmost bunk and move to the newly-vacant bunk
	      if (_bunks[i].sleepDuration > 0) {					// Positive number means one-shot
		      _numSleepers--;			
	      	  if (_numSleepers > 0) {				// Move topmost sleeper into this bunk (v rarely might be the same one, but safe so ignore)
			      _bunks[i].callback = _bunks[_numSleepers].callback;
			      _bunks[i].treatAsISR = _bunks[_numSleepers].treatAsISR;
			      _bunks[i].sleepDuration = _bunks[_numSleepers].sleepDuration;
			      _bunks[i].timeToWake = _bunks[_numSleepers].timeToWake;
			      _bunks[i].context = _bunks[_numSleepers].context;
			      i--;								// Decrement counter to ensure this sleeper isn't missed
		      }
	      }
	      else _bunks[i].timeToWake -=_bunks[i].sleepDuration;			// Repeating sleeper, just reset countdown
        
    }
  }
  
  // Start the heartbeat if sleepers left
  if (_numSleepers == 0) stopHeartbeat(); startHeartbeat();
  
  // Run the TREAT_AS_ISR sleepers that were woken - be quick (and block runAnyPending() from being run)
  _inISR = true;
  for (int i = runNowPtr; i < MAXPENDING; i++) _pending[i].callback(_pending[i].context);
  _inISR = false;
  
}