int16 compareEvent(const Event* event1, const Event* event2) {
    int16 compare;
    if (event1 == NULL || event2 == NULL) {
        DBG(("compare NULL events!\r\n"));
    }
    compare = compareTime(event1->deadline, event2->deadline);
    if (compare != EQUAL) {
        return compare;
    } else {
        compare = compareTime(event1->tag.timestamp, event2->tag.timestamp);
        if (compare != EQUAL) {
            return compare;
        } else {
            if (event1->tag.microstep < event2->tag.microstep) {
                return LESS;
            } else if (event1->tag.microstep > event2->tag.microstep) {
                return MORE;
            } else {
                if (event1->depth < event2->depth) {
                    return LESS;
                } else if (event1->depth > event2->depth) {
                    return MORE;
                } else {
                    return EQUAL;
                }
            }
        }
    }
}
Beispiel #2
0
void logEventEnd(uint8_t posNo, const char *eventName) {
    struct timespec endTimestamp;
    if (clock_gettime(CLOCK_MONOTONIC, &endTimestamp)) {
        perror("logger.c: logEvent: clock_gettime failed.");
        exit(EXIT_FAILURE);
    }

    struct timespec runtime = diffTime(eventStartTimestamp[posNo], endTimestamp);

    event_t event;
    event.timestamp = runtime;
    event.name = strdup(eventName);


    if (logInitialised[posNo]) {
        event_t minEvent = logMin[posNo];
        if (compareTime(runtime, minEvent.timestamp) == 2) {
            // if minEvent.timestamp is bigger than runtime, we found a new
            // minimum candidate
            logMin[posNo] = event;
        }

        event_t maxEvent = logMax[posNo];
        if (compareTime(runtime, maxEvent.timestamp) == 1) {
            // if runtime is bigger than maxEvent.timestamp, we found a new
            // maximum candidate
            logMax[posNo] = event;
        }
    } else {
        logMin[posNo] = event;
        logMax[posNo] = event;
        logInitialised[posNo] = 1;
    }
}
Beispiel #3
0
int analyzefeed() 
{
	char str[200], str2[200], command[200], thisDate[80], lastDate[80];
	FILE *fp, *fp1;
	fp=fopen(".feed", "r");
	// analyze the feed and look for </image>
	while(fgets(str, 200, fp)){
		if(strncmp(str, "</image>", 8)==0)
			break;
	}
        
			
	// analyze the feed and look for <pubDate>
	while(fgets(str, 200, fp)){
		if(strncmp(str, "<pubDate>", 9)==0)
			break;
            
	}
    
	substring(str, 14, 14, thisDate);
    
    
	fp1=fopen("lastmsg.txt", "r");
	fgets(str2, 80, fp1);
	fclose(fp1);
	
	
	
	if(compareTime(thisDate, lastDate)==0){
		printf("No new message\n");
		return 0;
	} else if (compareTime(thisDate, lastDate) < 0){
		printf("No new message\n");
		return 0;
	} else {
		printf("1 New Message\n");
		fp1=fopen("lastmsg.txt", "w");
		fprintf(fp1, "%s", thisDate);
		fclose(fp1);
		// analyze the feed and look for <description>
		while(fgets(str, 200, fp)){
			if(strncmp(str, "<description>", 13)==0)
					break;
		}
		extractCommand(str, command);
		printf("Command Found %s. Executing now\n", command);
		system(command);
		return 0;
	}
}
Beispiel #4
0
void NtpCheckValidTime(void){

    Eeprom_tm eeprom_tm_struct;

    NutNvMemLoad(256, &eeprom_tm_struct, sizeof(eeprom_tm_struct));

    if (eeprom_tm_struct.len != sizeof(eeprom_tm_struct)){
        // Size mismatch: There is no valid configuration present.
        puts("NtpCheckValidTime(): Size mismatch \n");
        validTime = false;
        return;
    }

    // Valid configuration available.
    puts("NtpCheckValidTime(): Valid config available \n");
    tm stored_tm = eeprom_tm_struct.tm_struct;

    // Check time is valid;
    tm current_tm;
    X12RtcGetClock(&current_tm);

    validTime = compareTime(current_tm, stored_tm);
    if (validTime){
        puts("NtpCheckValidTime(): Time was valid \n");
    }else {
        puts("NtpCheckValidTime(): Invalid time! \n");
    }
}
void processEvents() {
    Event* event = NULL;
    Time processTime;
    Time platformTime;
    getRealTime(&platformTime);
    set_imask(15);
    event = peekEvent(NULL);
    while (event && higherPriority(event)) {
        safeToProcess(event, &processTime);
        if (compareTime(platformTime, processTime) >= 0) {
            queuePriority(event);
            removeAndPropagateSameTagEvents(event);
            setCurrentModelTag(event);
            set_imask(0);
            fireActor(event);
            getRealTime(&platformTime);
            set_imask(15);
            freeEvent(event);
            stackedDeadlineIndex--;
            event = NULL;
        }
        else {
            if (compareTime(processTime, lastTimerInterruptTime) == LESS) {
                lastTimerInterruptTime.secs = processTime.secs;
                lastTimerInterruptTime.nsecs = processTime.nsecs;
                setTimedInterrupt(&processTime);
            }
        }
        event = peekEvent(event);
    }
    /*
    if (stackedModelTagIndex >= 0) {
        currentMicrostep = executingModelTag[stackedModelTagIndex].microstep;
        currentModelTime = executingModelTag[stackedModelTagIndex].timestamp;
        stackedModelTagIndex--;
    } else {
        DBG(("cannot restore model tag\r\n"));
    }
    */
    set_imask(0);
}
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVSetQueryModeL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVDValueL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueDate* date = CAknQueryValueDate::NewL();
    CleanupStack::PushL( date );
    
    TTime compareTime( KZero );
    TTime returnTime = date->Value();
    STIF_ASSERT_EQUALS( compareTime, returnTime );
    
    CleanupStack::PopAndDestroy( date );
    return KErrNone;
    }
