Exemplo n.º 1
0
TEST
test_Enqueue(){
	Queue q;
	Node *newItem, *newItem2, *newItem3;
	InitQueue(&q);
	
	newItem = NewItem();
	
	//add item to queue
	AddQueue(&q, newItem);

	ASSERT(q.head == newItem);
	ASSERT(q.tail == newItem);
	ASSERT(q.count == 1);

	newItem2 = NewItem();
	AddQueue(&q, newItem2);

	//make sure that head val has not changed, and only tail val has changed
	ASSERT(q.head == newItem);
	ASSERT(q.tail == newItem2);
	ASSERT(q.count == 2);
	//head should point at tail
	ASSERT(q.head->next == q.tail);

	//one more for good measure
	newItem3 = NewItem();
	AddQueue(&q, newItem3);
	//head has not changed, as we add to the end
	ASSERT(q.head == newItem);
	//tail is our new item
	ASSERT(q.tail == newItem3);
	//count updated correctly
	ASSERT(q.count == 3);
	//head.prev points to tail
	ASSERT(q.head->prev == q.tail);
	//head.next does not point to tail, points to middle
	ASSERT(q.head->next == newItem2);
	//3 items, all connected
	ASSERT(q.head->next->next == q.tail);
	//tail.next == head
	ASSERT(q.tail->next == q.head);
	
	//free items
	FreeItem(newItem);
	FreeItem(newItem2);
	FreeItem(newItem3);


	PASS();
}
Exemplo n.º 2
0
// right - left >= 0  ---> 1, otherwise 0
// down - top >= 0  ---> 1, otherwise 0
void CompactColor(unsigned char *CompactValue, double *HistogramValue)
{
	qdata		*pop, Queue[NUM_BINS];
	int			qfront = 0, qrear = 0;
	int			width = 8;		// 8x8 = 64
	int			i, j, jj, count;
	double		left, right;

	AddQueue(Queue, &qrear, 0, 0, 8, 8, 0);

	count = 0;
	while( (pop=DeleteQueue(Queue, &qfront, qrear)) )
	{
		left = right = 0;			// left also denote top, right also denote down
		if( pop->flag == 0 )		// right - left
		{
			for(j=pop->posY, jj=pop->posY*width; j<pop->posY+pop->sizeY; j++, jj+=width)
				for(i=pop->posX; i<pop->posX+pop->sizeX/2; i++)
					left += HistogramValue[jj+i];
			for(j=pop->posY, jj=pop->posY*width; j<pop->posY+pop->sizeY; j++, jj+=width)
				for(i=pop->posX+pop->sizeX/2; i<pop->posX+pop->sizeX; i++)
					right += HistogramValue[jj+i];
		}
		else						// down - top
		{
			for(j=pop->posY, jj=pop->posY*width; j<pop->posY+pop->sizeY/2; j++, jj+=width)
				for(i=pop->posX; i<pop->posX+pop->sizeX; i++)
					left += HistogramValue[jj+i];
			for(j=pop->posY+pop->sizeY/2, jj=(pop->posY+pop->sizeY/2)*width; j<pop->posY+pop->sizeY; j++, jj+=width)
				for(i=pop->posX; i<pop->posX+pop->sizeX; i++)
					right += HistogramValue[jj+i];
		}

		CompactValue[count] = (right>left) ? 1 : 0;
		count ++;

		// push into queue
		if( pop->flag == 0 && pop->sizeX > 1 )
		{
			AddQueue(Queue, &qrear, pop->posX, pop->posY, pop->sizeX/2, pop->sizeY, 1);
			AddQueue(Queue, &qrear, pop->posX+pop->sizeX/2, pop->posY, pop->sizeX/2, pop->sizeY, 1);
		}
		else if( pop->flag == 1 && pop->sizeY > 2 )
		{
			AddQueue(Queue, &qrear, pop->posX, pop->posY, pop->sizeX, pop->sizeY/2, 0);
			AddQueue(Queue, &qrear, pop->posX, pop->posY+pop->sizeY/2, pop->sizeX, pop->sizeY/2, 0);
		}
	}
}
Exemplo n.º 3
0
TEST
test_RotateQ(){

	Queue q;
	InitQueue(&q);
	Node *newItem1, *newItem2, *newItem3, *newItem4;

	newItem1 = NewItem();
	newItem2 = NewItem();
	newItem3 = NewItem();
	newItem4 = NewItem();

	AddQueue(&q, newItem1);
	AddQueue(&q, newItem2);
	AddQueue(&q, newItem3);
	AddQueue(&q, newItem4);

	//Queue is 1 2 3 4
	ASSERT(q.head == newItem1);
	ASSERT(q.tail == newItem4);

	RotateQ(&q);
	//Queue is 2 3 4 1
	ASSERT(q.head == newItem2);
	ASSERT(q.tail == newItem1);

	RotateQ(&q);
	//Queue is 3 4 1 2
	ASSERT(q.head == newItem3);
	ASSERT(q.tail == newItem2);

	RotateQ(&q);
	//Queue is 4 1 2 3
	ASSERT(q.head == newItem4);
	ASSERT(q.tail == newItem3);

	RotateQ(&q);
	//Queue is 1 2 3 4
	ASSERT(q.head == newItem1);
	ASSERT(q.tail == newItem4);

	FreeItem(newItem1);
	FreeItem(newItem2);
	FreeItem(newItem3);
	FreeItem(newItem4);
	
	PASS();
}
Exemplo n.º 4
0
int main(void)
{
	Stack s1;
	Stack s2;
	s1 = CreateStack(10);
	s2 = CreateStack(10);
	Item it = 1;
	AddQueue(it, s1,s2);
	it = 2;
	AddQueue(it,s1,s2);
	it = 3;
	AddQueue(it,s1,s2);
	DeleteQueue(&it,s1,s2);
	printf("%d\n",it);
	DeleteQueue(&it,s1,s2);
	printf("%d\n",it);
	DeleteQueue(&it,s1,s2);
	printf("%d\n",it);
}
Exemplo n.º 5
0
void BFS(LGraph Graph ,Vertex V , void (*Visit)(Vertex) )
{
    Queue  queue;
    Vertex v;
    PtrToAdjVNode w;
    queue = CreateQueue(20);
    AddQueue(queue,V);
    VisitedBFS[V] = 1;/*标记已经访问*/
	Visit(V);
	while(queue->front != queue->rear){/*队列不为空*/
        v = DeleteQueue(queue);
        for(w = Graph->G[v].FirstEdge ; w != NULL ; w = w->next )
            if(VisitedBFS[w->AdjV] == 0){
				AddQueue(queue,w->AdjV);
				VisitedBFS[w->AdjV] = 1;
				Visit(w->AdjV);
			}
        
    }     
} 
Exemplo n.º 6
0
void ThreadContrl::StartMonitor(Monitor *pMonitor)
{
	MonitorThread *pThread=(MonitorThread*)GetIdleThread();
	if(pThread==NULL)
	{
		m_isThreadPoolFull=TRUE;
		AddQueue(pMonitor);
		return ;
	}
	pThread->ExecuteMonitor(pMonitor);


}
void
tmTransactionManager::HandleTransaction(tmTransaction *aTrans) {

  PRUint32 action = aTrans->GetAction();
  PRUint32 ownerID = aTrans->GetOwnerID();
  tmQueue *queue = nsnull;

  // get the right queue -- attaches do it differently
  if (action == TM_ATTACH) {
    const char *name = (char*) aTrans->GetMessage(); // is qName for Attaches
    queue = GetQueue(name);  
    if (!queue) {
      PRInt32 index = AddQueue(name);
      if (index >= 0)
        queue = GetQueue(index); // GetQueue may return nsnull
    }
  }
  else  // all other trans should have a valid queue ID already
    queue = GetQueue(aTrans->GetQueueID());

  if (queue) {
    // All possible actions should have a case, default is not valid
    //   delete trans when done with them, let the queue own the trans
    //   that are posted to them.
    PRInt32 result = 0;
    switch (action) {
    case TM_ATTACH:
      queue->AttachClient(ownerID);
      break;
    case TM_POST:
      result = queue->PostTransaction(aTrans);
      if (result >= 0) // post failed, aTrans cached in a tmQueue
        return;
      break;
    case TM_FLUSH:
      queue->FlushQueue(ownerID);
      break;
    case TM_DETACH:
      if (queue->DetachClient(ownerID) == TM_SUCCESS_DELETE_QUEUE) {
        // the last client has been removed, remove the queue
        RemoveQueue(aTrans->GetQueueID()); // this _could_ be out of bounds
      }
      break;
    default:
      PR_NOT_REACHED("bad action in the transaction");
    }
  }
  delete aTrans;
}
Exemplo n.º 8
0
void IPCQueueEvent(int argc, char** argv, PLSOBJECT Object)
{
	char* Name = argv[0];
	LSTypeDefinition* Type = pLSInterface->FindLSType(argv[1]);
	char* SubType = argv[2];
	char* Method = argv[3];

	LSOBJECT queueobject;
	if((queueobject.Ptr = FindQueue(Name)) == 0)
	{
		queueobject.Ptr = new LSQueue(Type, SubType);
		AddQueue(Name, (LSQueue*)queueobject.Ptr);
	}
	pQueueType->GetMethodEx(queueobject.GetObjectData(), Method, argc - 4, &argv[4]);
}
Exemplo n.º 9
0
void main()
{
	Queue *queue = NULL;
	Element item;
	queue = CreateQueue();

	item.key = 1;
	printf("Add ist element into the queue.\n");
	AddQueue(queue, item);
	PrintQueue(queue);

	printf("Add 2st element into the queue.\n");
	item.key = 2;
	AddQueue(queue, item);
	PrintQueue(queue);

	printf("Add 2st element into the queue.\n");
	item.key = 3;
	AddQueue(queue, item);
	PrintQueue(queue);

	printf("Add 2st element into the queue.\n");
	item.key = 4;
	AddQueue(queue, item);
	PrintQueue(queue);

	printf("Delete the top element from the queue.\n");
	item = DeleteQueue(queue);
	printf("Delete %d\n", item.key);
	PrintQueue(queue);

	printf("Destroy the queue.\n");
	DestoryQueue(queue);

	PrintQueue(queue);
}
Exemplo n.º 10
0
Monitor *ThreadContrl::PopMonitorInQueue(Monitor *pMonitor)
{
	Monitor *pmt=NULL;

	if(pMonitor->GetQueueIndex()>=0)
		pmt=m_pTaskQueueManager->Pop(pMonitor->GetQueueIndex());
	else
		pmt=m_pTaskQueueManager->Pop((LPCSTR)pMonitor->GetMonitorClass());

	if(pmt!=NULL)
	{
		AddQueue(pMonitor);
		return pmt;
	}

	return pMonitor;
}
Exemplo n.º 11
0
void keyboard_irq(int irq, struct pt_regs *regs)
{
    int modifiers;
    int key;

    modifiers = psiongetchar();
    key = (modifiers & 0x00FF);

    /* no key pressed */
    if (key == 0) {
	key_repeat = 0;
	last_key = 0;
	return;
    }

    if (key == last_key) {
	if (key_repeat < 5) {
	    key_repeat++;
	    return;
	}
    }

    last_key = key;
    key_repeat = 0;

    if (modifiers & PSION) {
	if (key == 0x31 && power_state == 1)	/* Psion + 1 */
	    power_off();

	if (key == 0x20 && power_state == 0)	/* Psion + Space */
	    power_on();

	return;
    }

    if (power_state == 0)
	return;			/* prevent key presses when off */

    if (modifiers & MENU) {
	if (key < 0x40 && key > 0x30) {	/* MENU + 1..9 */

#ifdef CONFIG_SIBO_VIRTUAL_CONSOLE

	    Console_set_vc(key - 0x31);

#else

	    AddQueue(ESC);
	    AddQueue(key - 0x31 + 'a');

#endif

	    return;
	}
    }

    switch (key) {
    case 0x18:			/* Arrow up */
	AddQueue(ESC);
	AddQueue('A');
	return;
    case 0x19:			/* Arrow down */
	AddQueue(ESC);
	AddQueue('B');
	return;
    case 0x1A:			/* Arrow right */
	AddQueue(ESC);
	AddQueue('C');
	return;
    case 0x1B:			/* Arrow left */
	AddQueue(ESC);
	AddQueue('D');
	return;
    default:
	AddQueue(key);
	return;
    }
}
Exemplo n.º 12
0
bool IPCQueueType::GetMethod(LSOBJECTDATA &ObjectData, PLSTYPEMETHOD pMethod, int argc, char *argv[])
{
/*******************************************
 * Parameters
 *
 * [in] LSOBJECTDATA ObjectData: ObjectData is a 32-bit value that can be accessed in any number of different ways
 *        by way of union.  Most commonly, ObjectData.Ptr, ObjectData.DWord, or ObjectData.CharPtr are useful.  This
 *        value is the representation of some object of this object type.  "ipcfoo" works on IPCFoo*
 *        so ObjectData is a IPCFoo*
 *
 * [in] PLSTYPEMETHOD pMethod: pMethod is a pointer to the information on the method to be retrieved, including its
 *        Name and ID.  We use the ID in a switch statement in order to quickly process the method, since the Name
 *        has already been resolved by the LavishScript engine.
 *
 * [in] int argc, char *argv[]: argc and argv are *nearly* standard C console program parameters.  The difference here
 *        is that the name of the method is NOT given as the first argument (in contrast to LavishScript commands).
 *        Therefore, argc is 0 unless arguments are specifically given to the method retrieval.
 */

/*******************************************
 * Return Value
 *
 * The return value for this function is very simple.  If the method execution fails for any reason, OR the object
 * is destroyed during execution, return false.  Otherwise, return true (indicating the object still exists AND
 * the method execution succeeded).
 *
 */
	/* Validate the pointer */
	if (!pQueue)
		return false;

	/* Perform the given member retrieval */
	switch(pMethod->ID)
	{
	case Queue:
		pQueue->Queue->Queue(argc, argv);
		QueueRelay(pQueue->IPCName, pQueue->Type->GetName(), pQueue->SubType, "Queue", argc, argv);
		return true;
	case Dequeue:
		pQueue->Queue->Dequeue();
		QueueRelay(pQueue->IPCName, pQueue->Type->GetName(), pQueue->SubType, "Dequeue", argc, argv);
		return true;
	case Clear:
		pQueue->Queue->Clear();
		QueueRelay(pQueue->IPCName, pQueue->Type->GetName(), pQueue->SubType, "Clear", argc, argv);
		return true;
	case Set:
	case SetIPCName:
		if(argc)
		{
			LSQueue *newQueue;
			strncpy(pQueue->IPCName, argv[0], sizeof(pQueue->IPCName));
			if((newQueue=FindQueue(pQueue->IPCName))==0)
			{
				newQueue = new LSQueue(pQueue->Type, pQueue->SubType);
				AddQueue(pQueue->IPCName, newQueue);
			}
			pQueue->Queue = newQueue;
			return true;
		}
		return false;
	case GetIterator:
		LSOBJECT iteratorobject;
		if(argc)
		{
			//printf("%s %s %d", argv[0], pQueue->IPCName, pQueue->Queue->GetContainerUsed());
			if(pLSInterface->DataParse(argv[0], iteratorobject))
			{
				return InitializeIterator(pQueue->Queue, 0, iteratorobject);
			}
		}
		return false;
	}
	return false;
}
Exemplo n.º 13
0
void
ProcessEntryPointEvent(
    DEBUG_EVENT64 * pde,
    HTHDX           hthdx
    )
