void ThreadPoolWorker::WakeUp()
	{
		SetIdle(false);
		kpr::ScopedLock<kpr::Monitor> lock(*this);
		m_canWork = true;
		Notify();
	}
	void ThreadPoolWorker::Run()
	{
		while (!m_stop)
		{
			SetIdle(true);
			{
				kpr::ScopedLock<kpr::Monitor> lock(*this);
				while (!m_canWork)
				{
					try
					{
						m_isWaiting = true;
						Wait();
						m_isWaiting = false;
					}
					catch (...)
					{
					}
				}

				m_canWork = false;
			}

			while (!m_stop)
			{
				ThreadPoolWork* request = m_pThreadPool->GetWork(this);
				if (NULL == request)
				{
					break;
				}

				SetIdle(false);
				request->Do();

				request = NULL;
			}

			if (m_stop || m_pThreadPool->IsDestroy())
			{
				break;
			}
		}

		m_pThreadPool ->RemoveThread(this);
		m_pThreadPool = NULL;
	}
Beispiel #3
0
int IdleChanged(WPARAM wParam, LPARAM lParam) {
	if(!(lParam & IDF_PRIVACY)) {
		is_idle = lParam & IDF_ISIDLE ? true : false;
		SetIdle(is_idle);
	}

	return 0;
}
Beispiel #4
0
void CFlowNode_AIStateRoam::OnUpdate(SActivationInfo* pActInfo)
{
	if(m_State != ROAM && CryGetTicks() >= m_State)
	{
		SetIdle(false);
		ForceAIRoam();
		m_State = ROAM;
	}
}
Beispiel #5
0
void CFlowNode_AIStateGuard::OnUpdate(SActivationInfo* pActInfo)
{
	if(m_State != GUARD && CryGetTicks() >= m_State)
	{
		SetIdle(false);
		ForceAIGuard();
		m_State = GUARD;
	}
}
Beispiel #6
0
int CSametimeProto::OnIdleChanged(WPARAM, LPARAM lParam)
{
	if (!(lParam & IDF_PRIVACY)) {
		is_idle = lParam & IDF_ISIDLE ? true : false;
		SetIdle(is_idle);
	}

	return 0;
}
void
SharedDecoderManager::Select(SharedDecoderProxy* aProxy)
{
  if (mActiveProxy == aProxy) {
    return;
  }
  SetIdle(mActiveProxy);

  mActiveProxy = aProxy;
  mActiveCallback = aProxy->mCallback;
}
nsresult
RtspMediaCodecReader::ReadMetadata(MediaInfo* aInfo,
                                   MetadataTags** aTags)
{
  mRtspResource->DisablePlayoutDelay();
  EnsureActive();
  nsresult rv = MediaCodecReader::ReadMetadata(aInfo, aTags);
  SetIdle();

  if (rv == NS_OK && !IsWaitingMediaResources()) {
    mRtspResource->EnablePlayoutDelay();
  }

  return rv;
}
nsRefPtr<MediaDecoderReader::MetadataPromise>
RtspMediaCodecReader::AsyncReadMetadata()
{
  mRtspResource->DisablePlayoutDelay();
  EnsureActive();

  nsRefPtr<MediaDecoderReader::MetadataPromise> p =
    MediaCodecReader::AsyncReadMetadata();

  // Send a PAUSE to the RTSP server because the underlying media resource is
  // not ready.
  SetIdle();

  return p;
}
void
SharedDecoderManager::Select(SharedDecoderProxy* aProxy)
{
  if (mActiveProxy == aProxy) {
    return;
  }
  SetIdle(mActiveProxy);

  mActiveProxy = aProxy;
  mActiveCallback = aProxy->mCallback;

  if (mDecoderReleasedResources) {
    mDecoder->AllocateMediaResources();
    mDecoderReleasedResources = false;
  }
}
Beispiel #11
0
nsRefPtr<MediaDecoderReader::MetadataPromise>
RtspOmxReader::AsyncReadMetadata()
{
  // Send a PLAY command to the RTSP server before reading metadata.
  // Because we might need some decoded samples to ensure we have configuration.
  mRtspResource->DisablePlayoutDelay();

  nsRefPtr<MediaDecoderReader::MetadataPromise> p =
    MediaOmxReader::AsyncReadMetadata();

  // Send a PAUSE to the RTSP server because the underlying media resource is
  // not ready.
  SetIdle();

  return p;
}
Beispiel #12
0
int Playlist::StopNow(int forceStop)
{
	LogDebug(VB_PLAYLIST, "Playlist::StopNow(%d)\n", forceStop);

	// FIXME PLAYLIST, get rid of this
	if (!m_subPlaylist)
		FPPstatus = FPP_STATUS_STOPPING_NOW;

	if (m_currentSection->at(m_sectionPosition)->IsPlaying())
		m_currentSection->at(m_sectionPosition)->Stop();

	SetIdle();

	m_forceStop = forceStop;

	return 1;
}
Beispiel #13
0
void RightSide::Notify(EventHeader* event)
{
	switch (event->event_type_)
	{
	case EVENT_FIRST_CLICK:
	{
		OffShuffle();
		OffFocus();
		SetArrange();
	}break;

	case EVENT_VOTE_COMPLETE:
	{
		OffShuffle();
		Event::VoteCompleteEvent* recvEvent = (Event::VoteCompleteEvent*)event;
		OffFocus();
		for (int i = 0; i < recvEvent->objectLength; i++)
		{
			isFocus[recvEvent->object[i]] = true;
		}
	}break;

	case EVENT_SELECT:
	{
		OffShuffle();
		Event::SelectEvent* recvEvent = (Event::SelectEvent*)event;
		memset(isFocus, false, sizeof(isFocus));
		for (int i = 0; i < recvEvent->objectLength; i++)
		{
			isFocus[recvEvent->object[i]] = true;
		}
	}break;

	case EVENT_SHUFFLE:
	{
		Event::ShuffleEvent* recvEvent = (Event::ShuffleEvent*)event;
		SetIdle();
	}break;

	default:
	{
		break;
	}
	}
}
Beispiel #14
0
        void DoAction(const int32 action)
        {
            if(action == DATA_CHAINS)
            {
                SetIdle();
                SetPincers(false);
                Talk(EMOTE_IMPALE);
                events.SetPhase(PHASE_HEAD);
                Movement::MoveSplineInit init(me);
                init.SetFacing(me->GetHomePosition().GetOrientation());
                me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);

                if(Unit * passenger = veh->GetPassenger(2)) // Eject the tank
                {
                    passenger->ExitVehicle(&ejectPos);
                    passenger->RemoveAurasDueToSpell(SPELL_MANGLE);
                    passenger->RemoveAurasDueToSpell(SPELL_MANGLE_PERIODIC);
                }
                if(Unit * head = veh->GetPassenger(4)) // Make the head Visible
                {
                    head->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE);
                    head->RemoveAurasDueToSpell(SPELL_QUEST_INVIS_5);
                    if(!head->isInCombat())
                        if(Unit * victim = me->GetVictim())
                            head->SetInCombatWith(victim);
                    me->CastSpell(head, SPELL_POINT_OF_VULNERABILITY, true);
                    head->SetHealth(me->GetHealth());
                }
                if(Unit * stalker = me->FindNearestCreature(NPC_SPIKE_STALKER, 100.0f)) // Cast Arrow Visual
                    me->CastSpell(stalker, SPELL_LOCATION_MARKER, true);

                DoCast(SPELL_IMPALE_SELF);
                events.CancelEvent(EVENT_EJECT);
                events.DelayEvents(36000);
                events.ScheduleEvent(EVENT_IMPALE_END, 36000);
            }
        }
