Esempio n. 1
0
QueueElement *Queue::run_next()
{
    QueueElement* el = NULL;

    if (!queue[PRIORITY_HIGH].empty())
    {
        el = queue[PRIORITY_HIGH].front();
        queue[PRIORITY_HIGH].pop_front();
    }
    else if (!queue[PRIORITY_MEDIUM].empty())
    {
        el = queue[PRIORITY_MEDIUM].front();
        queue[PRIORITY_MEDIUM].pop_front();
    }
    else if (!queue[PRIORITY_LOW].empty())
    {
        el = queue[PRIORITY_LOW].front();
        queue[PRIORITY_LOW].pop_front();
    }
    else if (!queue[PRIORITY_NONE].empty())
    {
        el = queue[PRIORITY_NONE].front();
        queue[PRIORITY_NONE].pop_front();
    }

    if (!el)
        return NULL;

    el->Run();
    return el;
}
Esempio n. 2
0
static void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_Size, void* UserHandle_Void)
{
    //*integrity tests
    if (Data_Size<4)
        return; //There is a problem

    QueueElement *queue = (QueueElement*)UserHandle_Void;
    struct MediaInfo_Event_Generic* Event_Generic = (struct MediaInfo_Event_Generic*)Data_Content;
    // unsigned char ParserID = (unsigned char)((Event_Generic->EventCode & 0xFF000000) >> 24);
    unsigned short EventID = (unsigned short)((Event_Generic->EventCode & 0x00FFFF00) >> 8);
    unsigned char EventVersion = (unsigned char)(Event_Generic->EventCode & 0x000000FF);

    switch (EventID)
    {
        case MediaInfo_Event_Global_AttachedFile:
            if (EventVersion == 0)
                queue->attachment_cb((struct MediaInfo_Event_Global_AttachedFile_0 *)Data_Content);
            break;
        case MediaInfo_Event_Log:
            if (EventVersion == 0 && Data_Size >= sizeof(struct MediaInfo_Event_Log_0))
                queue->log_cb((struct MediaInfo_Event_Log_0*)Data_Content);
            break;
        default:
            break;
    }
}
Esempio n. 3
0
void NetworkBase::tickSend(NetworkEvent* event)
{
	// send
	if (sendQueue_.empty() == false)
	{
		QueueElement* queueElement = sendQueue_.front();

		int sent = queueElement->send(clientSock_);
		
		if (sent == -1)
		{
			cleanup();
			event->eventCode = eOtherSideClosedConnection;
			return;
		}

		dataSent_ += sent;
		
		if (queueElement->finished() == true)
		{
			delete queueElement;
			sendQueue_.pop_front();
		}
	}
}
bool
WimaxMacQueue::Enqueue (Ptr<Packet> packet, const MacHeaderType &hdrType,
                        const GenericMacHeader &hdr)
{

  if (m_queue.size () == m_maxSize)
    {

      m_traceDrop (packet);
      return false;
    }

  m_traceEnqueue (packet);
  QueueElement element (packet, hdrType, hdr, Simulator::Now ());
  m_queue.push_back (element);

  if (hdrType.GetType () == MacHeaderType::HEADER_TYPE_GENERIC)
    {
      m_nrDataPackets++;
    }
  else
    {
      m_nrRequestPackets++;
    }

  m_bytes += element.GetSize ();
  return true;
}
Esempio n. 5
0
ProtocolEvent ProtocolUDPGeneric::waitForEvent(
    DataObjectRef &dObj, 
    Timeval *timeout, 
    bool writeevent)
{
    QueueElement *qe = NULL;
    Queue *q = getQueue();

    if (!q) {
        return PROT_EVENT_ERROR;
    }

    SocketWrapper *sock = getReadEndOfReceiveSocket();

    if (NULL == sock) {
        HAGGLE_ERR("%s Null receive socket\n", getName());
        return PROT_EVENT_ERROR_FATAL;
    }

    HAGGLE_DBG("%s Waiting for queue element or timeout... %s\n", 
	       getName(), timeout->getAsString().c_str());

    QueueEvent_t qev = q->retrieve(&qe, 
		      sock->getSOCKET(), 
		      timeout, 
		      writeevent);

    if (QUEUE_ELEMENT == qev) {
        dObj = qe->getDataObject();
        delete qe;
        return PROT_EVENT_TXQ_NEW_DATAOBJECT;
    }

    if (QUEUE_EMPTY == qev) {
        return PROT_EVENT_TXQ_EMPTY;
    }

    if (QUEUE_WATCH_WRITE == qev) {
        return PROT_EVENT_WRITEABLE;
    }

    if (QUEUE_WATCH_ABANDONED == qev) {
        // SW: this occurs when the protocol has been shutdown via some other
        // mechanism, such as interface down
        HAGGLE_DBG("%s Waiting for event abandoned\n", getName());
        return PROT_EVENT_SHOULD_EXIT;
    }
    
    if (QUEUE_TIMEOUT == qev) {
        HAGGLE_DBG("%s Waiting for event timeout\n", getName());
        return  PROT_EVENT_TIMEOUT;
    }

    if (QUEUE_WATCH_READ == qev) {
        return PROT_EVENT_INCOMING_DATA;
    } 

    HAGGLE_ERR("%s Waiting for event unknown error\n", getName());
    return PROT_EVENT_ERROR;
}
Esempio n. 6
0
int NetworkBase::sendData(const void* data, unsigned int size)
{
	if (isConnected() == false)
		return -1;

	QueueElement* queueElement = new QueueElement(data, size, 0);
	sendQueue_.push_back(queueElement);
	return queueElement->id();
}
Esempio n. 7
0
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
	cs.Enter();
	QueueElement q = actionQueue.front();
	actionQueue.pop_front();
	UpdateTimer();
	cs.Leave();
	q.Handler(q.hContact, q.inf);
}
Esempio n. 8
0
VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD)
{
	mir_cslockfull lck(cs);
	QueueElement q = actionQueue.front();
	actionQueue.pop_front();
	UpdateTimer();
	lck.unlock();

	q.Handler(q.hContact, q.inf);
}
Esempio n. 9
0
void IndexedQueue::init(RanGen& ran, AllReactions& all){

	_pqueue.clear();
	for(unsigned i=0; i < _indices.size() ; ++i){
		QueueElement* elm = _indices[i];
		delete elm;
		_indices[i] = NULL;
	}
        _indices.clear();


	//create empty PQueue using information in all.
	if(!_sentinel){
		_sentinel = new QueueElement();
		_pqueue.setSentinel(_sentinel);  // sentinel is not added to the indexvector
	}
        else if (_pqueue.size()==0){//if init() is called again, sentinel has to be set again!
            _pqueue.setSentinel(_sentinel);
        }
	
	for (unsigned r=0; r < all.size() ; ++r){
		// cout << r << "\t" << all[r]->propensity() << "\t";
		double time_i = std::numeric_limits<double>::infinity();
		if(all[r]->propensity() > 0.0){
			double rval = ran.randouble();
			time_i = all[r]->calcPutativeTime(rval); 
			// cout << "Rval = " << rval << " for reaction " << *(all[r]) << " ";//" produces pututative time = "<<  time_i << endl;
		}
		else all[r]->setPutativeTime(time_i);
		// cout << all[r]->putativeTime()<<"\t" << endl;
		
		QueueElement *elm = new QueueElement(r, time_i);
		_indices.push_back(elm);
		elm->setQueueLoc(_pqueue.size()); //starts at 1!!!
		try {
			_pqueue.push(elm);
		}
		catch (std::exception & e){
                    std::cout <<" HEAP exception: " << e.what() << std::endl;
			exit(0);
		}
	}
        // all.print(std::cout);
}
Esempio n. 10
0
QueueElement::QueueElement(const QueueElement& other){
	_idx=other.index();
	_tau=other.tau();
	_queloc=other.queueLoc();
}
Esempio n. 11
0
Ptr<Packet>
WimaxMacQueue::Dequeue (MacHeaderType::HeaderType packetType)
{
  if (!IsEmpty ())
    {
      QueueElement element = Front (packetType);
      Pop (packetType);

      if (element.m_hdrType.GetType () == MacHeaderType::HEADER_TYPE_GENERIC)
        {
          NS_LOG_INFO ("Enqueued Packet IS A data packet");
          NS_ASSERT_MSG (m_nrDataPackets >= 1,
                         "Can not enqueue more packets: no space left in the queue");
          m_nrDataPackets--;
        }
      else
        {
          NS_LOG_INFO ("Enqueued Packet IS A Request BW packet");
          NS_ASSERT_MSG (m_nrRequestPackets >= 1,
                         "Can not enqueue more packets: no space left in the queue");
          m_nrRequestPackets--;
        }

      Ptr<Packet> packet = element.m_packet;

      if (!element.m_fragmentation)
        {
          NS_LOG_INFO ("FRAG_DEBUG: Enqueued Packet IS NOT a fragment" << std::endl);
          /*check because may be it is a bandwidth request packet (in which case a Bandwidth Request Header
            has already been added to the packet) in which case Generic MAC Header will not be added to it.
            this will only happen in the case of SS as only SS sends the bandwidth request packet. */
          m_bytes -= element.GetSize ();
          if (element.m_hdrType.GetType () == MacHeaderType::HEADER_TYPE_GENERIC)
            {
              packet->AddHeader (element.m_hdr);
            }
          packet->AddHeader (element.m_hdrType);

          m_traceDequeue (packet);
          return packet;
        }
      else
        {
          /*
           The enqueued packet is a fragment (the latest fragment)
           We must modify type field of the m_hdr and add a fragmentation Subhdr
           */
          NS_LOG_INFO ("\t Enqueued Packet IS a fragment, add subhdr" << std::endl);

          // Create a fragment
          uint32_t fragmentOffset = element.m_fragmentOffset;
          uint32_t fragmentSize = element.m_packet->GetSize () - fragmentOffset;

          NS_LOG_INFO ("\t Create a fragment"
                       "\n\t\t fragmentOffset=" << fragmentOffset <<
                       "\n\t\t packetSize=" << element.m_packet->GetSize () <<
                       "\n\t\t fragmentSize=" << fragmentSize << std::endl);

          Ptr<Packet> fragment = packet->CreateFragment (fragmentOffset,fragmentSize);

          FragmentationSubheader fragmentSubhdr;
          NS_LOG_INFO ("\t Latest Fragment" << std::endl);
          fragmentSubhdr.SetFc (2);   // This is the latest fragment
          fragmentSubhdr.SetFsn (element.m_fragmentNumber);

          NS_LOG_INFO ("\t FragmentSize=" << fragment->GetSize () << std::endl);
          fragment->AddHeader (fragmentSubhdr);

          /*check because may be it is a bandwidth request packet (in which case a Bandwidth Request Header
          has already been added to the packet) in which case Generic MAC Header will not be added to it.
          this will only happen in the case of SS as only SS sends the bandwidth request packet. */
          if (element.m_hdrType.GetType () == MacHeaderType::HEADER_TYPE_GENERIC)
            {
              uint8_t tmpType = element.m_hdr.GetType ();
              tmpType |= 4;
              element.m_hdr.SetType (tmpType);

              uint32_t length = fragmentSize + element.m_hdr.GetSerializedSize ()
                + fragmentSubhdr.GetSerializedSize ();
              element.m_hdr.SetLen ((uint16_t)length);

              fragment->AddHeader (element.m_hdr);
            }
          fragment->AddHeader (element.m_hdrType);
          m_bytes -= fragmentSize;

          m_traceDequeue (fragment);
          return fragment;
        }
    }
  return 0;
}