예제 #1
0
void addBookReader(library_t * self,const char * name,const char * readerName){

for(int i = 0;i<List_getSize(self->book);i++){
            book_t * tmpBook = List_get(self->book,i,NULL);
            if(strcmp(tmpBook->name,name)==0 && tmpBook->status == 0){

                user_t * tmpUser = newUser(readerName);
                //List_add(tmpBook->users,List_getSize(tmpBook->users)-1,tmpUser);

                List_t tmpList = tmpBook->users;
                List_add(tmpList,List_getSize(tmpList),tmpUser);


                //user_t * tmpUser1 = List_get(tmpList,List_getSize(tmpList)-1,NULL);
                //puts(tmpUser1->name);

                book_t * nB = newBookchangeParam(name,1,tmpBook->curDaysUsed,"day",tmpList);
                List_remove(self->book,i,NULL);
                List_add(self->book,i,nB);

                return;
            }
    }

}
예제 #2
0
/**
 * \brief Close the Var component
 * \private
 */
void Var_close(void) {
    List* keys;
    int n;

    if(initialized) {
        /* Free readonly variable cache */
        keys = Dictionary_getKeys(ro_cache);
        n = List_getSize(keys);
        for(int i = 0; i < n; i++) {
            free(Dictionary_get(ro_cache, List_get(keys, i)));
        }

        List_destroy(keys);
        Dictionary_destroy(ro_cache);

        /* Free subscriptions */
        keys = Dictionary_getKeys(subscriptions);
        n = List_getSize(keys);
        for(int i = 0; i < n; i++) {
            free(Dictionary_get(subscriptions, List_get(keys, i)));
        }

        List_destroy(keys);
        Dictionary_destroy(subscriptions);

        initialized = false;
    }
}
예제 #3
0
List_t * getOldBooks(library_t * self,int days){
    List_t neededList = List_new();
     for(int i = 0;i<List_getSize(self->book);i++){
             book_t * tmpBook = List_get(self->book,i,NULL);
            if(tmpBook->curDaysUsed >= days){
                List_add(neededList,List_getSize(neededList),tmpBook);
            }
    }
    return neededList;
}
예제 #4
0
void printList(List_t * self){
    for(int i = 0;i<List_getSize(self);i++){
            book_t * tmpBook = List_get(self,i,NULL);
            printf("\nBook number: %i\nBook name: %s\ncurDaysUsed: %i\n",i+1,tmpBook->name,tmpBook->curDaysUsed);
            if(tmpBook->status == 1){
                user_t * tmpUser = List_get(tmpBook->users,List_getSize(tmpBook->users)-1,NULL);
                printf("CurrentUser: %s\n",tmpUser->name);

            }
    }
    puts("");
}
예제 #5
0
List_t * getNeededBooks(library_t * self,int status){
    List_t neededList = List_new();

      for(int i = 0;i<List_getSize(self->book);i++){
             book_t * tmpBook = List_get(self->book,i,NULL);

                    if(tmpBook->status == status){
                       List_add(neededList,List_getSize(neededList),tmpBook);

                    }

    }

    return neededList;
}
예제 #6
0
int main()
{
    Post_t post = Post_new(0, 0);
    Post_addWantedCar(post, "007");
    Person_t carOwner = Person_new("Nikita", "Silchenko");
    Car_t car = Car_new("007");
    Car_setOwner(car, carOwner);
    char buff[128];
    Transist_t transist = Transist_new(car, TRANSIST_DEST_TO);
    Post_subscribeWantedCarTransist(post, carOwner, wantedCarPassed_Person, NULL );
    Post_pass(post, transist);
    List_t carsTo = Post_getCars(post, TRANSIST_DEST_TO);
    printf("%d\n", Post_getTransistsNum(post));
    int lSize = List_getSize(carsTo);
    for(int i = 0; i < lSize; i++){
        char buff[128];
        puts(Person_toString(Car_getOwner(List_get(carsTo, i, NULL)), buff));
    }

    Post_delete(post);
    Transist_delete(transist);
    Person_delete(carOwner);
    Car_delete(car);
    return 0;
}
예제 #7
0
char * DataHandler_convertToXml(DataHandler_t self, char * buff)
{
    xmlDoc * doc = NULL;
	xmlNode * root = NULL;
	xmlChar * str = NULL;

	doc = xmlNewDoc("1.0");
	root = xmlNewNode(NULL, "patients");
	xmlDocSetRootElement(doc, root);

	int numberOfPatients = List_getSize(self->patients);

	for(int i = 0; i < numberOfPatients; i++)
        {
        patient_convertToXml(List_get(self->patients, i, NULL), doc, root);
	}

	xmlDocDumpMemory(doc, &str, NULL);

	strcpy(buff, str);

    free(str);
    xmlFreeDoc(doc);
    return buff;
}
예제 #8
0
List_t Post_getWantedCars(Post_t self){
    int lSize = List_getSize(self->wantedCars);
    List_t retList = List_new();
    for(int i = 0; i < lSize; i++){
        List_append(retList, List_get(self->wantedCars, i, NULL));
    }
    return retList;
}
예제 #9
0
List_t Post_getTransists(Post_t self){
    int lSize = List_getSize(self->transists);
    List_t retList = List_new();
    for(int i = 0; i < lSize; i++){
        List_append(retList, List_get(self->transists, i, NULL));
    }
    return retList;
}
예제 #10
0
bool Post_carIsWanted(Post_t self, const char * carId){
    int lSize = List_getSize(self->wantedCars);
    for(int i = 0; i < lSize; i++){
        if(!strcmp(List_get(self->wantedCars, i, NULL), carId)){
            return true;
        }
    }
    return false;
}
예제 #11
0
void Post_unsubscribeWantedCarTransist(Post_t self, void * receiver, PostEvent_CB cb){
    int lSize = List_getSize(self->wantedCarEvents);
    for(int i = 0; i < lSize; i++){
        Event_t ev = List_get(self->wantedCarEvents, i, NULL);
        if(ev->receiver == receiver && ev->cb == cb){
            List_remove(self->wantedCarEvents, i, NULL);
        }
    }
}
예제 #12
0
List_t Post_getLastNCars(Post_t self, unsigned int N){
    int lSize = List_getSize(self->transists);
    if (N >= lSize) printf("Post: invalid index %d", N);
    List_t retList = List_new();
    for(int i = lSize - N; i < lSize; i++){
        List_append(retList, Transist_getCar(List_get(self->transists, i, NULL)));
    }
    return retList;
}
예제 #13
0
void deleteBook(library_t * self,const char * name){
for(int i = 0;i<List_getSize(self->book);i++){
            book_t * tmpBook = List_get(self->book,i,NULL);
            if(strcmp(tmpBook->name,name)==0){
                List_remove(self->book,i,NULL);
                return;
            }
    }
}
예제 #14
0
List_t Post_getCars(Post_t self, TRANSIST_DEST dest){
    int lSize = List_getSize(self->transists);
    List_t retList = List_new();
    for(int i = 0; i < lSize; i++){
        Transist_t transist = List_get(self->transists, i, NULL);
        if(dest == transist->dest){
            List_append(retList, Transist_getCar(transist));
        }
    }
    return retList;
}
예제 #15
0
void* Stack_pop(Stack stack) {
	int size = List_getSize(stack);

	if(size == 0) return NULL;

	Node node = List_detachNodeAtIndex(stack, size - 1);
	void* data = Node_getData(node);

	Node_destroy(node, NULL);

	return data;
}
예제 #16
0
void Post_pass(Post_t self, Transist_t transist){
    if(Post_carIsWanted(self, transist->car->id)){
        int lSize = List_getSize(self->wantedCarEvents);

        for(int i = 0; i < lSize; i++){
            Event_t ev = List_get(self->wantedCarEvents, i, NULL);
            if(ev->cb != NULL){
                PostEvent_CB fn = ev->cb;
                fn(ev->receiver, self, ev->data);
                break;
            }
        }
    }
    List_append(self->transists, transist);
}
예제 #17
0
void bookDeleteReader(library_t * self,const char * name){

       // printf("ListSize: %i",List_getSize(self));
        for(int i = 0;i<List_getSize(self->book);i++){
             book_t * tmpBook = List_get(self->book,i,NULL);
            if(strcmp(tmpBook->name,name)==0){
                    if(tmpBook->status == 1){
                        book_t * nB = newBookchangeParam(name,0,tmpBook->curDaysUsed+1,"",tmpBook->users);
                        List_remove(self->book,i,NULL);
                        List_add(self->book,i,nB);
                            return;

                    }else{
                            return;
                    }
            }
    }

}
예제 #18
0
/**
 * \brief Close the configuration subsystem in the hub
 * 
 * Free memory and structures associated with a loaded configuration file
 */