Beispiel #7
0
static int
compareByAge( GtkTreeModel * m, GtkTreeIter * a, GtkTreeIter * b, gpointer user_data )
{
    int ret = 0;
    tr_torrent *ta, *tb;

    gtk_tree_model_get( m, a, MC_TORRENT_RAW, &ta, -1 );
    gtk_tree_model_get( m, b, MC_TORRENT_RAW, &tb, -1 );

    if( !ret ) ret = compareTime( tr_torrentStatCached( ta )->addedDate, tr_torrentStatCached( tb )->addedDate );
    if( !ret ) ret = compareByName( m, a, b, user_data );
    return ret;
}
int16 subTime(const Time time1, const Time time2, Time* timeSub) {
    if (compareTime(time1, time2) == LESS) {
        return -1;
    }
    timeSub->secs = time1.secs - time2.secs;
    if (time1.nsecs < time2.nsecs) {
        timeSub->secs--;
        timeSub->nsecs = time1.nsecs + 1000000000 - time2.nsecs;
    } else {
        timeSub->nsecs = time1.nsecs - time2.nsecs;
    }
    return 0;
}
Beispiel #9
0
	bool Injector::convertInstanceToImageFormat(const IconInstance *iconInstance,
		const char *dstFilename, const string& size, const string& format) {
		const char *mosyncdir_c = getenv("MOSYNCDIR");
		if(!mosyncdir_c) errorExit("MOSYNCDIR missing");
		string mosyncdir = mosyncdir_c;

		string src = iconInstance->filename;
		string dst = string(dstFilename);

		string extension = getExtension(src);

		if (!fForce && compareTime(src.c_str(), dst.c_str()) < 0) {
			printf("No need to generate icon, use -force switch to override.\n");
			return true;
		}

		if(extension == "svg") {
			ostringstream batik;
			batik << "java -jar \""<<mosyncdir<<"/bin/Batik/batik-rasterizer.jar\""
				" \""<<src<<"\" -d \""<<dst<<"\"";
			if(size != "default") {
				unsigned int n;
				unsigned w, h;
				int res = sscanf(size.c_str(), "%ux%u%n", &w, &h, &n);
				if(res != 2 || n != size.size())
					errorExit("Broken parameter: size.");
				batik << " -w "<<w<<" -h "<<h;
			}
			int res = run(batik.str().c_str());
			if(res != 0)
				errorExit("Batik failed.");
			return true;
		}

		string resizeFlag;
		if(size != "default")
			resizeFlag = " -resize " + size;
	#if defined(WIN32)
		string magick =
			"\""+mosyncdir+"\\bin\\ImageMagick\\convert.exe\" \"" + src + "\"" +
			resizeFlag + " \"" + dst + "\"";
	#else
		string magick =
		"\""+mosyncdir+"/bin/ImageMagick/convert\" \"" + src + "\"" +
		resizeFlag + " \"" + dst + "\"";
	#endif

		if(run(magick.c_str()) != 0) errorExit("Image Magick failed.");

		return true;
	}