/*++

Routine Description:

    This handles task start events after the first one.

Arguments:


Return Value:


--*/
{
#if defined(i386) && !defined(WIN32S)
    IMAGE_NOTE  in;
    LPBYTE      lpb;
    DWORD       cbRead;
    int         b;
    char        szName0[_MAX_FNAME + _MAX_EXT];
    char        szName1[_MAX_FNAME + _MAX_EXT];
    char        szExt  [_MAX_EXT];


    lpb = (LPBYTE)pde->
            u.Exception.ExceptionRecord.ExceptionInformation[2];
    b = DbgReadMemory(hthdx->hprc,
                      (UINT_PTR)lpb,
                      &in,
                      sizeof(in),
                      &cbRead);

    if ((b == 0) || (cbRead != sizeof(in))) {
        b = GetLastError();
    } else {
        _splitpath(in.FileName, NULL, NULL, szName0, szExt);
        _tcscat(szName0, szExt);
        _splitpath(nameBuffer, NULL, NULL, szName1, szExt);
        _tcscat(szName1, szExt);

        if (_strcmpi(szName0, szName1) == 0) {
            *nameBuffer = 0;
            //hthdx->hprc->pstate &= ~ps_preEntry;
            //hthdx->tstate |= ts_stopped;
			hthdx->hprc->pstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ps_preEntry));
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_stopped));
            NotifyEM(pde, hthdx, 0, ENTRY_BP);
            return;
        }
    }

    AddQueue( QT_CONTINUE_DEBUG_EVENT,
              hthdx->hprc->pid,
              hthdx->tid,
              DBG_CONTINUE,
              0);
    //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
    //hthdx->tstate |= ts_running;
	hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
	hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
    return;
