Example #1
0
Scheduler::~Scheduler() {
	OUTPUT << "Scheduler destructor" << endl;
	removeKeywords();
	if (schedulerThread)
		delete schedulerThread;
	delete sem_schedulerStart;
}
Example #2
0
/***************************************************************************
 * createListOfRooms
 * Parameter: path - the folder path generated by saveData()
 *            fc - the FileCollection struct to contains the rooms loaded
 *                 from local files
 * Description: This function geneates FileRooms and attaches them to the
 *              FileCollection. The FileRooms' data are populated from
 *              files saved locally by saveData().
 ***************************************************************************/
void createListOfRooms (const char* path, FileCollection* fc)
{
    FILE* file;
    char filepath[100];
    int doorCount;
    char type[20];
    char* ret_str;
    char name[20];
    char line[255];
    char keywords[20];

    int i, j;
    for(i=0; i < MAX_ROOMS; i++)
    {
        doorCount=0;
        sprintf(filepath, "%s/room_%d", path, i+1);

        //open the file
        file = fopen(filepath, "r");

        //get the first line
        while(fgets(line, sizeof(line), file) != NULL) {

            //remove the newline char
            char *pos;
            if ((pos=strchr(line, '\n')) != NULL)
                *pos = '\0';

            //check for keywords and remove them
            if(strstr(line, "ROOM NAME:"))
            {
                ret_str = removeKeywords(line, "ROOM NAME: ", 0);
                sprintf(name, "%s", ret_str);
            }
            else if (strstr(line, "CONNECTION "))
            {
                ret_str = removeKeywords(line, "CONNECTION", 4);
                char* str = malloc(sizeof(char) * strlen(ret_str) + 1);
                sprintf(str, "%s", ret_str);
                fc->rooms[i]->door_list[doorCount] = str;
                doorCount++;
            }
            else if (strstr(line, "ROOM TYPE:"))
            {
                ret_str = removeKeywords(line, "ROOM TYPE: ", 0);
                sprintf(type, "%s", ret_str);

                // setup the start and end rooms
                if(strcmp(ret_str, "START_ROOM") == 0)
                    fc->beginning = fc->rooms[i];
                else if (strcmp(ret_str, "END_ROOM") == 0)
                    fc->end = fc->rooms[i];
           }
        }

        //close the file
        fclose(file);

        //create the FileRoom with the retrieved data
        initFileRoom(fc->rooms[i], filepath, name, type, doorCount);
    }

}