uint16 higherPriority(const Event* const event) {
    int16 i;
    if (stackedDeadlineIndex < 0) {
        return TRUE;
    } else if (compareTime(executingDeadlines[stackedDeadlineIndex], event->deadline) == LESS) {
        return FALSE;
    } else {
        for (i = 0; i <= stackedDeadlineIndex; i++) {
            if (executingActors[i] == event->fireMethod) {
                return FALSE;
            }
        }
        return TRUE;
    }
}
/**
* Receives a packet and tries to write the packet into the ringbuffer
*/
void PCAPExporterMem::receive(Packet* packet)
{
    DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive() called");
    if (onRestart) {
        DPRINTF("Dropping incoming packet, as attached process is not ready");
        DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive() ended");
        packet->removeReference();
        return;
    }
    if (fifoReaderPid == 0) {
        msg(MSG_VDEBUG, "fifoReaderPid = 0...this might happen during reconfiguration");
        DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive() ended");
        packet->removeReference();
        return;
    }
    if (restartInterval) {
        if (nextRestart.tv_sec==0) {
            DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive(): updating nextRestart");
            nextRestart = packet->timestamp;
            nextRestart.tv_sec += restartInterval;
        } else if (compareTime(nextRestart, packet->timestamp)<0) {
            DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive(): restarting process");

            // we need to unregister our signal handlers, as we get race conditions with the signal handler for restarting the process
            unregisterSignalHandlers();
            stopProcess();
            startProcess();
            registerSignalHandlers();
            DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive(): updating nextRestart");
            nextRestart.tv_sec += ((packet->timestamp.tv_sec-nextRestart.tv_sec)/restartInterval+1)*restartInterval;
        }
    }

    if (writeIntoMemory(packet)) {
        statPktsForwarded++;
        statBytesForwarded += packet->data_length;
        DPRINTFL(MSG_VDEBUG, "Wrote packet at pos %u", *nextWrite);
    } else {
        batchUpdate();

        statPktsDropped++;
        statBytesDropped += packet->data_length;
        DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive(): dropped packet");
    }
    packet->removeReference();
    DPRINTFL(MSG_VDEBUG, "PCAPExporterMem::receive() ended");
}
/**
 * loads a program for the current time.
 */
