Esempio n. 1
0
void * dump_proc(void * args) {

	struct dump_manager *manager = (struct dump_manager*) args;
	while (1) {
		wait_usb_plugin(manager);
		unmount_usb(manager);
		if (mount_usb(manager) == 0) {

			get_record_id(manager);
			change_led_mode(LED_DUMP);
			if (exe_update(manager) != 0) {
				get_config_info(manager);

				get_time(&(manager->time_export));
				dump_status(manager);
				dump_serial(manager);
				dump_wave(manager);
			}
			unmount_usb(manager);

			change_led_mode(LED_DUMP_FINISHED);
			wait_usb_plugout(manager);

			change_led_mode(LED_NORMAL);
		}

	}

	return NULL;
}
Esempio n. 2
0
static int
insertrecsbypointer(int max, void **tree, const enum insertorder order)
{
    int indx = 0;
    for(indx = 0 ; indx < max ; ++indx) {
        int i = 0;
        int k = 0;
        char kbuf[40];
        char dbuf[60];
        struct example_tentry *mt = 0;
        struct example_tentry *retval = 0;

        i = get_record_id(order,indx);
        snprintf(kbuf,sizeof(kbuf),"%u",i);
        strcpy(dbuf," data for ");
        strcat(dbuf,kbuf);
        printf("insertrec %d\n",i);
        /*  Do it twice so we have test the case where
            tsearch adds and one
            where it finds an existing record. */

        for (k = 0; k < 2 ;++k) {
            mt = make_example_tentry(i,dbuf);
            errno = 0;
            /* tsearch adds an entry if its not present already. */
            retval = dwarf_tsearch(mt,tree, mt_compare_func  );
            if(retval == 0) {
                printf("FAIL ENOMEM in search on  %d, give up insertrecsbypointer\n",i);
                exit(1);
            } else {
                struct example_tentry *re = 0;
                re = *(struct example_tentry **)retval;
                if(re != mt) {
                    if(!k) {
                        printf("FAIL found existing an error %u\n",i);
                        mt_free_func(mt);
                        return 1;
                    } else {
                        printf("found existing ok  %u\n",i);
                    }
                    /*  Prevents data leak: mt was
                        already present. */
                    mt_free_func(mt);
                } else {
                    if(!k) {
                        printf("insert new ok %u\n",i);
                    } else {
                        printf("FAIL new found but expected existing %u\n",i);
                    }
                    /* New entry mt was added. */
                }
            }
        }
    }
    return 0;
}
Esempio n. 3
0
struct dump_manager* get_dump_manager() {
	if (gpdump_manager == NULL) {
		gpdump_manager = malloc(sizeof(struct dump_manager));
		if (gpdump_manager != NULL) {
			memset(gpdump_manager, 0, sizeof(struct dump_manager));

			add_block_filter(&(gpdump_manager->manager), NULL,
					sizeof(struct dump), 8);

			get_record_id(gpdump_manager);
			pthread_create(&(gpdump_manager->thread_dump), NULL, dump_proc,
					gpdump_manager);
		}
	}
	return gpdump_manager;
}
Esempio n. 4
0
static int
findrecsbypointer(int max,int findexpected,
    const void **tree,
    const enum insertorder order)
{
    int indx = 0;
    for(indx = 0 ; indx < max ; ++indx) {
        char kbuf[40];
        char dbuf[60];
        dbuf[0] = 0;
        struct example_tentry *mt = 0;
        struct example_tentry *retval = 0;
        int i = 0;

        i = get_record_id(order,indx);
        snprintf(kbuf,sizeof(kbuf),"%u",i);
        mt = make_example_tentry(i,dbuf);
        printf("findrec %d\n",i);
        retval = dwarf_tfind(mt,(void *const*)tree,mt_compare_func);
        if(!retval) {
            if(indx < findexpected) {
                mt_free_func(mt);
                printf("FAIL tfind on %s is FAILURE\n",kbuf);
                return 1;
            } else {
                printf("Not found with tfind on %s is ok\n",kbuf);
            }
        } else {
            printf("found ok %u\n",i);
            if(indx >= findexpected) {
                mt_free_func(mt);
                printf("FAIL: found with tfind on %s is FAILURE\n",kbuf);
                return 1;
            } else {
                printf("Found with tfind on %s is ok\n",kbuf);
            }
        }
        mt_free_func(mt);
    }
    return 0;
}
Esempio n. 5
0
/* The dodump flag is so we can distinguish binarysearch actions
   from the binarysearch with eppinger mods easily in the test output.
   The difference is slight and not significant,
   but the difference is what we look for when we look.
*/
static int
delrecsbypointer(int max,int findexpected, void **tree,const enum insertorder order,int dodump)
{
    int indx = 0;
    for (indx = 0; indx < max; indx++) {
        struct example_tentry *mt = 0;
        struct example_tentry *re3 = 0;
        void *r = 0;

        int i = 0;

        i = get_record_id(order,indx);
        printf("delrec %d\n",i);
        mt = make_example_tentry(i,0);
        r = dwarf_tfind(mt,(void *const*)tree,mt_compare_func);
        if (r) {
            /*  This is what tdelete will delete.
                tdelete just removes the reference from
                the tree, it does not actually delete
                the memory for the entry itself.
                In fact there is no way to know for sure
                what was done just given the return
                from tdelete.  You just just assume the delete
                worked and use the tfind result to delete
                your contents if you want to.*/
            re3 = *(struct example_tentry **)r;
            if(indx < findexpected) {
                ;
            } else {
                mt_free_func(mt);
                printf("FAIL delrecsbypointer should not have found record to delete for %d\n",i);
                return 1;
            }
            r = dwarf_tdelete(mt,tree,mt_compare_func);
            if (! *tree) {
                printf("tree itself now empty\n");
            }
            /* We don't want the 'test' node left around. */
            if(r) {
                /*  If the node deleted was root, r
                    is really the new root, not the parent.
                    Or r is non-null but bogus.
                    (so don't print).
                    */
                printf("tdelete returned parent or something.\n");
            } else {
                printf("tdelete returned NULL, tree now empty.\n");
#ifdef HASHSEARCH
                printf("Only really means some hash chain is now empty.\n");
#endif /* HASHSEARCH */
            }
            mt_free_func(mt);
            mt_free_func(re3);
        } else {
            if(indx >= findexpected) {
                ;
            } else {
                mt_free_func(mt);
                printf("FAIL delrecsbypointer should have found record to delete for %d\n",i);
                return 1;
            }
            /* There is no node like this to delete. */
            /* We don't want the 'test' node left around. */
            mt_free_func(mt);
        }
        if (dodump) {
            dwarf_tdump( *tree,mt_keyprint,"In Delrecs");
        }
        dwarf_twalk( *tree,walk_entry);
    }
    return 0;
}