Beispiel #15
0
Playlist::Playlist(void *parent, int subPlaylist)
  : m_parent(parent),
	m_repeat(0),
	m_loop(0),
	m_loopCount(0),
	m_random(0),
	m_blankBetweenSequences(0),
	m_blankBetweenIterations(0),
	m_blankAtEnd(1),
	m_startTime(0),
	m_subPlaylistDepth(0),
	m_subPlaylist(subPlaylist),
	m_forceStop(0),
	m_fileTime(0),
	m_configTime(0),
	m_currentState("idle"),
	m_currentSectionStr("New"),
	m_sectionPosition(0),
	m_startPosition(0)
{
	SetIdle();

	SetRepeat(0);
}
Beispiel #16
0
/*******************************************************************************
* Function Name  : Speaker_NoData_Setup
* Description    : Handle the no data class specific requests.
* Input          : None.
* Output         : None.
* Return         : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
RESULT Speaker_NoData_Setup(u8 RequestNo)
{
  if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
      && (RequestNo == SET_PROTOCOL))
  {
    SetProtocol(pInformation->USBwIndex0,pInformation->USBwValue0);
    return USB_SUCCESS;
  }
  else if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
      && (RequestNo == SET_REPORT))
  {
    return USB_SUCCESS;
  }
  else if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
      && (RequestNo == SET_IDLE))
  {
    SetIdle(pInformation->USBwIndex0,pInformation->USBwValue0,pInformation->USBwValue1);
    return USB_SUCCESS;
  }
  else
  {
    return USB_UNSUPPORT;
  }
}
Beispiel #17
0
uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) {
        const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR);

        uint8_t buf[constBufSize];
        USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
        uint8_t rcode;
        UsbDevice *p = NULL;
        EpInfo *oldep_ptr = NULL;
        uint8_t len = 0;

        uint8_t num_of_conf; // number of configurations
        //uint8_t num_of_intf; // number of interfaces

        AddressPool &addrPool = pUsb->GetAddressPool();

        USBTRACE("HU Init\r\n");

        if(bAddress)
                return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;

        // Get pointer to pseudo device with address 0 assigned
        p = addrPool.GetUsbDevicePtr(0);

        if(!p)
                return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;

        if(!p->epinfo) {
                USBTRACE("epinfo\r\n");
                return USB_ERROR_EPINFO_IS_NULL;
        }

        // Save old pointer to EP_RECORD of address 0
        oldep_ptr = p->epinfo;

        // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
        p->epinfo = epInfo;

        p->lowspeed = lowspeed;

        // Get device descriptor
        rcode = pUsb->getDevDescr(0, 0, 8, (uint8_t*)buf);

        if(!rcode)
                len = (buf[0] > constBufSize) ? constBufSize : buf[0];

        if(rcode) {
                // Restore p->epinfo
                p->epinfo = oldep_ptr;

                goto FailGetDevDescr;
        }

        // Restore p->epinfo
        p->epinfo = oldep_ptr;

        // Allocate new address according to device class
        bAddress = addrPool.AllocAddress(parent, false, port);

        if(!bAddress)
                return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;

        // Extract Max Packet Size from the device descriptor
        epInfo[0].maxPktSize = udd->bMaxPacketSize0;

        // Assign new address to the device
        rcode = pUsb->setAddr(0, 0, bAddress);

        if(rcode) {
                p->lowspeed = false;
                addrPool.FreeAddress(bAddress);
                bAddress = 0;
                USBTRACE2("setAddr:", rcode);
                return rcode;
        }

        //delay(2); //per USB 2.0 sect.9.2.6.3

        USBTRACE2("Addr:", bAddress);

        p->lowspeed = false;

        p = addrPool.GetUsbDevicePtr(bAddress);

        if(!p)
                return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;

        p->lowspeed = lowspeed;

        if(len)
                rcode = pUsb->getDevDescr(bAddress, 0, len, (uint8_t*)buf);

        if(rcode)
                goto FailGetDevDescr;

        VID = udd->idVendor; // Can be used by classes that inherits this class to check the VID and PID of the connected device
        PID = udd->idProduct;

        num_of_conf = udd->bNumConfigurations;

        // Assign epInfo to epinfo pointer
        rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);

        if(rcode)
                goto FailSetDevTblEntry;

        USBTRACE2("NC:", num_of_conf);

        for(uint8_t i = 0; i < num_of_conf; i++) {
                //HexDumper<USBReadParser, uint16_t, uint16_t> HexDump;
                ConfigDescParser<USB_CLASS_HID, 0, 0,
                        CP_MASK_COMPARE_CLASS> confDescrParser(this);

                //rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump);
                rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);

                if(rcode)
                        goto FailGetConfDescr;

                if(bNumEP > 1)
                        break;
        } // for

        if(bNumEP < 2)
                return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;

        // Assign epInfo to epinfo pointer
        rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);

        USBTRACE2("Cnf:", bConfNum);

        // Set Configuration Value
        rcode = pUsb->setConf(bAddress, 0, bConfNum);

        if(rcode)
                goto FailSetConfDescr;

        for(uint8_t i = 0; i < bNumIface; i++) {
                if(hidInterfaces[i].epIndex[epInterruptInIndex] == 0)
                        continue;

                rcode = SetIdle(hidInterfaces[i].bmInterface, 0, 0);

                if(rcode && rcode != hrSTALL)
                        goto FailSetIdle;
        }

        USBTRACE("HU configured\r\n");

        OnInitSuccessful();

        bPollEnable = true;
        return 0;

FailGetDevDescr:
#ifdef DEBUG_USB_HOST
        NotifyFailGetDevDescr();
        goto Fail;
#endif

FailSetDevTblEntry:
#ifdef DEBUG_USB_HOST
        NotifyFailSetDevTblEntry();
        goto Fail;
#endif

FailGetConfDescr:
#ifdef DEBUG_USB_HOST
        NotifyFailGetConfDescr();
        goto Fail;
#endif

FailSetConfDescr:
#ifdef DEBUG_USB_HOST
        NotifyFailSetConfDescr();
        goto Fail;
#endif


FailSetIdle:
#ifdef DEBUG_USB_HOST
        USBTRACE("SetIdle:");
#endif

#ifdef DEBUG_USB_HOST
Fail:
        NotifyFail(rcode);
#endif
        Release();
        return rcode;
}
Beispiel #18
0
int Playlist::Start(void)
{
	LogDebug(VB_PLAYLIST, "Playlist::Start()\n");

	if ((!m_leadIn.size()) &&
		(!m_mainPlaylist.size()) &&
		(!m_leadOut.size()))
	{
		SetIdle();
		return 0;
	}

	// FIXME PLAYLIST, get rid of this
	if (!m_subPlaylist)
		FPPstatus = FPP_STATUS_PLAYLIST_PLAYING;

	m_currentState = "playing";

	m_startTime = GetTime();
	m_loop = 0;
	m_forceStop = 0;

	LogDebug(VB_PLAYLIST, "============================================================================\n");

	if (m_startPosition > 0)
	{
		if (m_startPosition >= (m_leadIn.size() + m_mainPlaylist.size() + m_leadOut.size()))
			m_startPosition = 0;

		if (m_startPosition >= (m_leadIn.size() + m_mainPlaylist.size()))
		{
			m_sectionPosition = m_startPosition - (m_leadIn.size() + m_mainPlaylist.size());
			m_currentSectionStr = "LeadOut";
			m_currentSection = &m_leadOut;
		}
		else if (m_startPosition >= m_leadIn.size())
		{
			m_sectionPosition = m_startPosition - m_leadIn.size();
			m_currentSectionStr = "MainPlaylist";
			m_currentSection = &m_mainPlaylist;
		}
		else
		{
			m_sectionPosition = m_startPosition;
			m_currentSectionStr = "LeadIn";
			m_currentSection = &m_leadIn;
		}
	}
	else
	{
		if (m_leadIn.size())
		{
			m_currentSectionStr = "LeadIn";
			m_currentSection = &m_leadIn;
		}
		else if (m_mainPlaylist.size())
		{
			m_currentSectionStr = "MainPlaylist";
			m_currentSection = &m_mainPlaylist;
		}
		else // must be only lead Out
		{
			m_currentSectionStr = "LeadOut";
			m_currentSection = &m_leadOut;
		}

		m_sectionPosition = 0;
	}


	m_currentSection->at(m_sectionPosition)->StartPlaying();

	if (mqtt)
	{
		mqtt->Publish("status", m_currentState.c_str());
		mqtt->Publish("playlist/section/status", m_currentSectionStr);
		mqtt->Publish("playlist/sectionPosition/status", m_sectionPosition);
	}

	return 1;
}
Beispiel #19
0
void CFlowNode_AIStateGuard::OnEndActGoto()
{
	ResetGoalpipe();
	m_State = CryGetTicks() + GetPortFloat(&m_ActInfo, INPORT_DELAY) * gEnv->pTimer->GetTicksPerSecond(); //Pause
	SetIdle();
}
Beispiel #20
0
void CFlowNode_AIStateGuard::OnBehaviorEnd()
{
	SetIdle(false);
	SetUpdates(false, &m_ActInfo);
}
Beispiel #21
0
int Playlist::Process(void)
{
	//LogExcess(VB_PLAYLIST, "Playlist::Process: %s, section %s, position: %d\n", m_name.c_str(), m_currentSectionStr.c_str(), m_sectionPosition);

	if (m_sectionPosition >= m_currentSection->size())
	{
		LogErr(VB_PLAYLIST, "Section position %d is outside of section %s\n",
			m_sectionPosition, m_currentSectionStr.c_str());
		StopNow();
		return 0;
	}

//	if (FPPstatus == FPP_STATUS_STOPPING_NOW)
//	{
//		if (m_currentSection->at(m_sectionPosition)->IsPlaying())
//			m_currentSection->at(m_sectionPosition)->Stop();
//
//		SetIdle();
//		return 1;
//	}

	if (m_currentSection->at(m_sectionPosition)->IsPlaying())
		m_currentSection->at(m_sectionPosition)->Process();

	if (m_currentSection->at(m_sectionPosition)->IsFinished())
	{
		LogDebug(VB_PLAYLIST, "Playlist entry finished\n");
		if ((logLevel & LOG_DEBUG) && (logMask & VB_PLAYLIST))
			m_currentSection->at(m_sectionPosition)->Dump();

		LogDebug(VB_PLAYLIST, "============================================================================\n");

		if (FPPstatus == FPP_STATUS_STOPPING_GRACEFULLY)
		{
			if ((m_currentSectionStr == "LeadIn") ||
				(m_currentSectionStr == "MainPlaylist"))
			{
				ReloadIfNeeded();

				if (m_leadOut.size())
				{
					LogDebug(VB_PLAYLIST, "Stopping Gracefully\n");
					SwitchToLeadOut();
				}
				else {
					SetIdle();
				}
				return 1;
			}
		}

		if (m_currentSection->at(m_sectionPosition)->GetNextSection() != "")
		{
			LogDebug(VB_PLAYLIST, "Attempting Switch to %s section.\n",
				m_currentSection->at(m_sectionPosition)->GetNextSection().c_str());

			if (m_currentSection->at(m_sectionPosition)->GetNextSection() == "leadIn")
			{
				m_currentSectionStr = "LeadIn";
				m_currentSection = &m_leadIn;
			}
			else if (m_currentSection->at(m_sectionPosition)->GetNextSection() == "leadOut")
			{
				m_currentSectionStr = "LeadOut";
				m_currentSection = &m_leadOut;
			}
			else
			{
				m_currentSectionStr = "MainPlaylist";
				m_currentSection = &m_mainPlaylist;
			}

			if (m_currentSection->at(m_sectionPosition)->GetNextItem() == -1)
				m_sectionPosition = 0;
			else if (m_currentSection->at(m_sectionPosition)->GetNextItem() < m_currentSection->size())
				m_sectionPosition = m_currentSection->at(m_sectionPosition)->GetNextItem();
			else
				m_sectionPosition = 0;
		}
		else if (m_currentSection->at(m_sectionPosition)->GetNextItem() != -1)
		{
			if (m_currentSection->at(m_sectionPosition)->GetNextItem() < m_currentSection->size())
				m_sectionPosition += m_currentSection->at(m_sectionPosition)->GetNextItem();
			else
				m_sectionPosition = m_currentSection->size();
		}
		else
		{
			m_sectionPosition++;
		}

		if (m_sectionPosition >= m_currentSection->size())
		{
			if (m_currentSectionStr == "LeadIn")
			{
				LogDebug(VB_PLAYLIST, "At end of leadIn.\n");

				ReloadIfNeeded();

				if (m_mainPlaylist.size())
				{
					SwitchToMainPlaylist();
				}
				else if (m_leadOut.size())
				{
					SwitchToLeadOut();
				}
				else
				{
					LogDebug(VB_PLAYLIST, "No more playlist entries, switching to idle.\n");
					SetIdle();
				}
			}
			else if (m_currentSectionStr == "MainPlaylist")
			{
				m_loop++;
				LogDebug(VB_PLAYLIST, "mainPlaylist loop now: %d\n", m_loop);
				if ((m_repeat) && (!m_loopCount || (m_loop < m_loopCount)))
				{
					ReloadIfNeeded();

					if (FPPstatus == FPP_STATUS_STOPPING_GRACEFULLY_AFTER_LOOP)
					{
						if (m_leadOut.size())
						{
							LogDebug(VB_PLAYLIST, "Stopping Gracefully after loop\n");
							SwitchToLeadOut();
						}
						else
						{
							LogDebug(VB_PLAYLIST, "Stopping Gracefully after loop. Empty leadOut, setting to Idle state\n");
							SetIdle();
						}

						return 1;
					}

					if (!m_loopCount)
						LogDebug(VB_PLAYLIST, "mainPlaylist repeating for another loop, loopCount == 0\n");
					else
						LogDebug(VB_PLAYLIST, "mainPlaylist repeating for another loop, %d <= %d\n", m_loop, m_loopCount);

					m_sectionPosition = 0;
					m_mainPlaylist[0]->StartPlaying();
				}
				else if (m_leadOut.size())
				{
					ReloadIfNeeded();

					SwitchToLeadOut();
				}
				else
				{
					LogDebug(VB_PLAYLIST, "No more playlist entries, switching to idle.\n");
					SetIdle();
				}
			}
			else
			{
				LogDebug(VB_PLAYLIST, "No more playlist entries, switching to idle.\n");
				SetIdle();
			}
		}
		else
		{
			// Start the next item in the current section
			m_currentSection->at(m_sectionPosition)->StartPlaying();
		}

		if (mqtt)
		{
			mqtt->Publish("playlist/section/status", m_currentSectionStr);
			mqtt->Publish("playlist/sectionPosition/status", m_sectionPosition);
		}
	}

	return 1;
}
Beispiel #22
0
        void UpdateAI(const uint32 diff)
        {
            if(!UpdateVictim())
                return;

            events.Update(diff);

            if(enrageTimer <= diff)
            {
                DoCast(SPELL_BERSERK);
                enrageTimer = 600000;
            }else enrageTimer -= diff;

            if(uint32 eventId = events.ExecuteEvent())
            {
                switch(eventId)
                {
                    case EVENT_LAVA_SPEW:
                        DoCast(me, SPELL_LAVA_SPEW);
                        events.ScheduleEvent(EVENT_LAVA_SPEW, urand(15000, 20000), 0, PHASE_NORMAL);
                        break;
                    case EVENT_MAGMA_SPIT:
                        if(Unit * victim = me->GetVictim())
                        {
                            float dist = me->GetDistance(victim);
                            if(dist >= 60.0f)
                                EnterEvadeMode();
                            else if(dist >= INTERACTION_DISTANCE)
                                DoCast(victim, SPELL_MAGMA_SPIT, true);
                        }
                        events.ScheduleEvent(EVENT_MAGMA_SPIT, urand(3000, 5000), 0, PHASE_NORMAL);
                        break;
                    case EVENT_PILLAR_OF_FLAME:
                        {
                            Unit * target = SelectTarget(SELECT_TARGET_RANDOM, 0, -15.0f, true);
                            if(!target)
                                target = SelectTarget(SELECT_TARGET_RANDOM, 0, 0.0f, true);
                            if(target)
                                me->SummonCreature(NPC_PILLAR_OF_FLAME_TRIGGER, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), 0.0f, TEMPSUMMON_TIMED_DESPAWN, 20000);
                            Talk(EMOTE_PILLAR);
                            DoCast(me, SPELL_PILLAR_OF_FLAME);
                            events.ScheduleEvent(EVENT_PILLAR_OF_FLAME, 30000, 0, PHASE_NORMAL);
                        }
                        break;
                    case EVENT_MANGLE:
                        DoCastVictim(SPELL_MANGLE, true);
                        SetIdle();

                        events.ScheduleEvent(EVENT_MANGLE, 95000);
                        events.ScheduleEvent(EVENT_IGNITION, 2000);
                        events.SetPhase(PHASE_HEAD);
                        break;
                    case EVENT_IGNITION:
                    {
                        bool pos = urand(0, 1);
                        Movement::MoveSplineInit init(me);
                        init.SetFacing(pos ? 4.7f : 3.47f);

                        std::list<Position> summonPos;
                          for (uint8 i = 0; i < 8; i++)
                            me->SummonCreature(NPC_IGNITION_TRIGGER, me->GetPositionX() + i, me->GetPositionY() + i, me->GetPositionZ(), 1.5f, TEMPSUMMON_TIMED_DESPAWN, 65100);
                            summonPos.clear();
                        events.DelayEvents(10000);
                        events.ScheduleEvent(EVENT_MASSIVE_CRASH, 3000);
                        events.ScheduleEvent(EVENT_EJECT, 40000);
                        break;
                    }
                    case EVENT_MASSIVE_CRASH:
                        Talk(EMOTE_CRASH);
                        DoCast(SPELL_MASSIVE_CRASH);
                        me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
                        SetPincers(true);
                        events.ScheduleEvent(EVENT_MASSIVE_CRASH_END, 10000);
                        break;
                    case EVENT_IMPALE_END:
                        if(Unit * head = veh->GetPassenger(4)) // make the head unattackable
                        {
                            head->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE);
                            head->CastSpell(head, SPELL_QUEST_INVIS_5, true);
                        }
                        me->RemoveAurasDueToSpell(SPELL_CHAIN_R);
                        me->RemoveAurasDueToSpell(SPELL_CHAIN_L);
                        events.RescheduleEvent(EVENT_MAGMA_SPIT, 5000);
                        events.RescheduleEvent(EVENT_LAVA_SPEW, 8000);
                        events.RescheduleEvent(EVENT_MAGMA_SPIT, urand(8000, 10000));
                        events.RescheduleEvent(EVENT_PILLAR_OF_FLAME, urand(8000, 12000));
                        events.RescheduleEvent(EVENT_MANGLE, urand(25000, 30000));
                    case EVENT_MASSIVE_CRASH_END:
                        me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
                        me->SetReactState(REACT_AGGRESSIVE);
                        events.SetPhase(PHASE_NORMAL);
                        if(Unit * victim = me->GetVictim()) // resume combat
                        {
                            DoStartNoMovement(victim);
                            me->SetUInt64Value(UNIT_FIELD_TARGET, victim->GetGUID());
                        }
                        break;
                    case EVENT_EJECT:
                        // Tank in seat 3 will be dead by then
                        SetPincers(false);
                        break;
                    case EVENT_BLAZING_INFERNO:
                        if(Creature * nefarian = me->GetCreature(*me, nefarianGUID))
                            if(Unit * target = SelectTarget(SELECT_TARGET_RANDOM, 0, -5.0f, true))
                                nefarian->CastSpell(target, SPELL_BLAZING_INFERNO, true);
                        events.ScheduleEvent(EVENT_BLAZING_INFERNO, urand(20000, 25000));
                        break;
                    case EVENT_SHADOWFLAME_BARRAGE:
                        if(Creature * nefarian = me->GetCreature(*me, nefarianGUID))
                        {
                            if(nefarian->HasUnitState(UNIT_STATE_CASTING))
                                events.ScheduleEvent(EVENT_SHADOWFLAME_BARRAGE, 200);
                            else
                            {
                                nefarian->CastSpell(nefarian, SPELL_SHADOWFLAME_BARRAGE, false);
                                events.ScheduleEvent(EVENT_SHADOWFLAME_BARRAGE, 2100);
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            DoMeleeAttackIfReady();
        }
uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed)
{
	const uint8_t constBufSize = sizeof(USB_DEVICE_DESCRIPTOR);

	uint8_t		buf[constBufSize];
	uint8_t		rcode;
	UsbDevice	*p = NULL;
	EpInfo		*oldep_ptr = NULL;
	uint8_t		len = 0;
	uint16_t	cd_len = 0;

	uint8_t		num_of_conf;	// number of configurations
	uint8_t		num_of_intf;	// number of interfaces

	AddressPool	&addrPool = pUsb->GetAddressPool();

	USBTRACE("HU Init\r\n");

	if (bAddress)
		return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;

	// Get pointer to pseudo device with address 0 assigned
	p = addrPool.GetUsbDevicePtr(0);

	if (!p)
		return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;

	if (!p->epinfo)
	{
		USBTRACE("epinfo\r\n");
		return USB_ERROR_EPINFO_IS_NULL;
	}

	// Save old pointer to EP_RECORD of address 0
	oldep_ptr = p->epinfo;

	// Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
	p->epinfo = epInfo;

	p->lowspeed = lowspeed;

	// Get device descriptor
	rcode = pUsb->getDevDescr( 0, 0, 8, (uint8_t*)buf );

	if  (!rcode)
		len = (buf[0] > constBufSize) ? constBufSize : buf[0];

	if( rcode ) 
	{
		// Restore p->epinfo
		p->epinfo = oldep_ptr;

		goto FailGetDevDescr;
	}

	// Restore p->epinfo
	p->epinfo = oldep_ptr;

	// Allocate new address according to device class
	bAddress = addrPool.AllocAddress(parent, false, port);

	if (!bAddress)
		return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;

	// Extract Max Packet Size from the device descriptor
	epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; 

	// Assign new address to the device
	rcode = pUsb->setAddr( 0, 0, bAddress );

	if (rcode)
	{
		p->lowspeed = false;
		addrPool.FreeAddress(bAddress);
		bAddress = 0;
		USBTRACE2("setAddr:",rcode);
		return rcode;
	}

	USBTRACE2("Addr:", bAddress);

	p->lowspeed = false;

	p = addrPool.GetUsbDevicePtr(bAddress);

	if (!p)
		return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;

	p->lowspeed = lowspeed;

	if (len)
		rcode = pUsb->getDevDescr( bAddress, 0, len, (uint8_t*)buf );

	if(rcode) 
		goto FailGetDevDescr;

	num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations;

	// Assign epInfo to epinfo pointer
	rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);

	if (rcode)
		goto FailSetDevTblEntry;

	USBTRACE2("NC:", num_of_conf);

	for (uint8_t i=0; i<num_of_conf; i++)
	{
		HexDumper<USBReadParser, uint16_t, uint16_t>		HexDump;
		ConfigDescParser<USB_CLASS_HID, 0, 0, 
			CP_MASK_COMPARE_CLASS>							confDescrParser(this);

		rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump);
		rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
		
		if (bNumEP > 1)
			break;
	} // for
	
	if (bNumEP < 2)
		return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;

	// Assign epInfo to epinfo pointer
	rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);

	USBTRACE2("\r\nCnf:", bConfNum);

	// Set Configuration Value
	//rcode = pUsb->setConf(bAddress, 0, 0);
	rcode = pUsb->setConf(bAddress, 0, bConfNum);

	if (rcode)
		goto FailSetConfDescr;

	for (uint8_t i=0; i<bNumIface; i++)
	{
		if (hidInterfaces[i].epIndex[epInterruptInIndex] == 0)
			continue;

		USBTRACE("Proto\r\n");

		//rcode = SetProtocol(hidInterfaces[i].bmInterface, HID_RPT_PROTOCOL);

		//if (rcode)
		//	goto FailSetProtocol;

		rcode = SetIdle(hidInterfaces[i].bmInterface, 0, 0);

		if (rcode)
			goto FailSetIdle;
	}

	USBTRACE("HU configured\r\n");

	{
		HexDumper<USBReadParser, uint16_t, uint16_t>    Hex;
		ReportDescParser                                Rpt;

		if (rcode = GetReportDescr(0, &Hex))
			goto FailGetReportDescr;
	        
		if (rcode = GetReportDescr(0, &Rpt))
			goto FailGetReportDescr;
	}
	bPollEnable = true;
	return 0;

FailGetDevDescr:
	USBTRACE("getDevDescr:");
	goto Fail;

FailSetDevTblEntry:
	USBTRACE("setDevTblEn:");
	goto Fail;

FailGetConfDescr:
	USBTRACE("getConf:");
	goto Fail;

FailSetConfDescr:
	USBTRACE("setConf:");
	goto Fail;

FailSetProtocol:
	USBTRACE("SetProto:");
	goto Fail;

FailSetIdle:
	USBTRACE("SetIdle:");
	goto Fail;

FailGetReportDescr:
	USBTRACE("GetReportDescr:");
	goto Fail;

Fail:
	Serial.println(rcode, HEX);
	Release();
	return rcode;
}