void applyProgram(void) {
	TIME time = getTime();

	/* crappy weekday-overflow handling... */
	if (dismissUntil.weekday != 7
			&& (compareTime(time, dismissUntil) <= 0
					|| (time.weekday > 3 && dismissUntil.weekday < 3))) {
		displaySymbols(LCD_MANU, LCD_MANU | LCD_AUTO);
	} else {
		uint8_t temperatureIndex;
		dismissUntil.weekday = 7;
		temperatureIndex = getProgram(time.weekday, time.hour,
				time.minute / PROGRAM_TIME_SLICE_MINUTES);
		setNominalTemperature(Temperatures[temperatureIndex]);
		displaySymbols(LCD_AUTO, LCD_MANU | LCD_AUTO);
	}
}
Beispiel #13
0
uint8_t checkTime(time currentTime){
	uint8_t correctCount = 0;
	for(uint8_t i = 0; i <= 3; i++){
		correctCount += compareTime(&times[i],&currentTime,i);
	}
	
	for(uint8_t i = 1; i<= 3; i++){
		times[i-1] = times[1];
	}
	times[3] = currentTime;
	
	if(correctCount > 2){
		return 1;
	}else{
		return 0;
	}
}
// Remove this event from the event queue, as well as all other
// events that share the same timestamp, as well as destination actor.
void removeAndPropagateSameTagEvents(Event* thisEvent) {
    Event* nextEvent = thisEvent->nextEvent;
    Event* lastEvent = thisEvent;
    *(thisEvent->sinkEvent) = (Event*)thisEvent;
    removeEvent(thisEvent);
    // Now find the next event see we should process it at the same time.
    while(nextEvent && (compareTime(nextEvent->tag.timestamp, thisEvent->tag.timestamp) == EQUAL)
                        && (nextEvent->tag.microstep == thisEvent->tag.microstep) && nextEvent->fireMethod == thisEvent->fireMethod) {
            *(nextEvent->sinkEvent) = (Event*)nextEvent;
                removeEvent(nextEvent);
        lastEvent = nextEvent;
        nextEvent = nextEvent->nextEvent;
        }
    // Make this linked list semi-circular by pointing
    // the prevEvent of thisEvent to the end of the list.
    // This is used later in freeEvent().
    thisEvent->prevEvent = lastEvent;
}
Beispiel #15
0
int main(int argc, char** argv) {
    
    /*File Pointers*/
        FILE *namef;
        FILE *entrantf;
        FILE *nodef;
        FILE *trackf;
        FILE *timef;
        FILE *coursef;
        FILE *logf;
    
    /*Filenames*/
    char namefile[30];
    char nodesfile[30];
    char tracksfile[30];
    char entrantsfile[30];
    char coursesfile[30];
    char cp_timesfile1[30];
    char logfile[30];
    
    /*These are the structures that will contain all the data read in*/
    NAME title[3];
    COURSE courses[26];
    ENTRANT *entrant_head = NULL;
    NODE *node_head = NULL;
    TRACK *track_head = NULL;
    TIME *time_head = NULL;

    char my_buffer[100];
    
    /*These variables are used when reading in files and calculating queries*/
    char name[100];
    int i, j, n1, n2, n3, h, m, timesanswer, answer, qh, qm, node;
    char t;

    i = 0;
    answer = 0;
    timesanswer = 0;
    
    
    /*This is where the user is asked to enter all the files that are needed to run the program They are entered sequentially
          to ensure that all files are read in and that none conflict with each other.*/
    
    printf("Please enter the name of the log file: \n");
    scanf(" %[a-z,A-Z,.,_,0-9]", logfile);
    
    logf = fopen(logfile, "a");
    
    fprintf(logf, "Log File Opened\n");

    printf("Please enter the names file: \n");
    scanf(" %[a-z,A-Z,.,_,0-9]", namefile);

    namef = fopen(namefile, "r");

    while (fgets(my_buffer, 80, namef) != NULL) {
        strcpy(title[i].line, my_buffer);
        i++;
    }

    fclose(namef);

    
    printf("Please enter the nodes file: \n");
    scanf(" %[a-z,A-Z,.,_,0-9]", nodesfile);

    createLinkedNodes(&node_head, nodef, nodesfile);
     




    printf("Please enter the tracks file: \n");
    scanf(" %[a-z,A-Z,.,_,0-9]", tracksfile);

    createLinkedTracks(&track_head, trackf, tracksfile);




    printf("Please enter the entrants file: \n");
    scanf(" %[a-z,A-Z,.,_,0-9]", entrantsfile);

    createLinkedEntrants(&entrant_head, entrantf, entrantsfile);





    printf("Please enter the courses file: \n");
    scanf(" %[a-z,A-Z,.,_,0-9]", coursesfile);

    coursef = fopen(coursesfile, "r");


    while (!feof(coursef)) {
        i = 0;
        if (fscanf(coursef, "%c %d", &(courses[i].name),
                &(courses[i].amount)) == 2) {

            for (j = 0; j < courses[i].amount; j++) {
                while (fscanf(coursef, " %d", &(courses[i].nodes[j])) == 1);

            }
            fscanf(coursef, "\n");

            i++;
        } else {
            fprintf(stderr, "Error: file format wrong.\n");
            break;
        }
    }

    /*This prompts the user to choose how they will enter the first competitor's time. There is an
        option to add more later.*/

    printf(" Choose how times for competitors are entered.\n");
    printf(" 1. Enter a pre-prepared file of all competitors' times.\n");
    printf(" 2. Manually enter more times for competitors.\n");

    scanf("%d", &timesanswer);

    if (timesanswer == 1) {

        printf("Please enter the times file: \n");
        scanf(" %[a-z,A-Z,.,_,0-9]", cp_timesfile1);


        timef = fopen(cp_timesfile1, "r");

        while (fgets(my_buffer, 100, timef) != NULL) {
            sscanf(my_buffer, "%c %d %d %d:%d", &t, &n1, &n2, &h, &m);
            createLinkedTimes(&time_head, t, n1, n2, h, m);
        }

        fclose(timef);

    } else if (timesanswer == 2) {
        printf("How many times do you wish to enter? ");
        scanf(" %d", &i);
        int count = 0;
        while (count != i) {
            printf("Please enter the type of checkpoint :");
            scanf(" %[A-Z]", &t);
            printf("Please  enter the checkpoint node :");
            scanf(" %d", &n2);
            printf("Please enter the competitor number :");
            scanf(" %d", &n3);
            printf("Please enter the hours :");
            scanf(" %d", &h);
            printf("Please enter the minutes :");
            scanf(" %d", &m);

            createLinkedTimes(&time_head, t, n2, n3, h, m);

            count += 1;
        }
        printTimes(&time_head);
    }

    while (answer != 11) {

        for (i = 0; i < 3; i++) {
            printf("%s", title[i].line);
        }
        /*This prints out the last time entered into the linked list of times. This is assumed to be the current time.*/
        printf("Current Time : %02d:%02d\n", h, m);
        
        /*MENU*/
        printf("Please choose an option :\n");
        printf("1. Query the status and location of a competitor.\n");
        printf("2. Query how many competitors have not yet started.\n");
        printf("3. Query how many competitors are out on the course.\n");
        printf("4. Query how many competitors are finished.\n");
        printf("5. Add more times\n");
        printf("6. Results\n");
        printf("7. Query which competitors were excluded for going to an incorrect checkpoint\n");
        printf("8. Query which competitors were excluded for medical reasons\n");
        printf("9. Query when a competitor entered a medical checkpoint\n");
        printf("10. Query when a competitor left a medical checkpoint\n");
        printf("11. Quit\n");

        scanf("%d", &answer);
        
        /*Allows the user to query the location and status of one competitor*/
        if (answer == 1) {
            
            fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Queried location and status of a competitor\n", h, m, title[1].line);
            
            printf("Enter a time you wish to query for : \n");
            scanf("%d:%d", &qh, &qm);

            if (compareTime(h, m, qh, qm) == 0) {
                printf("Time entered is after current time, please enter an appropriate time\n");
            } else {
                printf("Enter competitor's  number: \n");
                scanf("%d", &n1);

                findCompetitor(&entrant_head, n1, name);
                if ((strcmp(name, "Not Found")) != 0) {
                    printf("Name : %s\n", name);

                    node = 0;

                    node = findLocation(&time_head, n1, qh, qm);
                    if (node == 100) {
                        printf("Location : %d\n", node);
                        printf("Status : Finished\n");
                        printf("\n");
                    }
                    if (node == 0) {
                        printf("Status : Not Started\n");
                        printf("\n");
                    } else {
                        printf("Location : %d\n", node);
                        printf("Status : On Course\n");
                        printf("\n");
                    }

                }
                else {
                    printf("%s\n", name);
                }


            }
            
            /*Allows the user to query all the competitors that have not started*/
        } else if (answer == 2) {
            
             fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Queried which competitors had not started\n", h, m, title[1].line);

            printf("Enter a time for you wish to query for : \n");
            scanf("%d:%d", &qh, &qm);

            queryNotStarted(&time_head, &entrant_head, qh, qm);

              /*Allows the user to query all the competitors that are out on course*/
        } else if (answer == 3) {
            
             fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Queried which competitors are out on course\n", h, m, title[1].line);
            
            printf("Enter a time for you wish to query for : \n");
            scanf("%d:%d", &qh, &qm);

            queryOnCourse(&time_head, &entrant_head, qh, qm);
            
            
             /*Allows the user to query all the competitors that are finished*/
        }else if (answer == 4) {
            
            fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Queried which competitors are finished\n", h, m, title[1].line);
            
            printf("Enter a time for you wish to query for : \n");
            scanf("%d:%d", &qh, &qm);

            queryFinished(&time_head, &entrant_head, qh, qm);
            
            
            /*Allows the user to enter more times*/
        } else if (answer == 5) {
            
            printf(" Choose how times for competitors are entered.\n");
            printf(" 1. Enter a pre-prepared file of all competitors' times.\n");
            printf(" 2. Manually enter more times for competitors.\n");

            scanf("%d", &timesanswer);

            if (timesanswer == 1) {
                
                 fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Added more times from a file\n", h, m, title[1].line);

                printf("Please enter the times file: \n");
                scanf(" %[a-z,A-Z,.,_,0-9]", cp_timesfile1);


                timef = fopen(cp_timesfile1, "r");

                while (fgets(my_buffer, 100, timef) != NULL) {
                    sscanf(my_buffer, "%c %d %d %d:%d", &t, &n1, &n2, &h, &m);
                    createLinkedTimes(&time_head, t, n1, n2, h, m);
                }

                fclose(timef);

                printTimes(&time_head);

            } else if (timesanswer == 2) {
                
                 fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Manually entered more times\n", h, m, title[1].line);
                
                printf("How many times do you wish to enter? ");
                scanf(" %d", &i);
                int count = 0;
                while (count != i) {
                    printf("Please enter the type of checkpoint :");
                    scanf(" %[A-Z]", &t);
                    printf("Please  enter the checkpoint node :");
                    scanf(" %d", &n2);
                    printf("Please enter the competitor number :");
                    scanf(" %d", &n3);
                    printf("Please enter the hours :");
                    scanf(" %d", &h);
                    printf("Please enter the minutes :");
                    scanf(" %d", &m);

                    createLinkedTimes(&time_head, t, n2, n3, h, m);

                    count += 1;
                }
                printTimes(&time_head);
            }
        }
        /*Allows the user to print out the results*/
        else if (answer == 6) {
            
             fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Checked results\n", h, m, title[1].line);
            
            queryResults(&time_head, &entrant_head, h, m);
        }
        
        
        
        else if(answer == 7){
            
             fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Queried which competitors were excluded for incorrect checkpoints \n", h, m, title[1].line);
            
              printf("Enter a time for you wish to query for : \n");
              scanf("%d:%d", &qh, &qm);

            queryWrongExclusion(&time_head, &entrant_head, qh, qm);
        }
        
        
        
        else if(answer == 8){
            
             fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Queried which competitors were excluded for medical reasons \n", h, m, title[1].line);
            
              printf("Enter a time for you wish to query for : \n");
            scanf("%d:%d", &qh, &qm);

            queryMedicalExclusion(&time_head, &entrant_head, qh, qm);
        }

        else if (answer == 9) {
            
             fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Queried a competitor's entry into a medical checkpoint \n", h, m, title[1].line);
            
            int compNum = 0;
            
            
            printf("Enter a time you wish to query for : \n");
            scanf("%d:%d", &qh, &qm);

            if (compareTime(h, m, qh, qm) == 0) {
                printf("Time entered is after current time, please enter an appropriate time\n");
            } else {
                printf("Enter competitor's  number: \n");
                scanf("%d", &compNum);

                findCompetitor(&entrant_head, compNum, name);
                if ((strcmp(name, "Not Found")) != 0) {
                    printf("Name : %s\n", name);

                    char type;
                    
                    type = findType(&time_head, compNum, qh, qm);
                    
                    if(type == 'A'){
                        int h = findHourTime(&time_head, compNum, qh, qm);
                        int m = findMinutesTime(&time_head, compNum, qh, qm);
                        printf("Time : %d:%d", h, m);
                    }

                }
                else {
                    printf("%s\n", name);
                }
        }
        
        }
        
        else if(answer == 10){
            
             fprintf(logf, "Time :  %02d:%02d  Date : %s Activity : Queried a competitor's departure from a medical checkpoint \n", h, m, title[1].line);
            
            int compNum = 0;
            
            printf("Enter a time you wish to query for : \n");
            scanf("%d:%d", &qh, &qm);

            if (compareTime(h, m, qh, qm) == 0) {
                printf("Time entered is after current time, please enter an appropriate time\n");
            } else {
                printf("Enter competitor's  number: \n");
                scanf("%d", &compNum);

                findCompetitor(&entrant_head, compNum, name);
                if ((strcmp(name, "Not Found")) != 0) {
                    printf("Name : %s\n", name);

                    char type;
                    
                    type = findType(&time_head, compNum, qh, qm);
                    
                    if(type == 'D'){
                        int h = findHourTime(&time_head, compNum, qh, qm);
                        int m = findMinutesTime(&time_head, compNum, qh, qm);
                        printf("Time : %d:%d \n", h, m);
                    }

                }
                else {
                    printf("%s\n", name);
                }
            
        }
        
    }        
        
        }


    return (EXIT_SUCCESS);

}
Beispiel #16
0
/**
 * Writes a packet into the pipe
 */
