コード例 #1
0
void TestMessagePoolPutMessage(CuTest *tc) {
	struct MessagePool *pool = CreateMessagePool();
	struct Message *m = NewMessage();
	PutMessage(pool, m);
	CuAssertIntEquals(tc, 1024*1024+1, pool->count);

	int i = 0;
	for (i = 0; i < 1024*1024; i ++) {
		struct Message *msg = GetMessage(pool);
	}
	CuAssertIntEquals(tc, 1, pool->count);
	CuAssertPtrNotNull(tc, pool->head);

	struct Message *msg = GetMessage(pool);
	CuAssertIntEquals(tc, 0, pool->count);
	CuAssertPtrEquals(tc, NULL, pool->head);

	struct Message *m1 = NewMessage();
	PutMessage(pool, m1);
	CuAssertIntEquals(tc, 1, pool->count);
	CuAssertPtrNotNull(tc, pool->head);

	struct Message *m2 = NewMessage();
	PutMessage(pool, m2);
	CuAssertIntEquals(tc, 2, pool->count);
	CuAssertPtrNotNull(tc, pool->head);
}
コード例 #2
0
int CSenceManager::handle_timeout(const ACE_Time_Value &tv, const void *arg)
{
	if(arg != NULL)
	{
		//OUR_DEBUG((LM_ERROR,"[CMessageService::handle_timeout] arg is not NULL, time is (%d).\n", tv.sec()));
		//思考再三,决定在Timer线程里面,添加到队列中去。这样减少多并发引起的麻烦。

		_TimerInfo* pTimerInfo = (_TimerInfo* )arg;

		_CommandInfo objCommandInfo;

		objCommandInfo.u4RoomID      = pTimerInfo->m_u4RoomID;
		objCommandInfo.u4PlayerID    = pTimerInfo->m_u4PlayerID;
		objCommandInfo.u4OpreationID = pTimerInfo->m_u4Event;

		//清理一下定时器的记录信息
		if(pTimerInfo->m_u4CommandID == COMMAND_TIMERPLAYER)
		{
			App_RoomManager::instance()->SetRoomPlayerTimerID(objCommandInfo.u4RoomID, objCommandInfo.u4PlayerID, 0, TIMER_ERROR_IN, NULL);
		}
		else if(pTimerInfo->m_u4CommandID == COMMAND_TIMERROOM)
		{
			App_RoomManager::instance()->SetRoomTimerID(objCommandInfo.u4RoomID, 0, TIMER_ERROR_IN, NULL);
		}
		

		PutMessage(pTimerInfo->m_u4CommandID, objCommandInfo);

		SAFE_DELETE(pTimerInfo);
	}

	return 0;
}
コード例 #3
0
ファイル: NETROUTE.C プロジェクト: dylancarlson/acit
/* -------------------------------------------------------------------- */
BOOL save_mail(void)
{
    label tosystem;
    char  filename[100];
    FILE *fl;

    /* where are we sending it? */
    strcpy(tosystem, msgBuf->mbzip);

    /* send it vila... */
    route(tosystem);

    /* get the node entery */
    if (!getnode(tosystem))
        return FALSE;
  
    sprintf(filename, "%s\\%s", cfg.transpath, node.ndmailtmp);

    fl = fopen(filename, "ab");
    if (!fl) return FALSE;

    PutMessage(fl);

    fclose(fl);

    return TRUE;
}
コード例 #4
0
void main (void){
    unsigned char i;
        clock_int_48MHz();
	Init_GLCD();
        
        SetPos(1,1);  
	SanDraw((char*)imagem);
        tempo_ms(4000);
        ClearScreen();

///*    //box(1,1,126,62);//plota caixa entre os 4 pontos x1,y1,x2,y2 (máx 126 e 62)
	//ASCII 22 (x16) is set position followed by x,y
	PutMessage((char*)"\x16\x26\x08 Grupo\x16\x20\x10  SanUSB\n Titulo:\n Autor:\n Compilador:");
	PutMessage((char*)"\x16\x32\x18LcdGrafico C18");
	PutMessage((char*)"\x16\x32\x20Grupo SanUSB");
	PutMessage((char*)"\x16\x40\x28MPLABX C18");
        tempo_ms(1000);
        //ClearScreen(); //*/
   
	while (1){inverte_saida(pin_b7); inverte_saida(pin_d7); tempo_ms(500);
                  if(!entrada_pin_e3){Reset();} //Estado de gravação via USB
                 }
}
コード例 #5
0
ファイル: alice.c プロジェクト: nbfhjgr/mima_praktikumI
int main(int argc, char **argv) {
	Connection con;
	Message msg1, msg2, msg3;
	char *OurNetName, *OthersNetName, *ServerNetName;

	/* Konstruktion eindeutiger Namen für das Netzwerksystem:
	 * OurName, OthersName und ServerName wird der Gruppenname vorangestellt.
	 * So gibt es KEINE Kollisionen zwischen den einzelnen Gruppen!
	 * Dieser Netzname wird nur für den Verbindungsaufbau über das
	 * E.I.S.S.-Network-Playfield benutzt. Die im Rahmen des Protokolls
	 * ausgetauschten Namen sind OutName, OthersName und ServerName!
	 */

	OurNetName = MakeNetName2(OurName);
	OthersNetName = MakeNetName2(OthersName);
	ServerNetName = MakeNetName2(ServerName);

	/***************  Verbindungsaufbau zum Server  ********************/
	/* Die Verbindung zum Server muß einen anderen "Quell"-Namen haben, als
	 * die zu Bob. Daher hängen wir einfach ein _S an! */
	if (!(con = ConnectTo(concatstrings(OurNetName, "_S", NULL), ServerNetName))) {
		fprintf(stderr,
				"ALICE: Kann keine Verbindung zum Server aufbauen: %s\n",
				NET_ErrorText());
		exit(20);
	}

	/******  Paket mit den beiden Namen erzeugen und Abschicken  *******/
	msg1.typ = Alice_Server;
	strcpy(msg1.body.Alice_Server.A, OurName);
	strcpy(msg1.body.Alice_Server.B, OthersName);
	PutMessage("Server", con, &msg1);

	/***********  Antwort des Servers lesen  ***********/
	GetMessage("Server", con, &msg1, Server_Alice);

	/****************  Verbindung zum Server abbauen  *************/
	DisConnect(con);

	/*>>>>                                         <<<<*
	 *>>>> AUFGABE: - Entschlüsseln der Nachricht  <<<<*
	 *>>>>          - Nachrichtenaustauch mit Bob  <<<<*
	 *>>>>          - Überprüfen der Bob-Nachricht <<<<*
	 *>>>>          - Schlüssel für Telefonieren   <<<<*
	 *>>>>                                         <<<<*/

	// Entschlüsseln der Nachricht
	DES_ikey ikey_sa;
	DES_GenKeys(Key_AS, 0, ikey_sa);
	DES_data iv;
	memset(&iv, 0, sizeof(DES_data));

	ServerData toDecServerData;
	memcpy(&toDecServerData, &msg1.body.Server_Alice.Serv_A1,
			sizeof(ServerData));
	DES_OFB(ikey_sa, iv, &toDecServerData, sizeof(ServerData),
			&msg1.body.Server_Alice.Serv_A1);

	// Analysierung der Nachricht
	DES_GenKeys(msg1.body.Server_Alice.Serv_A1.Key_AB, 0, iKey_AB);
	int TimeStamp = msg1.body.Server_Alice.Serv_A1.TimeStamp;
	int cur_time = GetCurrentTime();
	printf("%d\n",cur_time-TimeStamp);
	if (cur_time - TimeStamp < 0 || cur_time - TimeStamp > 30000) {		//set Time-out 30s
		fprintf(stderr, "TimeStamp check Error!\n");
		exit(20);
	}

	// Generierung neuer Nachricht zu Bob mit ServerData_B und AuthData_A
	msg2.typ = Alice_Bob;
	memcpy(&msg2.body.Alice_Bob.Serv_B2, &msg1.body.Server_Alice.Serv_B1,
			sizeof(ServerData));

	strcpy(&msg2.body.Alice_Bob.Auth_A2.Name,
			&msg1.body.Server_Alice.Serv_A1.Receiver);
	msg2.body.Alice_Bob.Auth_A2.Rand = RandomNumber();
	AuthData toEncAuthData;
	memset(&iv, 0, sizeof(DES_data));
	memcpy(&toEncAuthData, &msg2.body.Alice_Bob.Auth_A2, sizeof(AuthData));
	DES_OFB(iKey_AB, iv, &toEncAuthData, sizeof(AuthData),
			&msg2.body.Alice_Bob.Auth_A2);

	// Schick Bob die Nachricht
	if (!(con = ConnectTo(OurNetName, OthersNetName))) {
		fprintf(stderr, "ALICE: Kann keine Verbindung zum %s aufbauen: %s\n",
				OthersNetName, NET_ErrorText());
		exit(20);
	}
	PutMessage(OthersName, con, &msg2);

	// bekommen der Nachricht von Bob, enschlüsseln und überprüfen
	GetMessage(OthersName, con, &msg3, Bob_Alice);
	AuthData toDecAuthData;
	memset(&iv, 0, sizeof(DES_data));
	memcpy(&toDecAuthData, &msg3.body.Bob_Alice.Auth_B3, sizeof(AuthData));
	DES_OFB(iKey_AB, iv, &toDecAuthData, sizeof(AuthData),
			&msg3.body.Bob_Alice.Auth_B3);

	if (strcmp(msg3.body.Bob_Alice.Auth_B3.Name, OthersName) != 0) {
		fprintf(stderr, "Sender check Error!\n");
		exit(20);
	}

	if (msg3.body.Bob_Alice.Auth_B3.Rand != SwitchRandNum(toEncAuthData.Rand)) {
		fprintf(stderr, "Rand check Error!\n");
		exit(20);
	}

	printf("Keberos-Handshake successful!\n");

	/***********************  Phone starten  *****************************/
	Phone(con, OurName, OthersName, EnCrypt, DeCrypt);
	DisConnect(con);
	return 0;
}
コード例 #6
0
ファイル: NETMSG.C プロジェクト: dylancarlson/gremcit
/* -------------------------------------------------------------------- */
void saveMessage(ulong id, FILE *fl)
{
    ulong here;
    ulong loc;
    ulong result;
/*  int originroomno; */

#ifdef NEWMSGTAB
    ulong slot;
#else
    int   slot;
#endif
    FILE *fl2;
/*   label str; */


    result = indexslot(id);

#ifdef NEWMSGTAB    
    slot = indexslot(id);
#else
    slot = (int)indexslot(id);
#endif
    
    if (result == ULONG_ERROR) return;


#ifdef NEWMSGTAB
    if (getFlags(slot)->COPY)
#else
    if (msgTab_mtmsgflags[slot].COPY)
#endif

    {
        copyflag     = TRUE;
        originalId   = id;
        originalattr = 0;


#ifdef NEWMSGTAB
        originalattr = (uchar)
                       (originalattr | (getFlags(slot)->RECEIVED)?ATTR_RECEIVED :0 );
        originalattr = (uchar)
                       (originalattr | (getFlags(slot)->REPLY   )?ATTR_REPLY : 0 );
        originalattr = (uchar)
                       (originalattr | (getFlags(slot)->MADEVIS )?ATTR_MADEVIS : 0 );
#else
        originalattr = (uchar)
                       (originalattr | (msgTab_mtmsgflags[slot].RECEIVED)?ATTR_RECEIVED :0 );
        originalattr = (uchar)
                       (originalattr | (msgTab_mtmsgflags[slot].REPLY   )?ATTR_REPLY : 0 );
        originalattr = (uchar)
                       (originalattr | (msgTab_mtmsgflags[slot].MADEVIS )?ATTR_MADEVIS : 0 );
#endif

#ifdef GOODBYE                       
        if (msgTab3[slot].mtoffset <= (ushort)slot)
            saveMessage( (ulong)(id - (ulong)msgTab3[slot].mtoffset), fl);
#endif


#ifdef NEWMSGTAB
/*      if (getOriginID(slot)     <= (ushort)slot)  */
        if (long_JOIN(getToHash(slot), getAuthHash(slot))     <= slot)
#else
   /*   if (msgTab_mtomesg[slot]  <= (ushort)slot)  */

if(long_JOIN(msgTab_mttohash[slot], msgTab_mtauthhash[slot]) <= (ushort)slot) 


#endif

#ifdef NEWMSGTAB
        /*  saveMessage( (ulong)(id - (ulong)getOriginID(slot)    ), fl); */
            saveMessage( (id - long_JOIN(getToHash(slot), getAuthHash(slot))   ), fl);
#else
        /*  saveMessage( (ulong)(id - (ulong)msgTab_mtomesg[slot] ), fl);  */

            saveMessage( (ulong)(id - long_JOIN(msgTab_mttohash[slot], 
            msgTab_mtauthhash[slot])) , fl);

#endif

        return;
    }

    /* in case it returns without clearing buffer */
    msgBuf->mbfwd[  0]  = '\0';
    msgBuf->mbto[   0]  = '\0';

/*  loc = msgTab2[slot].mtmsgLoc; */

#ifdef NEWMSGTAB
    loc  = getLocation(slot);
#else
    loc  = long_JOIN(msgTab_mtmsgLocLO[slot], msgTab_mtmsgLocHI[slot]); 
#endif

    if (loc == ULONG_ERROR) return;


#ifdef NEWMSGTAB
    if (copyflag)  slot = indexslot(originalId);
#else
    if (copyflag)  slot = (int)indexslot(originalId);
#endif


#ifdef NEWMSGTAB
    if (!mayseeindexmsg(slot) && !getFlags(slot)->NET) return;
#else
    if (!mayseeindexmsg(slot) && !msgTab_mtmsgflags[slot].NET) return;
#endif

    fseek(msgfl, loc, 0);

    getMessage();
    getMsgStr(msgBuf->mbtext, MAXTEXT);

    sscanf(msgBuf->mbId, "%lu", &here);

    /* cludge to return on dummy msg #1 */
    /* if ((int)here == 1) return; */

#ifdef NEWMSGTAB
    if (!mayseemsg() && !getFlags(slot)->NET) return;
#else
    if (!mayseemsg() && !msgTab_mtmsgflags[slot].NET) return;
#endif

    if (here != id )
    {
        cPrintf("Can't find message. Looking for %lu at byte %ld!\n ",
                 id, loc);
        return;
    }

    if (msgBuf->mblink[0])
    {
        if ((fl2 = fopen(msgBuf->mblink, "rt")) == NULL)
        {
            return;
        }
        GetFileMessage(fl2, msgBuf->mbtext, MAXTEXT);
        fclose(fl2);
    }

#ifdef HENGE    
    if (node.network == NET_HENGE)
    {
        HengePutMessage(fl);
    }
    else
    {
#endif         
        PutMessage(fl);
#ifdef HENGE    
    }
#endif         
}
コード例 #7
0
irqreturn_t MailboxIRQHandler0(int irq, void *dev_id, struct pt_regs *regs)
{
    CoreServicesBridge*     bridge  = (CoreServicesBridge*)alloyRam;
    uint32_t                coreID  = read_cpuid_mpidr() & 0x3;
    uint32_t                mailboxSource       = readl( __io_address(ARM_LOCAL_MAILBOX0_CLR0) + (coreID*0x10));
    FullCoreMessage         msg;

    //printk("mailboxSource = %08x\n",mailboxSource);

    //memcpy_fromio( &bridge, alloyRam, sizeof(bridge) );

    //
    // Clear the interrupt...
    //
    coreID  = 0;
    if( (mailboxSource&(1<<0)) != 0 )
    {
        printk("Message from Core 0: type=%08x payload=%08x\n", bridge->coreMessages[coreID][0].type, bridge->coreMessages[coreID][0].payload );

        msg.coreID      = 0;
        msg.type        = bridge->coreMessages[coreID][0].type;
        msg.payload     = bridge->coreMessages[coreID][0].payload;
        PutMessage( &msg );

        writel( 1<<0, __io_address(ARM_LOCAL_MAILBOX0_CLR0) );
    }

    if( (mailboxSource&(1<<1)) != 0 )
    {
        printk("Message from Core 1: type=%08x payload=%08x\n", bridge->coreMessages[coreID][1].type, bridge->coreMessages[coreID][1].payload );

        msg.coreID      = 1;
        msg.type        = bridge->coreMessages[coreID][1].type;
        msg.payload     = bridge->coreMessages[coreID][1].payload;
        PutMessage( &msg );

        writel( 1<<1, __io_address(ARM_LOCAL_MAILBOX0_CLR0) );
    }

    if( (mailboxSource&(1<<2)) != 0 )
    {
        printk("Message from Core 2: type=%08x payload=%08x\n", bridge->coreMessages[coreID][2].type, bridge->coreMessages[coreID][2].payload );

        msg.coreID      = 2;
        msg.type        = bridge->coreMessages[coreID][2].type;
        msg.payload     = bridge->coreMessages[coreID][2].payload;
        PutMessage( &msg );

        writel( 1<<2, __io_address(ARM_LOCAL_MAILBOX0_CLR0) );
    }

    if( (mailboxSource&(1<<3)) != 0 )
    {
        printk("Message from Core 3: type=%08x payload=%08x\n", bridge->coreMessages[coreID][3].type, bridge->coreMessages[coreID][3].payload );

        msg.coreID      = 3;
        msg.type        = bridge->coreMessages[coreID][3].type;
        msg.payload     = bridge->coreMessages[coreID][3].payload;
        PutMessage( &msg );

        writel( 1<<3, __io_address(ARM_LOCAL_MAILBOX0_CLR0) );
    }


    return IRQ_HANDLED;
}