int StructuredDatabaseTest() { Table* table; int user_id; DynArray<1024> what; DynArray<1024> where; table = new Table(&database, "structured_test"); table->Truncate(); user_id = InsertUser(table, "dopey", "dopeypass", "online"); InsertEvent(table, user_id, "dinner", "cheezburger", "2009-03-24 01:09:00"); InsertEvent(table, user_id, "meeting", "important", "2009-03-24 11:12:00"); // SELECT * FROM event WHERE user=%d AND date > 2009-03-24 01 what.Printf("event:user:%d", user_id); where.Printf("date:2009-03-24 01"); //TableSelector selector(what.buffer, where.buffer); // QuerySelector selector("SELECT date, note FROM event WHERE user_id=%d", user_id); // table->Visit(selector); ListTableVisitor visitor; table->Visit(visitor); return TEST_SUCCESS; }
gd::BaseEvent & EventsList::InsertNewEvent(gd::Project & project, const gd::String & eventType, size_t position) { gd::BaseEventSPtr event = project.CreateEvent(eventType); if ( event == std::shared_ptr<gd::BaseEvent>()) { std::cout << "Unknown event of type " << eventType; event = std::shared_ptr<gd::BaseEvent>(new EmptyEvent); } InsertEvent(event, position); return *event; }
/// Pack/unpack/sizing operator void EqHeap::pup(PUP::er &p) { int i=0, hs; Event *e; if (p.isUnpacking()) { // UNPACK entire heap right here p(hs); top = NULL; while (i < hs) { e = new Event(); e->pup(p); InsertEvent(e); i++; } } else { // PACK / SIZE p(heapSize); if (top) top->pup(p); // HeapNode::pup recursively packs/sizes events } }
void GenerateNextArrival() { double x, log(), ceil(); struct event *evptr; /* x is uniform on [0,2*AveTimeBetweenMsgs ] having mean of AveTimeBetweenMsgs */ x = AveTimeBetweenMsgs *GetRandomNumber()*2; if ( TraceLevel >= 4) printf("\tGenerateNextArrival: Creating new arrival at %f from now\n", x); evptr = (struct event *)malloc(sizeof(struct event)); evptr->evtime = CurrentSimTime + x; evptr->evtype = FROM_LAYER5; if (Bidirectional && (GetRandomNumber()>0.5) ) evptr->eventity = BEntity; else evptr->eventity = AEntity; InsertEvent(evptr); }
static event_t * ReadEvent(int today) { FILE *fp; char buf[PATHLEN]; event_t head; head.next = NULL; sethomefile(buf, cuser.userid, "calendar"); fp = fopen(buf, "r"); if (fp) { while (fgets(buf, sizeof(buf), fp)) { char *date, *color, *content; event_t *t; char *strtok_pos; if (buf[0] == '#') continue; date = strtok_r(buf, " \t\n", &strtok_pos); color = strtok_r(NULL, " \t\n", &strtok_pos); content = strtok_r(NULL, "\n", &strtok_pos); if (!date || !color || !content) continue; t = malloc(sizeof(event_t)); if (ParseEventDate(date, t) || t->days < today) { free(t); continue; } t->color = ParseColor(color) + 30; for (; *content == ' ' || *content == '\t'; content++); t->content = strdup(content); InsertEvent(&head, t); } fclose(fp); } return head.next; }
void AllocationPlanning(event *ptrCurrentEvent, event *ptrEventList, machine *ptrMachineList, task *ptrTaskList, balanceAccountInfo **ptrPtrBalanceAccountInfo) { if (ptrCurrentEvent->eventID == ALLOCATIONPLANNING) { if (ptrMachineList && ptrTaskList) { unsigned long int balance, numberOfGridMachines; balance = GetBalance(ptrPtrBalanceAccountInfo, ptrCurrentEvent->time); numberOfGridMachines = (int)((balance * gridQoSFactor)/taskAvgTime); // ceiling or trunk??? // printf("o balance na grade agora e %d\n", GetBalance(ptrBalanceAccountInfo, ptrCurrentEvent->time)); // printf("\n"); // printf("balance %d\n", balance); // printf("gridFactor %.2f\n", gridQoSFactor); // printf("numberofGridMachines %d\n", numberOfGridMachines); task *ptrAuxTask; ptrAuxTask = ptrTaskList; unsigned short int allocated = 0; while(ptrAuxTask) { // printf("taskID %d\n", ptrAuxTask->taskID); unsigned short int found = 0; if ( ptrAuxTask->taskID > 0 && ptrAuxTask->arrivalTime <= ptrCurrentEvent->time && ptrAuxTask->status == QUEUED ) { // taskID 0 means code for an empty task list // passou(); // treating the allocation on in-house machines machine *ptrAuxLocalMachine; ptrAuxLocalMachine = ptrMachineList; while(ptrAuxLocalMachine) { if ( ptrAuxLocalMachine->source == LOCAL && (ptrAuxLocalMachine->status == IDLE || ptrAuxLocalMachine->status == DONATING) ) { found = 1; allocated = 1; ptrAuxLocalMachine->status = RUNNING; // LEMBAR QUE ESTOU AQUI A UM SEGUNDO DE COMECAR A EXECUCAO EFETIVAMENTE ptrAuxTask->status = STARTED; // LEMBAR QUE ESTOU AQUI A UM SEGUNDO DE COMECAR A EXECUCAO EFETIVAMENTE // insert a new task schedule into the event list event *ptrNewEvent; if( (ptrNewEvent = malloc(sizeof(event))) ) { ptrNewEvent->eventNumber = 0; ptrNewEvent->eventID = TASKSCHEDULE; ptrNewEvent->time = (ptrCurrentEvent->time + 1); ptrNewEvent->scheduleInfo.scheduleID = ++scheduleID; ptrNewEvent->scheduleInfo.scheduleTime = (ptrCurrentEvent->time + 1); ptrNewEvent->scheduleInfo.taskID = ptrAuxTask->taskID; ptrNewEvent->scheduleInfo.jobID = ptrAuxTask->jobID; ptrNewEvent->scheduleInfo.runtime = ptrAuxTask->runtime; ptrNewEvent->scheduleInfo.machineID = ptrAuxLocalMachine->machineID; ptrNewEvent->scheduleInfo.source = ptrAuxLocalMachine->source; ptrNewEvent->scheduleInfo.nextSchedule = NULL; ptrNewEvent->nextEvent = NULL; InsertEvent(ptrEventList, ptrNewEvent); } else printf("ERROR (allocation planning): merdou o malloc!!!\n"); // printf("eventID %d (Allocation Planning) time %d ", ptrCurrentEvent->eventID, ptrCurrentEvent->time); // printf("taskID %d jobID %d machineID %d source %d\n", ptrAuxTask->taskID, // ptrAuxTask->jobID, ptrAuxLocalMachine->machineID, ptrAuxLocalMachine->source); break; // finishing while(ptrAuxLocalMachine) } ptrAuxLocalMachine = ptrAuxLocalMachine->nextMachine; } // end of while(ptrAuxLocalMachine) // treating the allocation on grid machines if (found == 0 && numberOfGridMachines > 0) { numberOfGridMachines -= 1; gridMachinesID += 1; found = 1; allocated = 1; ptrAuxTask->status = STARTED; // LEMBAR QUE ESTOU AQUI A UM SEGUNDO DE COMECAR A EXECUCAO EFETIVAMENTE // unsigned int avgUpTime = (int)Randn(gridAvgUptime, (gridAvgUptime*0.1)); unsigned int avgUpTime = (int)Uniform(15, 25); // printf("DT %d\n", departureTime); // debug mode // insert a machine arrival event into the event list event *ptrNewGridMachine; if( (ptrNewGridMachine = malloc(sizeof(event))) ) { ptrNewGridMachine->eventNumber = 0; ptrNewGridMachine->eventID = MACHARRIVAL; ptrNewGridMachine->time = ptrCurrentEvent->time; ptrNewGridMachine->machineInfo.machineID = gridMachinesID; ptrNewGridMachine->machineInfo.source = GRID; ptrNewGridMachine->machineInfo.status = RUNNING; ptrNewGridMachine->machineInfo.arrivalTime = ptrCurrentEvent->time; ptrNewGridMachine->machineInfo.departureTime = (ptrCurrentEvent->time + avgUpTime); ptrNewGridMachine->machineInfo.usagePrice = 0.0; ptrNewGridMachine->machineInfo.reservationPrice = 0.0; ptrNewGridMachine->machineInfo.nextMachine = NULL; ptrNewGridMachine->nextEvent = NULL; InsertEvent(ptrEventList, ptrNewGridMachine); } else { printf("ERROR (allocation planning): merdou o malloc!!!\n"); } event *ptrOutGridMachine; if( (ptrOutGridMachine = malloc(sizeof(event))) ) { ptrOutGridMachine->eventNumber = 0; ptrOutGridMachine->eventID = MACHDEPARTURE; ptrOutGridMachine->time = (ptrCurrentEvent->time + avgUpTime); ptrOutGridMachine->machineInfo.machineID = gridMachinesID; ptrOutGridMachine->machineInfo.source = GRID; ptrOutGridMachine->machineInfo.status = IDLE; ptrOutGridMachine->machineInfo.arrivalTime = ptrCurrentEvent->time; ptrOutGridMachine->machineInfo.departureTime = (ptrCurrentEvent->time + avgUpTime); ptrOutGridMachine->machineInfo.usagePrice = 0.0; ptrOutGridMachine->machineInfo.reservationPrice = 0.0; ptrOutGridMachine->machineInfo.nextMachine = NULL; ptrOutGridMachine->nextEvent = NULL; InsertEvent(ptrEventList, ptrOutGridMachine); } else { printf("ERROR (allocation planning): merdou o malloc!!!\n"); } // insert a new task schedule into the event list event *ptrNewEvent; if( (ptrNewEvent = malloc(sizeof(event))) ) { ptrNewEvent->eventNumber = 0; ptrNewEvent->eventID = TASKSCHEDULE; ptrNewEvent->time = (ptrCurrentEvent->time + 1); ptrNewEvent->scheduleInfo.scheduleID = ++scheduleID; ptrNewEvent->scheduleInfo.scheduleTime = (ptrCurrentEvent->time + 1); ptrNewEvent->scheduleInfo.taskID = ptrAuxTask->taskID; ptrNewEvent->scheduleInfo.jobID = ptrAuxTask->jobID; ptrNewEvent->scheduleInfo.runtime = ptrAuxTask->runtime; ptrNewEvent->scheduleInfo.machineID = ptrNewGridMachine->machineInfo.machineID; ptrNewEvent->scheduleInfo.source = ptrNewGridMachine->machineInfo.source; ptrNewEvent->scheduleInfo.nextSchedule = NULL; ptrNewEvent->nextEvent = NULL; InsertEvent(ptrEventList, ptrNewEvent); } else printf("ERROR (allocation planning): merdou o malloc!!!\n"); // printf("eventID %d (Allocation Planning) time %d ", ptrCurrentEvent->eventID, ptrCurrentEvent->time); // printf("taskID %d jobID %d machineID %d source %d\n", ptrAuxTask->taskID, // ptrAuxTask->jobID, ptrNewGridMachine->machineInfo.machineID, ptrNewGridMachine->machineInfo.source); } // treating the allocation on cloud machines if (found == 0) { machine *ptrAuxCloudMachine; ptrAuxCloudMachine = ptrMachineList; while(ptrAuxCloudMachine) { // TALVEZ TENHA QUE ADICIONAR UM NOVO IF PARA AS MAQUINAS ON-DEMAND if ( (ptrAuxCloudMachine->source == RESERVED || ptrAuxCloudMachine->source == ONDEMAND) && ptrAuxCloudMachine->status == IDLE) { found = 1; allocated = 1; ptrAuxCloudMachine->status = RUNNING; // LEMBAR QUE ESTOU AQUI A UM SEGUNDO DE COMECAR A EXECUCAO EFETIVAMENTE ptrAuxTask->status = STARTED; // LEMBAR QUE ESTOU AQUI A UM SEGUNDO DE COMECAR A EXECUCAO EFETIVAMENTE // insert a new task schedule into the event list event *ptrNewEvent; if( (ptrNewEvent = malloc(sizeof(event))) ) { ptrNewEvent->eventNumber = 0; ptrNewEvent->eventID = TASKSCHEDULE; ptrNewEvent->time = (ptrCurrentEvent->time + 1); ptrNewEvent->scheduleInfo.scheduleID = ++scheduleID; ptrNewEvent->scheduleInfo.scheduleTime = (ptrCurrentEvent->time + 1); ptrNewEvent->scheduleInfo.taskID = ptrAuxTask->taskID; ptrNewEvent->scheduleInfo.jobID = ptrAuxTask->jobID; ptrNewEvent->scheduleInfo.runtime = ptrAuxTask->runtime; ptrNewEvent->scheduleInfo.machineID = ptrAuxCloudMachine->machineID; ptrNewEvent->scheduleInfo.source = ptrAuxCloudMachine->source; ptrNewEvent->scheduleInfo.nextSchedule = NULL; ptrNewEvent->nextEvent = NULL; InsertEvent(ptrEventList, ptrNewEvent); } else printf("ERROR (allocation planning): merdou o malloc!!!\n"); // printf("eventID %d (Allocation Planning) time %d ", ptrCurrentEvent->eventID, ptrCurrentEvent->time); // printf("taskID %d jobID %d machineID %d source %d\n", ptrAuxTask->taskID, // ptrAuxTask->jobID, ptrAuxCloudMachine->machineID, ptrAuxCloudMachine->source); break; } ptrAuxCloudMachine = ptrAuxCloudMachine->nextMachine; } // end of while(ptrAuxCloudMachine) } // end if (found == 0) } // end if (looking for a queued task) ptrAuxTask = ptrAuxTask->nextTask; } // end of while(ptrAuxTask) // if there is any unallocated in-house machine, creates a new donation event if (allocated != 0) { machine *ptrAuxMachine; ptrAuxMachine = ptrMachineList; while(ptrAuxMachine) { if ( ptrAuxMachine->source == LOCAL && ptrAuxMachine->status == IDLE ) { event *ptrNewDonation; if( (ptrNewDonation = malloc(sizeof(event))) ) { ptrNewDonation->eventNumber = 0; ptrNewDonation->eventID = GRIDDONATING; ptrNewDonation->time = ptrCurrentEvent->time; ptrNewDonation->machineInfo.machineID = ptrAuxMachine->machineID; ptrNewDonation->machineInfo.source = ptrAuxMachine->source; ptrNewDonation->machineInfo.status = DONATING; ptrNewDonation->machineInfo.arrivalTime = ptrAuxMachine->arrivalTime; ptrNewDonation->machineInfo.departureTime = ptrAuxMachine->departureTime; ptrNewDonation->machineInfo.usagePrice = ptrAuxMachine->usagePrice; ptrNewDonation->machineInfo.reservationPrice = ptrAuxMachine->reservationPrice; ptrNewDonation->machineInfo.nextMachine = ptrAuxMachine->nextMachine; ptrNewDonation->nextEvent = NULL; InsertEvent(ptrEventList, ptrNewDonation); } else printf("ERROR (Allocation Planning): merdou o malloc!!!\n"); } ptrAuxMachine = ptrAuxMachine->nextMachine; } } printf("eventID %d (Allocation Planning) time %ld ", ptrCurrentEvent->eventID, ptrCurrentEvent->time); printf("Allocation %d\n", allocated); } else printf("ERROR (allocation planning): there is no machine or task list!!!\n"); } else printf("ERROR (allocation planning): wrong eventID!!!\n"); } // end of AllocationPlanning()
void MMatchEventFactoryManager::ParseEvent( MXmlElement& chrElement ) { char szAttrName[ 128 ]; char szAttrValue[ 256 ]; DWORD dwEventListID = 0; DWORD dwEventID = 0; string strEventName; string strAnnounce; EVENT_TYPE EventType; DWORD dwElapsedTime = 0; DWORD dwPercent = 0; DWORD dwRate = 0; vector< EventServerType > vServerType; vector< EventGameType > vGameType; SYSTEMTIME Start, End; float fXPBonusRatio = 0.0f; float fBPBonusRatio = 0.0f; vector< EventPartTime > EventPartTimeVec; memset( &Start, 0, sizeof(SYSTEMTIME) ); memset( &End, 0, sizeof(SYSTEMTIME) ); const int nAttrCnt = chrElement.GetAttributeCount(); for( int i = 0; i < nAttrCnt; ++i ) { chrElement.GetAttribute( i, szAttrName, szAttrValue ); if( 0 == stricmp(EL_EVENT_LIST_ID, szAttrName) ) { dwEventListID = static_cast< DWORD >( atoi(szAttrValue) ); ASSERT( 0 < dwEventListID ); continue; } if( 0 == stricmp(EL_EVENTID, szAttrName) ) { dwEventID = static_cast< DWORD >( atol(szAttrValue) ); if( NULL == MMatchEventDescManager::GetInstance().Find(dwEventID) ) { ASSERT( 0 && "Event.xml에 없는 Event ID입니다." ); mlog( "MMatchEventFactoryManager::ParseEvent - Event.xml에 없는 Event ID(%u)입니다.\n", dwEventID ); return; } continue; } if( 0 == stricmp(EL_NAME, szAttrName) ) { strEventName = MGetStringResManager()->GetString( string(szAttrValue) ); continue; } if( 0 == stricmp(EL_EVENTTYPE, szAttrName) ) { EventType = static_cast< EVENT_TYPE >( atoi(szAttrValue) ); continue; } if( 0 == stricmp(EL_ELAPSEDTIME, szAttrName) ) { dwElapsedTime = static_cast< DWORD >( atoi(szAttrValue) ); continue; } if( 0 == stricmp(EL_PERCENT, szAttrName) ) { dwPercent = static_cast< DWORD >( atol(szAttrValue) ); continue; } if( 0 == stricmp(EL_RATE, szAttrName) ) { dwRate = static_cast< DWORD >( atol(szAttrValue) ); continue; } if( 0 == stricmp(EL_ANNOUNCE, szAttrName) ) { strAnnounce = MGetStringResManager()->GetString( string(szAttrValue) ); continue; } if( 0 == stricmp(EL_XPBONUS_RATIO, szAttrName) ) { fXPBonusRatio = static_cast<float>( atoi(szAttrValue) ) / 100.0f; continue; } if( 0 == stricmp(EL_BPBONUS_RATIO, szAttrName) ) { fBPBonusRatio = static_cast<float>( atoi(szAttrValue) ) / 100.0f; continue; } } MXmlElement chrNode; char szTag[ 128 ]; const int nChrNodeCnt = chrElement.GetChildNodeCount(); EventPartTimeVec.clear(); for( int j = 0; j < nChrNodeCnt; ++j ) { chrNode = chrElement.GetChildNode( j ); chrNode.GetTagName( szTag ); if (szTag[0] == '#') continue; if( 0 == stricmp(EL_SERVERTYPE, szTag) ) { ParseServerType( chrNode, vServerType ); continue; } if( 0 == stricmp(EL_GAMETYPE, szTag) ) { ParseGameType( chrNode, vGameType ); continue; } if( 0 == stricmp(EL_STARTTIME, szTag) ) { ParseStartEndTime( chrNode, Start ); continue; } if( 0 == stricmp(EL_ENDTIME, szTag) ) { ParseStartEndTime( chrNode, End ); continue; } if( 0 == stricmp(EL_PART_TIME, szTag) ) { ParseEventPartTime(chrNode, EventPartTimeVec ); continue; } } // check start end time. if( !CheckUsableEventTimeByEndTime(End) ) { #ifdef _DEBUG mlog( "Time out Event(%u:%u.%u.%u.%u~%u.%u.%u.%u)\n", dwEventID, Start.wYear, Start.wMonth, Start.wDay, Start.wHour, End.wYear, End.wMonth, End.wDay, End.wHour ); #endif return; } // check server type. vector< EventServerType >::iterator itSvrTyp, endSvrTyp; bool bUseEvent = false; endSvrTyp = vServerType.end(); for( itSvrTyp = vServerType.begin(); itSvrTyp != endSvrTyp; ++itSvrTyp ) { // 모든 서버에 적용. if( MSM_ALL == itSvrTyp->ServerType ) { bUseEvent = true; continue; } // 현제 서버 타입에만 적용. if( MGetServerConfig()->GetServerMode() == itSvrTyp->ServerType ) { bUseEvent = true; continue; } } ASSERT( (0 < Start.wYear) && (0 < Start.wMonth) && (0 < Start.wDay) && (0 <= Start.wHour) && (0 < End.wYear) && (0 < End.wMonth) && (0 < End.wDay) && (0 <= End.wHour) ); // check game type. if( bUseEvent ) { EventData ed; vector< EventGameType >::iterator itGmTyp, endGmTyp; endGmTyp = vGameType.end(); for( itGmTyp = vGameType.begin(); itGmTyp != endGmTyp; ++itGmTyp ) { // insert event. ed.dwEventListID = dwEventListID; ed.dwEventID = dwEventID; ed.EventType = EventType; ed.dwGameType = itGmTyp->GameType; ed.ServerType = MGetServerConfig()->GetServerMode(); ed.dwElapsedTime = dwElapsedTime; ed.dwPercent = dwPercent; ed.dwRate = dwRate; ed.Start = Start; ed.End = End; ed.strName = strEventName; ed.strAnnounce = strAnnounce; ed.fXPBonusRatio = fXPBonusRatio; ed.fBPBonusRatio = fBPBonusRatio; ed.EventPartTimeVec.swap( EventPartTimeVec ); InsertEvent( ed ); ++m_LoadEventSize; } } }