#endif
}
Exemplo n.º 14
0
void
ProcessSegmentLoadEvent(
    DEBUG_EVENT64 * pde,
    HTHDX           hthdx
    )

/*++

Routine Description:

    This function takes care of dealing with segment load events from
    the wow system.  These come in as exceptions and are translated
    to segment load events in ProcessDebugEvent.

Arguments:

    pde         - Supplies a pointer to the modified debug event

    hthdx       - Supplies the handle to the thread of the debug event

Return Value:

    None.

--*/

{
#if defined(i386) && !defined(WIN32S)

    PDWORDLONG  lpdw = &pde->u.Exception.ExceptionRecord.ExceptionInformation[0];
    int         mode = LOWORD( (DWORD)lpdw[0] );
    int         cb;
    int         cbRead;
    int         b;
    char *      lpb;
    WORD        packetType = tlfDebugPacket;
    HEMI        hemi;
    HPRCX       hprcx = hthdx->hprc;
    int         idx;
    SEGMENT_NOTE        sn;
    ADDR                addr;
    EXPECTED_EVENT *    pee;
    DWORD       eventCode;
    DWORD       subClass;
    LDT_ENTRY   ldt;
    BREAKPOINT *bp;


    DeWow = *pde;

    if ( !FVDMInitDone ) {
        HANDLE  hmodVDM;

        hmodVDM = LoadLibrary("VDMDBG.DLL");

        if ( hmodVDM != (HANDLE)NULL ) {
            FVDMActive = TRUE;

            pfnVDMProcessException = (VDMPROCESSEXCEPTIONPROC)
                GetProcAddress( hmodVDM, "VDMProcessException" );
            pfnVDMGetPointer = (VDMGETPOINTERPROC)
                GetProcAddress( hmodVDM, "VDMGetPointer" );
            pfnVDMGetThreadSelectorEntry = (VDMGETTHREADSELECTORENTRYPROC)
                GetProcAddress( hmodVDM, "VDMGetThreadSelectorEntry" );
            pfnVDMGetThreadContext = (VDMGETCONTEXTPROC)
                GetProcAddress( hmodVDM, "VDMGetContext" );
            pfnVDMSetThreadContext = (VDMSETCONTEXTPROC)
                GetProcAddress( hmodVDM, "VDMSetContext" );
            pfnVDMGetSelectorModule = (VDMGETSELECTORMODULEPROC)
                GetProcAddress( hmodVDM, "VDMGetSelectorModule" );
            pfnVDMEnumProcessWOW = (VDMENUMPROCESSWOWPROC)
                GetProcAddress( hmodVDM, "VDMEnumProcessWOW" );

        } else {
            DMPrintShellMsg( _T("LoadLibrary(VDMDBG.DLL) failed\n"));
        }
        FVDMInitDone = TRUE;
    }
    if ( !FVDMActive ) {
        return;
    } else {
        DebugEvent64To32(pde, &DeWow32);
        (*pfnVDMProcessException)((LPDEBUG_EVENT)&DeWow32);
        DebugEvent32To64(&DeWow32, pde);
    }

    hthdx->fWowEvent   = TRUE;

    switch ( mode ) {
        /*
         *   SEG LOAD:
         *
         *      LOWORD(lpdw[0]) --- DBG_SEGLOAD
         *      HIWORD(lpdw[0]) --- Unused
         *      LOWORD(lpdw[1]) --- Unused
         *      HIWORD(lpdw[1]) --- Unused
         *      lpdw[2]         --- pointer to SEGMENT_NOTE structure
         *      lpdw[3]         --- Reserved
         */

    case DBG_SEGLOAD:
        lpb = (char *) lpdw[2];
        b = DbgReadMemory(hprcx, (UINT_PTR)lpb, &sn, sizeof(sn), &cbRead);

        if ((b == 0) || (cbRead != sizeof(sn))) {
            b = GetLastError();
            AddQueue( QT_CONTINUE_DEBUG_EVENT,
                      hthdx->hprc->pid,
                      hthdx->tid,
                      DBG_CONTINUE,
                      0);
            //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
            //hthdx->tstate |= ts_running;
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
            return;
        }

        if (sn.FileName[0] == 0) {
            AddQueue( QT_CONTINUE_DEBUG_EVENT,
                      hthdx->hprc->pid,
                      hthdx->tid,
                      DBG_CONTINUE,
                      0);
            //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
            //hthdx->tstate |= ts_running;
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
            return;
        }
        cb = _tcslen(sn.FileName)+1;

        idx = LookupDllName(hprcx, sn.FileName);

        if ( idx != -1 ) {
            if (hprcx->rgDllList[idx].fReal) {
                //
                //  Changing from real to protected mode. We don't
                //  support this, so we'll throw away what we have
                //  and start from scratch.
                //
                WORD w = (WORD)idx;

                DMSendDebugPacket(dbceModFree16,
                                  hprcx->hpid,
                                  hthdx->htid,
                                  sizeof(WORD),
                                  &w
                                  );

                RemoveDllName( hprcx, idx );
                idx = -1;
            }
        }

        if (idx == -1) {

            LPMODULELOAD lpmdl;

            cb = cb + sizeof(MODULELOAD) + (sn.Segment+1)*sizeof(OBJD);

            lpmdl = (LPMODULELOAD) MHAlloc(cb);

            lpmdl->cobj = sn.Segment+1;

            lpmdl->rgobjd[sn.Segment].wSel = sn.Selector1;
            lpmdl->rgobjd[sn.Segment].cb = (DWORD) -1;
            lpmdl->rgobjd[sn.Segment].wPad = 1;

            lpmdl->mte = InsertDllName(hprcx, sn.FileName);
            _tcscpy((char *) &lpmdl->rgobjd[lpmdl->cobj], sn.FileName);

            lpmdl->fRealMode = FALSE;
            lpmdl->fFlatMode = FALSE;
            lpmdl->fOffset32 = FALSE;

            DMSendRequestReply(dbcModLoad,
                               hprcx->hpid,
                               hthdx->htid,
                               cb,
                               lpmdl,
                               sizeof(HEMI),
                               &hemi
                               );

            hemi = *((HEMI *) abEMReplyBuf);

            MHFree(lpmdl);

            AddQueue( QT_CONTINUE_DEBUG_EVENT,
                      hthdx->hprc->pid,
                      hthdx->tid,
                      DBG_CONTINUE,
                      0);
            //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
            //hthdx->tstate |= ts_running;
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));

        } else {

            SLI       sli;

            sli.wSelector = sn.Selector1;
            sli.wSegNo = sn.Segment;
            sli.mte = idx;

            DMSendDebugPacket(dbceSegLoad,
                              hprcx->hpid,
                              hthdx->htid,
                              sizeof(SLI),
                              &sli
                              );
        }

        break;

        /*
         *   SEGMOVE:
         *
         *      This event will be triggered if a selector number
         *      is to be changed.
         *
         *      LOWORD( lpdw[0] ) - SEGMOVE
         *      LOWORD( lpdw[1] ) - old selector number
         *      HIWORD( lpdw[1] ) - new selector number
         */

    case DBG_SEGMOVE:

        lpb = (char *) lpdw[2];
        b = DbgReadMemory(hprcx, (UINT_PTR)lpb, &sn, sizeof(sn), &cbRead);

        if ((b == 0) || (cbRead != sizeof(sn))) {
            b = GetLastError();
            AddQueue( QT_CONTINUE_DEBUG_EVENT,
                      hthdx->hprc->pid,
                      hthdx->tid,
                      DBG_CONTINUE,
                      0);
            //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
            //hthdx->tstate |= ts_running;
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
            return;
        }

        if (sn.FileName[0] == 0) {
            AddQueue( QT_CONTINUE_DEBUG_EVENT,
                      hthdx->hprc->pid,
                      hthdx->tid,
                      DBG_CONTINUE,
                      0);
            //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
            //hthdx->tstate |= ts_running;
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
            return;
        }
        cb = _tcslen(sn.FileName)+1;

        idx = LookupDllName(hprcx, sn.FileName);

        if ( idx != -1 ) {
            SLI       sli;

            assert( sn.Selector1 == 0 );
            sli.wSelector = sn.Selector2;
            sli.wSegNo = sn.Segment;
            sli.mte = idx;

            DMSendDebugPacket(dbceSegMove,
                              hprcx->hpid,
                              hthdx->htid,
                              sizeof(SLI),
                              &sli
                              );
        }

        AddQueue( QT_CONTINUE_DEBUG_EVENT,
                  hthdx->hprc->pid,
                  hthdx->tid,
                  DBG_CONTINUE,
                  0);
        //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
        //hthdx->tstate |= ts_running;
		hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
		hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));

        break;

        /*
         *   SEGFREE:
         *
         *      This event is triggered if a selector is freed
         *
         *      LOWORD( lpdw[0] ) - SEGFREE
         *      HIWORD( lpdw[0] ) - fBPRelease
         *      LOWORD( lpdw[1] ) - selector to be freed
         */

    case DBG_SEGFREE:

        AddQueue( QT_CONTINUE_DEBUG_EVENT,
                  hthdx->hprc->pid,
                  hthdx->tid,
                  DBG_CONTINUE,
                  0);
        //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
        //hthdx->tstate |= ts_running;

		hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
		hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
        break;

        /*
         *   MODLOAD:
         *
         *      This event is triggered when a new DLL is loaded
         *
         *      LOWORD( lpdw[0] ) - MODLOAD
         *      HIWORD( lpdw[0] ) - length of module name
         *      HIWORD( lpdw[1] ) - selector
         *      lpdw[2]           - address of module name
         *      lpdw[3]           - image length
         *
         */

    case DBG_MODLOAD:

        lpb = (char *) lpdw[2];
        b = DbgReadMemory(hprcx, (UINT_PTR)lpb, &sn, sizeof(sn), &cbRead);

        if ((b == 0) || (cbRead != sizeof(sn))) {
            b = GetLastError();
            AddQueue( QT_CONTINUE_DEBUG_EVENT,
                      hthdx->hprc->pid,
                      hthdx->tid,
                      DBG_CONTINUE,
                      0);
            //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
            //hthdx->tstate |= ts_running;
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
            return;
        }

        if (sn.FileName[0] == 0) {
            AddQueue( QT_CONTINUE_DEBUG_EVENT,
                      hthdx->hprc->pid,
                      hthdx->tid,
                      DBG_CONTINUE,
                      0);
            //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
            //hthdx->tstate |= ts_running;
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
            return;
        }

        cb = _tcslen(sn.FileName)+1;
        idx = LookupDllName(hprcx, sn.FileName);

        if (idx == -1) {
            LPMODULELOAD lpmdl;
            cb = cb + sizeof(MODULELOAD);

            lpmdl = (LPMODULELOAD) MHAlloc(cb);

            lpmdl->cobj = 0;

            lpmdl->mte = InsertDllName(hprcx, sn.FileName);

            idx = LookupDllName(hprcx, sn.FileName);

            if ( idx != -1 ) {
                hprcx->rgDllList[idx].fReal = TRUE;
            }

            _tcscpy((char *) &lpmdl->rgobjd[lpmdl->cobj], sn.FileName);

            lpmdl->StartingSegment = sn.Segment;

            lpmdl->fRealMode = TRUE;
            lpmdl->fFlatMode = FALSE;
            lpmdl->fOffset32 = FALSE;

            DMSendRequestReply(dbcModLoad,
                               hprcx->hpid,
                               hthdx->htid,
                               cb,
                               lpmdl,
                               sizeof(HEMI),
                               &hemi
                               );

            MHFree(lpmdl);
        }

        AddQueue( QT_CONTINUE_DEBUG_EVENT,
                  hthdx->hprc->pid,
                  hthdx->tid,
                  DBG_CONTINUE,
                  0);
        //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
        //hthdx->tstate |= ts_running;
		hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
		hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));

        break;

        /*
         *   MODFREE:
         *
         *      This event is triggered when a DLL is unloaded
         *
         *      LOWORD( lpdw[0] ) - MODFREE
         */

    case DBG_MODFREE:
        lpb = (char *) lpdw[2];
        b = DbgReadMemory(hprcx, (UINT_PTR)lpb, &sn, sizeof(sn), &cbRead);

        if ((b == 0) || (cbRead != sizeof(sn))) {
            b = GetLastError();
            AddQueue( QT_CONTINUE_DEBUG_EVENT,
                      hthdx->hprc->pid,
                      hthdx->tid,
                      DBG_CONTINUE,
                      0);
            //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
            //hthdx->tstate |= ts_running;
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
            return;
        }

        if (sn.FileName[0] == 0) {
            AddQueue( QT_CONTINUE_DEBUG_EVENT,
                      hthdx->hprc->pid,
                      hthdx->tid,
                      DBG_CONTINUE,
                      0);
            //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
            //hthdx->tstate |= ts_running;
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
			hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
            return;
        }
        cb = _tcslen(sn.FileName)+1;

        idx = LookupDllName(hprcx, sn.FileName);

        if (idx != -1) {

            WORD w = (WORD)idx;

            DMSendDebugPacket(dbceModFree16,
                              hprcx->hpid,
                              hthdx->htid,
                              sizeof(WORD),
                              &w
                              );

            RemoveDllName( hprcx, idx );
        }

        AddQueue( QT_CONTINUE_DEBUG_EVENT,
                  hthdx->hprc->pid,
                  hthdx->tid,
                  DBG_CONTINUE,
                  0);
        //hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
        //hthdx->tstate |= ts_running;

		hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate & ~(ts_stopped|ts_first|ts_second));
		hthdx->tstate = (TSTATEX)((DWORD)hthdx->tstate | (ts_running));
        break;

        /*
         *  Int 01h break;
         */

    case DBG_SINGLESTEP:
        hthdx->context.ContextFlags = VDMCONTEXT_FULL;
        (*pfnVDMGetThreadContext)(hthdx->hprc->rwHand, hthdx->rwHand, &hthdx->context);

        eventCode = EXCEPTION_DEBUG_EVENT;
        pde->dwDebugEventCode = EXCEPTION_DEBUG_EVENT;
        pde->u.Exception.ExceptionRecord.ExceptionCode = subClass =
            (DWORD)EXCEPTION_SINGLE_STEP;

        /*
         *  They are not clearing the trace bit
         */

        hthdx->context.EFlags &= ~TF_BIT_MASK;
        hthdx->fContextDirty = TRUE;

        AddrInit(&addr, 
                 0, 
                 (SEGMENT) hthdx->context.SegCs, 
                 SE32To64( hthdx->context.Eip ),
                 FALSE, 
                 FALSE, 
                 FALSE, 
                 FALSE
                 );

        bp = FindBP(hthdx->hprc, hthdx, bptpExec, (BPNS)-1, &addr, FALSE);

        if ( bp ) {
            SetBPFlag( hthdx, bp );
        }

        goto dispatch;

    case DBG_TASKSTART:
        hthdx->context.ContextFlags = VDMCONTEXT_FULL;
        (*pfnVDMGetThreadContext)(hthdx->hprc->rwHand, hthdx->rwHand, &hthdx->context);

        eventCode =
        pde->dwDebugEventCode = ENTRYPOINT_DEBUG_EVENT;

        goto dispatch;

    case DBG_TASKSTOP:
    case DBG_DLLSTART:
    case DBG_DLLSTOP:
    case DBG_ATTACH:
        AddQueue( QT_CONTINUE_DEBUG_EVENT,
                  hthdx->hprc->pid,
                  hthdx->tid,
                  DBG_CONTINUE,
                  0);
        hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
        hthdx->tstate |= ts_running;
        break;


        /*
         *   Int 03h break
         *
         *      LOWORD(lpdw[0])  --- BREAKPOINT
         *      HIWORD(lpdw[0])  --- Protect Mode
         */

    case DBG_BREAK:
        hthdx->context.ContextFlags = VDMCONTEXT_FULL;
        (*pfnVDMGetThreadContext)(hthdx->hprc->rwHand, hthdx->rwHand, &hthdx->context);

        Set_PC(hthdx, PC(hthdx) - 1);
        hthdx->fContextDirty = TRUE;

        eventCode = pde->dwDebugEventCode = BREAKPOINT_DEBUG_EVENT;

        // NOTENOTE --- jimsch -- assuming only 0xcc not 0xcd 0x3 breakpoints

        AddrInit(&addr, 
                 0, 
                 (SEGMENT) hthdx->context.SegCs, 
                 SE32To64( hthdx->context.Eip ),
                 FALSE, 
                 FALSE, 
                 FALSE, 
                 FALSE
                 );

        bp = FindBP(hthdx->hprc, hthdx, bptpExec, (BPNS)-1, &addr, FALSE);

        if ( bp && bp->isStep ) {

            eventCode             = EXCEPTION_DEBUG_EVENT;
            pde->dwDebugEventCode = EXCEPTION_DEBUG_EVENT;

            pde->u.Exception.ExceptionRecord.ExceptionCode =
                subClass = (DWORD)EXCEPTION_SINGLE_STEP;
                RemoveBP(bp);

        } else {

            if ( bp ) {
                SetBPFlag( hthdx, bp );
            }

            pde->u.Exception.ExceptionRecord.ExceptionCode =
                subClass = (DWORD)bp;
        }

        pde->u.Exception.ExceptionRecord.ExceptionAddress = PC(hthdx);

    dispatch:
        hthdx->fAddrIsReal = FALSE;
        hthdx->fAddrIsFlat = FALSE;

        DebugEvent64To32(pde, &DeWow32);
        if ((*pfnVDMGetThreadSelectorEntry)(&DeWow32,
                                            hthdx->rwHand,
                                            (WORD) hthdx->context.SegCs,
                                            &ldt)) {
            if (ldt.HighWord.Bits.Default_Big) {
                hthdx->fAddrOff32 = TRUE;
            } else {
                hthdx->fAddrOff32 = FALSE;
            }
        } else {
            hthdx->fAddrOff32 = FALSE;
        }

        /*
         *  Check if this debug event was expected
         */

        pee = PeeIsEventExpected(hthdx, eventCode, subClass, TRUE);

        /*
         * If it wasn't, run the standard handler with
         * notifications going to the execution model
         */

        assert((0 < eventCode) && (eventCode < MAX_EVENT_CODE));

        if (pee == NULL) {
            if ((hthdx != NULL) && (hthdx->tstate & ts_funceval)) {
                RgfnFuncEventDispatch[eventCode-EXCEPTION_DEBUG_EVENT](pde, hthdx);
            } else {
                DebugDispatchTable[eventCode-EXCEPTION_DEBUG_EVENT](pde,hthdx);
            }
            return;
        }


        /*
         *  If it was expected then call the action
         * function if one was specified
         */

        if (pee->action) {
            (pee->action)(pde, hthdx, 0, pee->lparam);
        }

        /*
         *  And call the notifier if one was specified
         */

        if (pee->notifier) {
            METHOD  *nm = pee->notifier;
            (nm->notifyFunction)(pde, hthdx, 0, nm->lparam);
        }

        free(pee);
        break;