void Hub_Config_close(void) {
    List* config_options;
    char* config_option;

    if(config) {
        config_options = Dictionary_getKeys(config);
        while(List_getSize(config_options)) {
            config_option = List_remove(config_options, 0);
            free(Dictionary_get(config, config_option));
        }

        List_destroy(config_options);
        Dictionary_destroy(config);
    }

    if(hub_config_file) {
        free(hub_config_file);
    }
}
예제 #19
0
/**
 * \brief Read a configuration file into a Dictionary
 *
 * Parse the configuration file as described above and store all the key/value
 * pairs into a Dictionary which is returned.
 *
 * \param filename The file to read
 * \return A Dictionary mapping the key/value pairs or NULL if an error occurs
 */
Dictionary* Config_readFile(const char* filename) {
    FILE* config_file = fopen(filename, "r");
    Dictionary* config = NULL;
    char* option;
    char* value;
    int i, tmp = 0;
    char line[MAX_LINE];
    bool comment;

    /* Reset config_errno to success */
    config_errno = CONFIG_SUCCESS;
    config_lineno = 0;

    /* Configuration file opened alright? */
    if(config_file == NULL) {
        config_errno = CONFIG_EFILEACCESS;
        goto config_error;
    }

    /* Create the dictionary object */
    config = Dictionary_new();

    /* Read in line by line until EOF to get each configuration option */
    while(true) {
        line[0] = '\0';

        /* Read until we find a non empty line */
        while(strcmp(line, "") == 0) {
            i = 0;
            comment = false;

            /* Read line */
            while(true) {
                tmp = fgetc(config_file);

                /* End of input/line */
                if(tmp == EOF || tmp == '\n') {
                    break;
                }

                /* Start of a comment */
                if(tmp == '#') {
                    comment = true;
                }

                /* If we're in a comment discard characters */
                if(!comment) {
                    line[i++] = tmp;
                }

                /* Ran out of space. Line too long */
                if(i >= MAX_LINE) {
                    config_errno = CONFIG_ELINETOOLONG;
                    goto config_error;
                }
            }
            config_lineno++;
            line[i] = '\0';

            /* Strip white space from entire line */
            Util_strip(line);

            /* If the line is empty and we have reached the end of file then
               return */
            if(tmp == EOF && strcmp(line, "") == 0) {
                fclose(config_file);
                return config;
            }
        }

        /* Split the line */
        option = value = line;
        for(i = 0; line[i] != '\0'; i++) {
            if(line[i] == '=') {
                line[i] = '\0';
                value = line + i + 1;
                break;
            }
        }

        /* Never found '=' in the line */
        if(option == value) {
            config_errno = CONFIG_EPARSE;
            goto config_error;
        }

        /* Strip spaces from components */
        Util_strip(option);
        Util_strip(value);

        /* Store the pair */
        Dictionary_set(config, option, strdup(value));
    }

 config_error:
    if(config != NULL) {
        List* options = Dictionary_getKeys(config);
        char* option;

        /* Free memory allocated to config values */
        while(List_getSize(options)) {
            option = List_remove(options, 0);
            free(Dictionary_get(config, option));
        }

        List_destroy(options);
        Dictionary_destroy(config);
    }

    if(config_file != NULL) {
        fclose(config_file);
    }

    return NULL;
}
예제 #20
0
int DataHandler_getNumberOfPatients(DataHandler_t self)
{
    return List_getSize(self->patients);
}
예제 #21
0
void addBook(library_t * self,const char * name){
book_t * nB = newBook(name);
List_add(self->book,List_getSize(self->book),nB);
}
size_t SentenceList_getSize(SentenceList_t list){
    return List_getSize(list);
}
예제 #23
0
int Stack_getSize(Stack stack)
{
	return List_getSize(stack);
}
예제 #24
0
/**
 * \brief Process the configuration file
 *
 * Read the configuration file and populate the configuration dictionary
 */