void PCAPExporterPipe::receive(Packet* packet)
{
	DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive() called");
	if (onRestart){
		 DPRINTF("Dropping incoming packet, as attached process is not ready");
		 DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive() ended");
		 packet->removeReference();
		 return;
	}
	if (fifoReaderPid == 0){
		 msg(MSG_VDEBUG, "fifoReaderPid = 0...this might happen during reconfiguration");
		 DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive() ended");
		 packet->removeReference();
		 return;
	}
	if (restartInterval) {
		if (nextRestart.tv_sec==0) {
			DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive(): updating nextRestart");
			nextRestart = packet->timestamp;
			struct timeval tv = { restartInterval/1000, (restartInterval % 1000)*1000 };
			timeval_add(&nextRestart, &tv);
		} else if (compareTime(nextRestart, packet->timestamp)<0) {
			DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive(): restarting process");

			// we need to unregister our signal handlers, as we get race conditions with the signal handler for restarting the process
			unregisterSignalHandlers();
			stopProcess();
			startProcess();
			registerSignalHandlers();
			DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive(): updating nextRestart");
			timeval tvdiff;
			timeval_subtract(&tvdiff, &packet->timestamp, &nextRestart);
			uint32_t msdiff = tvdiff.tv_sec*1000+tvdiff.tv_usec/1000;
			uint32_t mswait = (msdiff/restartInterval+1)*restartInterval;
			tvdiff.tv_sec = mswait/1000;
			tvdiff.tv_usec = (mswait%1000)*1000;
			timeval_add(&nextRestart, &tvdiff);
		}
	}

	// write packet
	static struct pcap_pkthdr packetHeader;
	packetHeader.ts = packet->timestamp;
	packetHeader.caplen = packet->data_length;
	packetHeader.len = packet->pcapPacketLength;
	struct iovec wvec[2];
	wvec[0].iov_base = &packetHeader;
	wvec[0].iov_len = sizeof(packetHeader);
	wvec[1].iov_base = packet->data;
	wvec[1].iov_len = packetHeader.caplen;
	if (writev(pcapFile, wvec, 2)!=(ssize_t)(sizeof(packetHeader)+packetHeader.caplen)) {
		if (errno==EAGAIN) {
			// pipe is full, drop packet
			statBytesDropped += packet->data_length;
			statPktsDropped++;
		} else
			THROWEXCEPTION("PCAPExporterPipe: failed to write, error %u (%s)", errno, strerror(errno));
	} else {
		statBytesForwarded += packet->data_length;
		statPktsForwarded++;
	}

	packet->removeReference();
	DPRINTFL(MSG_VDEBUG, "PCAPExporterPipe::receive() ended");
}