void playFinalMatch(int numGames, int gameNo, team_t* team1, team_t* team2, int* goals1, int* goals2) { playMatchGen(team1, team2, goals1, goals2); // handle visualization handleGame(36 + final_pos(numGames) + gameNo, team1->name, team2->name, *goals1, *goals2); }
void playGroupMatch(int groupNo, team_t* team1, team_t* team2, int* goals1, int* goals2) { playMatchGen(team1, team2, goals1, goals2); // handle visualization handleGame(gameNum[groupNo] + NUMGROUPS * groupNo, team1->name, team2->name, *goals1, *goals2); gameNum[groupNo]++; }
void MetadataDownload::run() { RunProlog(); MetadataLookup* lookup; while ((lookup = moreWork()) != NULL) { MetadataLookupList list; // Go go gadget Metadata Lookup if (lookup->GetType() == kMetadataVideo) { if (lookup->GetSubtype() == kProbableTelevision) list = handleTelevision(lookup); else if (lookup->GetSubtype() == kProbableMovie) list = handleMovie(lookup); else list = handleVideoUndetermined(lookup); if (!list.size() && lookup->GetSubtype() == kUnknownVideo) { list = handleMovie(lookup); } } else if (lookup->GetType() == kMetadataRecording) { if (lookup->GetSubtype() == kProbableTelevision) { if (lookup->GetSeason() > 0 || lookup->GetEpisode() > 0) list = handleTelevision(lookup); else if (!lookup->GetSubtitle().isEmpty()) list = handleVideoUndetermined(lookup); if (!list.size()) list = handleRecordingGeneric(lookup); } else if (lookup->GetSubtype() == kProbableMovie) { list = handleMovie(lookup); if (lookup->GetInetref().isEmpty()) list.append(handleRecordingGeneric(lookup)); } else { list = handleRecordingGeneric(lookup); if (lookup->GetInetref().isEmpty()) list.append(handleMovie(lookup)); } } else if (lookup->GetType() == kMetadataGame) list = handleGame(lookup); // inform parent we have lookup ready for it if (m_parent && list.count() >= 1) { // If there's only one result, don't bother asking // our parent about it, just add it to the back of // the queue in kLookupData mode. if (list.count() == 1 && list.at(0)->GetStep() == kLookupSearch) { MetadataLookup *newlookup = list.takeFirst(); newlookup->SetStep(kLookupData); prependLookup(newlookup); continue; } // If we're in automatic mode, we need to make // these decisions on our own. Pass to title match. if (list.at(0)->GetAutomatic() && list.count() > 1) { if (!findBestMatch(list, lookup->GetTitle())) QCoreApplication::postEvent(m_parent, new MetadataLookupFailure(MetadataLookupList() << lookup)); continue; } LOG(VB_GENERAL, LOG_INFO, QString("Returning Metadata Results: %1 %2 %3") .arg(lookup->GetTitle()).arg(lookup->GetSeason()) .arg(lookup->GetEpisode())); QCoreApplication::postEvent(m_parent, new MetadataLookupEvent(list)); } else { list.append(lookup); QCoreApplication::postEvent(m_parent, new MetadataLookupFailure(list)); } } RunEpilog(); }
int main(int argc, char *argv[]) { const unsigned int EXPECTED_ARGC = 2; const unsigned int KEY_FILE_ARG_INDEX = 1; const unsigned char KEY_CHAR = 'H'; const char ENDLINE[] = "\n"; const char SEPERATOR[] = ","; key_t key = 0; char *shm_addr = NULL; int csv_fd = 0, queue_length = 0, shm_id = 0, sem_id = 0; int job_number = 0, rel_prio = 0, real_prio = 0; initSigactions(); // Initialize the rand() seed. srand(time(NULL)); if(argc != EXPECTED_ARGC) { // No checking needed, exits with error code. write(STDERR_FILENO, NOF_INPUTS_ERROR, sizeof(NOF_INPUTS_ERROR)); exit(EXIT_ERROR_CODE); } // Create fifo. if(mkfifo(FIFO_NAME, ALLOW_READ_WRITE_TO_ALL) < 0) { // No checking needed, exits with error code. write(STDERR_FILENO, MKFIFO_ERROR, sizeof(MKFIFO_ERROR)); exit(EXIT_ERROR_CODE); } writePidToFifo(); // Wait for the queue process' singal. waitForSignal(); printf("got signal from %d!\n", Queue_Pid); // Generate key from the given file key = ftok(argv[KEY_FILE_ARG_INDEX], KEY_CHAR); if(key < 0) { deleteFifo(); // No checking needed, exits with error code. write(STDERR_FILENO, FTOK_ERROR, sizeof(FTOK_ERROR)); exit(EXIT_ERROR_CODE); } // Create shared memory. shm_addr = createSharedMemory(key, &shm_id); // Create semaphore. sem_id = createBinarySemaphore(key, shm_id); // Notify the queue.out process. if(kill(Queue_Pid, SIGUSR1) < 0) { deleteFifo(); // No checking needed, exits with error code. write(STDERR_FILENO, KILL_ERROR, sizeof(KILL_ERROR) - 1); exit(EXIT_ERROR_CODE); } queue_length = readQueueLengthFromFifo(); printf("Got N: %d\n", queue_length); // Done using the fifo - delete it. deleteFifo(); // Game Started! handleGame(shm_id, shm_addr, sem_id, queue_length, &job_number, \ &rel_prio, &real_prio); deleteResources(shm_id, sem_id); // Write results csv_fd = open(CSV_FILE_PATH, O_CREAT | O_APPEND | O_RDWR, ALLOW_READ_WRITE_TO_ALL); if(csv_fd < 0) { // No checking needed, exits with error code. write(STDERR_FILENO, OPEN_ERROR, sizeof(OPEN_ERROR) - 1); exit(EXIT_ERROR_CODE); } writeIntWithEnding(csv_fd, queue_length, SEPERATOR); writeIntWithEnding(csv_fd, job_number, SEPERATOR); writeIntWithEnding(csv_fd, rel_prio, SEPERATOR); writeIntWithEnding(csv_fd, real_prio, ENDLINE); return EXIT_OK_CODE; }
void MetadataDownload::run() { MetadataLookup* lookup; threadRegister("MetadataDownload"); while ((lookup = moreWork()) != NULL) { MetadataLookupList list; // Go go gadget Metadata Lookup if (lookup->GetType() == VID) { if (lookup->GetSeason() > 0 || lookup->GetEpisode() > 0) list = handleTelevision(lookup); else if (!lookup->GetSubtitle().isEmpty()) list = handleVideoUndetermined(lookup); else list = handleMovie(lookup); } // else if (lookup->GetType() == MUSIC) // list = handleMusic(lookup); else if (lookup->GetType() == GAME) list = handleGame(lookup); // inform parent we have lookup ready for it if (m_parent && list.count() >= 1) { // If there's only one result, don't bother asking // our parent about it, just add it to the back of // the queue in GETDATA mode. if (list.count() == 1 && list.at(0)->GetStep() == SEARCH) { MetadataLookup *newlookup = list.takeFirst(); newlookup->SetStep(GETDATA); prependLookup(newlookup); continue; } // If we're in automatic mode, we need to make // these decisions on our own. Pass to title match. if (list.at(0)->GetAutomatic() && list.count() > 1) { if (!findBestMatch(list, lookup->GetTitle())) QCoreApplication::postEvent(m_parent, new MetadataLookupFailure(MetadataLookupList() << lookup)); continue; } VERBOSE(VB_GENERAL, QString("Returning Metadata Results: %1 %2 %3") .arg(lookup->GetTitle()).arg(lookup->GetSeason()) .arg(lookup->GetEpisode())); QCoreApplication::postEvent(m_parent, new MetadataLookupEvent(list)); } else { list.append(lookup); QCoreApplication::postEvent(m_parent, new MetadataLookupFailure(list)); } } threadDeregister(); }