#if 0  // why is this here??
    case DBG_DIVOVERFLOW:
        pde->dwDebugEventCode = 3;
        goto fault_occured;

    case DBG_INSTRFAULT:
        pde->dwDebugEventCode = 1;
        goto fault_occured;
#endif

    case DBG_DIVOVERFLOW:
    case DBG_INSTRFAULT:
    case DBG_GPFAULT:
        pde->dwDebugEventCode = EXCEPTION_DEBUG_EVENT;

#if 0  // why is this here??
    fault_occured:
#endif

        hthdx->context.ContextFlags = VDMCONTEXT_FULL;
        (*pfnVDMGetThreadContext)(hthdx->hprc->rwHand, hthdx->rwHand, &hthdx->context);
        pde->u.Exception.ExceptionRecord.ExceptionCode = 13;

        hthdx->fAddrIsReal = FALSE;
        hthdx->fAddrIsFlat = FALSE;

        DebugEvent64To32(pde, &DeWow32);
        if ((*pfnVDMGetThreadSelectorEntry)(&DeWow32, hthdx->rwHand,
                                      (WORD) hthdx->context.SegCs, &ldt)) {
            if (ldt.HighWord.Bits.Default_Big) {
                hthdx->fAddrOff32 = TRUE;
            } else {
                hthdx->fAddrOff32 = FALSE;
            }
        } else {
            hthdx->fAddrOff32 = FALSE;
        }

        ProcessExceptionEvent(pde, hthdx);
        break;

    default:
        AddQueue( QT_CONTINUE_DEBUG_EVENT,
                  hthdx->hprc->pid,
                  hthdx->tid,
                  DBG_CONTINUE,
                  0);
        hthdx->tstate &= ~(ts_stopped|ts_first|ts_second);
        hthdx->tstate |= ts_running;
        break;
    }