static void Hub_Config_processConfig(void) {
    Dictionary* temp_config;
    List* options;
    char* option;
    char* value;

    /* Initialize config table with default options */
    config = Dictionary_new();
    for(int i = 0; i < sizeof(valid_options) / sizeof(valid_options[0]); i++) {
        Dictionary_set(config, valid_options[i].option, strdup(valid_options[i].default_value));
    }

    /* Locate a configuration file */
    if(Hub_Config_chooseConfigFile() == false) {
        Hub_Logging_log(WARNING, "Could not find configuration file! Continuing with default configuration!");
        return;
    }

    /* Attempt to read the configuration file */
    temp_config = Config_readFile(hub_config_file);

    /* Error handling for Config_readFile */
    if(temp_config == NULL) {
        switch(Config_getError()) {
        case CONFIG_EFILEACCESS:
            Hub_Logging_log(WARNING, Util_format("Failed to open configuration file: %s", strerror(errno)));
            break;
        case CONFIG_ELINETOOLONG:
            Hub_Logging_log(CRITICAL, Util_format("Line exceeded maximum allowable length at line %d", Config_getLineNumber()));
            break;
        case CONFIG_EPARSE:
            Hub_Logging_log(CRITICAL, Util_format("Parse error occured on line %d", Config_getLineNumber()));
            break;
        default:
            Hub_Logging_log(CRITICAL, "Unknown error occured while reading configuration file");
            break;
        }

        /* Bail out and exit */
        Hub_exitError();
    }

    /* Get the list of configuration options in the file */
    options = Dictionary_getKeys(temp_config);

    /* Check each configuration option and if it is valid store it in the real
       configuration table */
    while(List_getSize(options)) {
        /* Remove the first item from the list */
        option = List_remove(options, 0);
        value = Dictionary_get(temp_config, option);

        if(Dictionary_exists(config, option)) {
            /* Valid option, free old value, store new value */
            free(Dictionary_get(config, option));
            Dictionary_set(config, option, value);
        } else {
            Hub_Logging_log(WARNING, Util_format("Unknown configuration option '%s'", option));
        }
    }

    List_destroy(options);
    Dictionary_destroy(temp_config);
}
예제 #25
0
void Post_clearTransistsHistory(Post_t self){
   while(List_getSize(self->transists) > 0){
        List_remove(self->transists, 0, NULL);
   }
}
예제 #26
0
unsigned int Post_getTransistsNum(Post_t self){
    return List_getSize(self->transists);
}