#endif // i386 && !Win32S
    return;
}                               /* ProcessSegmentLoadEvent() */
Exemplo n.º 15
0
VOID
AhciCompleteRequest(
    _In_ PAHCI_CHANNEL_EXTENSION ChannelExtension,
    _In_ PSTORAGE_REQUEST_BLOCK  Srb,
    _In_ BOOLEAN AtDIRQL
    )
/*++
    Wrapper for ComleteRequest to protect against completing the local SRB back to port driver who doesn't know anything about local SRB
It assumes:
    SRB is completely ready to be completed back to the SRB generator
It performs:
    1. If Srb has completion routine, put it in completion queue.
    2. Complete the command back to the owner. Do not complete the Local Srb.
Called by:
    AhciHwStartIo
    RequiresControllerResources
    ReleaseSlottedCommand

NOTE:
    The caller of this routine should call AhciGetNextIos or ActiveQueue to program the command (from Srb completion routine) to adapter

--*/
{
    PAHCI_SRB_EXTENSION srbExtension = GetSrbExtension(Srb);

  //1. If Srb acquired active reference or has completion routine, put it in completion queue. Otherwise, complete it.
    if ( ((srbExtension->Flags & ATA_FLAGS_ACTIVE_REFERENCE) != 0) ||
         (srbExtension->CompletionRoutine != NULL) ) {

        STOR_LOCK_HANDLE    lockhandle = {0};

        if (AtDIRQL == FALSE) {
            AhciInterruptSpinlockAcquire(ChannelExtension->AdapterExtension, ChannelExtension->PortNumber, &lockhandle);
            AddQueue(ChannelExtension, &ChannelExtension->CompletionQueue, Srb, 0xDEADBEEF, 0x90);
            AhciInterruptSpinlockRelease(ChannelExtension->AdapterExtension, ChannelExtension->PortNumber, &lockhandle);
        } else {
            AddQueue(ChannelExtension, &ChannelExtension->CompletionQueue, Srb, 0xDEADBEEF, 0x90);
        }

        if (LogExecuteFullDetail(ChannelExtension->AdapterExtension->LogFlags)) {
            RecordExecutionHistory(ChannelExtension, 0x30000045); //Exit AhciCompleteRequest, SRB is put in CompletionQueue
        }

        if (!IsDumpMode(ChannelExtension->AdapterExtension)) {
            StorPortIssueDpc(ChannelExtension->AdapterExtension, &ChannelExtension->CompletionDpc, ChannelExtension, Srb);
        } else {
            AhciPortSrbCompletionDpcRoutine(&ChannelExtension->CompletionDpc, ChannelExtension->AdapterExtension, ChannelExtension, Srb);
        }

    } else {
      //2. Complete the command back to the owner
        if (IsMiniportInternalSrb(ChannelExtension, Srb)) {
            NT_ASSERT(((PSCSI_REQUEST_BLOCK)Srb == &ChannelExtension->Sense.Srb) || (ChannelExtension->StateFlags.ReservedSlotInUse == 0));
            RecordExecutionHistory(ChannelExtension, 0x20000045); //Exit AhciCompleteRequest,  Local SRB
            return;
        } else {
            NT_ASSERT(Srb->SrbStatus != SRB_STATUS_PENDING);
            StorPortNotification(RequestComplete, ChannelExtension->AdapterExtension, Srb);

            if (LogExecuteFullDetail(ChannelExtension->AdapterExtension->LogFlags)) {
                RecordExecutionHistory(ChannelExtension, 0x10000045); //Exit AhciCompleteRequest, SRB from port driver
            }
        }
    }

    return;
}
Exemplo n.º 16
0
TEST
test_DelQueue(){

	Queue q;
	InitQueue(&q);
	Node *newItem1, *newItem2, *newItem3, *newItem4;
	Node *testItem1, *testItem2, *testItem3;

	newItem1 = NewItem();

	AddQueue(&q, newItem1);
	ASSERT(q.head == newItem1);
	ASSERT(q.tail == q.head);
	ASSERT(q.count == 1);

	testItem1 = DelQueue(&q);
	ASSERT(q.head == q.tail);
	ASSERT(q.count == 0);

	ASSERT(testItem1 == newItem1);

	newItem2 = NewItem();

	newItem3 = NewItem();

	AddQueue(&q, newItem2);
	AddQueue(&q, newItem3);

	ASSERT(q.head == newItem2);
	ASSERT(q.tail == newItem3);
	ASSERT(q.count == 2);

	testItem2 = DelQueue(&q);
	ASSERT(testItem2 == newItem2);
	ASSERT(q.count == 1);
	ASSERT(q.head == q.tail);

	testItem3 = DelQueue(&q);
	ASSERT(testItem3 == newItem3);
	ASSERT(q.count == 0);

	newItem4 = NewItem();

	AddQueue(&q, newItem1);
	AddQueue(&q, newItem2);
	AddQueue(&q, newItem3);
	AddQueue(&q, newItem4);
	
	//test if queue is still circular after delete
	DelQueue(&q);
	ASSERT(q.head->prev == q.tail);
	ASSERT(q.tail->next == q.head);


	FreeItem(newItem1);
	FreeItem(newItem2);
	FreeItem(newItem3);
	FreeItem(newItem4);

	PASS();
}
Exemplo n.º 17
0
void keyboard_irq(int irq, struct pt_regs *regs, void *dev_id)
{
    static unsigned int ModeState = 0;
    static int E0Prefix = 0;
    int code, mode, E0 = 0;
    register char *keyp;
    register char *IsReleasep;

    code = inb_p((void *) KBD_IO);
    mode = inb_p((void *) KBD_CTL);

    /* Necessary for the XT. */
    outb_p((unsigned char) (mode | 0x80), (void *) KBD_CTL);
    outb_p((unsigned char) mode, (void *) KBD_CTL);

    if (kraw) {
	AddQueue((unsigned char) code);
	return;
    }
    if (code == 0xE0) {		/* Remember this has been received */
	E0Prefix = 1;
	return;
    }
    if (E0Prefix) {
	E0 = 1;
	E0Prefix = 0;
    }
    IsReleasep = (char *)(code & 0x80);
    switch (code & 0x7F) {
    case 29:
	IsReleasep ? (ModeState &= ~CTRL) : (ModeState |= CTRL);
	return;
    case 42:
	IsReleasep ? (ModeState &= ~LSHIFT) : (ModeState |= LSHIFT);
	return;
    case 54:
	IsReleasep ? (ModeState &= ~RSHIFT) : (ModeState |= RSHIFT);
	return;
    case 56:

#if defined(CONFIG_KEYMAP_DE) || defined(CONFIG_KEYMAP_SE)

	if (E0 == 0) {
	    IsReleasep ? (ModeState &= ~ALT) : (ModeState |= ALT);
	} else {
	    IsReleasep ? (ModeState &= ~ALT_GR) : (ModeState |= ALT_GR);
	}

#else

	IsReleasep ? (ModeState &= ~ALT) : (ModeState |= ALT);

#endif

	return;
    case 58:
	ModeState ^= IsReleasep ? 0 : CAPS;
	return;
    case 69:
	ModeState ^= IsReleasep ? 0 : NUM;
	return;
    default:
	if (IsReleasep)
	    return;
	break;
    }

    /*      Handle CTRL-ALT-DEL     */

    if ((code == 0x53) && (ModeState & CTRL) && (ModeState & ALT))
	ctrl_alt_del();

    /*
     *      Pick the right keymap
     */
    if (ModeState & CAPS && !(ModeState & ANYSHIFT))
	keyp = (char *) xtkb_scan_caps[code];
    else if (ModeState & ANYSHIFT && !(ModeState & CAPS))
	keyp = (char *) xtkb_scan_shifted[code];

    /* added for belgian keyboard (Stefke) */

    else if ((ModeState & CTRL) && (ModeState & ALT))
	keyp = (char *) xtkb_scan_ctrl_alt[code];

    /* end belgian                                  */

    /* added for German keyboard (Klaus Syttkus) */

    else if (ModeState & ALT_GR)
	keyp = (char *) xtkb_scan_ctrl_alt[code];
    /* end German */
    else
	keyp = (char *) xtkb_scan[code];

    if (ModeState & CTRL && code < 14 && !(ModeState & ALT))
	keyp = (char *) xtkb_scan_shifted[code];
    if (code < 70 && ModeState & NUM)
	keyp = (char *) xtkb_scan_shifted[code];
    /*
     *      Apply special modifiers
     */
    if (ModeState & ALT && !(ModeState & CTRL))	/* Changed to support CTRL-ALT */
	keyp = (char *)(((int) keyp) | 0x80); /* META-.. */
    if (!keyp)			/* non meta-@ is 64 */
	keyp = (char *) '@';
    if (ModeState & CTRL && !(ModeState & ALT))	/* Changed to support CTRL-ALT */
	keyp = (char *)(((int) keyp) & 0x1F); /* CTRL-.. */
    if (code < 0x45 && code > 0x3A) {	/* F1 .. F10 */

#ifdef CONFIG_CONSOLE_DIRECT

	if (ModeState & ALT) {
	    Console_set_vc((unsigned) (code - 0x3B));
	    return;
	}
#endif

	AddQueue(ESC);
	AddQueue((unsigned char) (code - 0x3B + 'a'));
	return;
    }
    if (E0)			/* Is extended scancode */
	switch (code) {
	case 0x48:		/* Arrow up */
	    AddQueue(ESC);
	    AddQueue('A');
	    return;
	case 0x50:		/* Arrow down */
	    AddQueue(ESC);
	    AddQueue('B');
	    return;
	case 0x4D:		/* Arrow right */
	    AddQueue(ESC);
	    AddQueue('C');
	    return;
	case 0x4B:		/* Arrow left */
	    AddQueue(ESC);
	    AddQueue('D');
	    return;
	case 0x1c:		/* keypad enter */
	    AddQueue('\n');
	    return;
	}
    if (((int)keyp) == '\r')
	keyp = (char *) '\n';
    AddQueue((unsigned char) keyp);
}
Exemplo n.º 18
0
BOOL ThreadContrl::AddTask(Monitor *pMonitor)
{ 
//	if(m_hThread==NULL)
//		throw MSException("Error : NO ThreadContrl thread");

	CString strError="";
	if(pMonitor==NULL)
		throw MSException("Monitor is empty");

	//bool ist=false;

	//if(stricmp(pMonitor->GetMonitorClass().getText(),"telnet")==0)
	//{
	//	char buf[100]={0};
	//	sprintf(buf,"////////////////class:%s telnet monitor:%s//////////////\n",pMonitor->GetMonitorClass().getText(),
	//		pMonitor->GetMonitorID());

	//	ist=true;

	//	//putil->ErrorLog(buf);
	//}

	if(pMonitor->GetSkipCount()>=MAXSKIPCOUNT)
	{
		strError.Format("SkipCount > %d, MonitorID:%s, this monitor will be deleted. ",MAXSKIPCOUNT,pMonitor->GetMonitorID());
		m_pSchMain->DeleteMonitorV70(pMonitor->GetMonitorID());
		string strTemp = strError.getText();
		WriteLog( strTemp.c_str() );
		//putil->ErrorLog(strError);
		//throw MSException((LPCSTR)strError);
		return false;
	}

	if(pMonitor->GetRunning())
	{
		pMonitor->SetSkipCount(pMonitor->GetSkipCount()+1);
		strError.Format("Monitor skip count:%d,Monitor ID:%s",pMonitor->GetSkipCount(),pMonitor->GetMonitorID());
		string strTemp = strError.getText();
		WriteLog( strTemp.c_str() );
		//putil->ErrorLog(strError);

	}else{
		if(!CheckSubsequent(pMonitor))
		{
			//if(ist)
			//	//putil->ErrorLog("will Start Monitor");
			StartMonitor(pMonitor);
	//		StartMonitor(PopMonitorInQueue(pMonitor));
		}
		else
		{
			//if(ist)
			//	//putil->ErrorLog("Enter queue");
			AddQueue(pMonitor);
		}
	}


	return TRUE;

}