예제 #1
0
void ScanTest(OSCQueue q) {
    myObj *item;

    printf("Start scan.\n");
    OSCQueueScanStart(q);

    while(1) {
	item = (myObj *) OSCQueueScanNext(q);
	if (item == 0) {
	    printf("End of scan.\n");
	    break;
	}
	printf("  Next scan object:  time tag %llu, data %s\n",
	       item->timetag, item->data);
    }

    printf("Queue should be unchanged after scan:   ");
    OSCQueuePrint(q);

    printf("Another scan, this time removing data that begins with 's'.\n");
    OSCQueueScanStart(q);

    while(1) {
        item = (myObj *) OSCQueueScanNext(q);
        if (item == 0) {
            printf("End of scan.\n");
            break;
	}
	if (item->data[0] == 's') {
	    printf("  Scan object data begins with 's':  time tag %llu, data %s\n",
               item->timetag, item->data);
	    printf("How the queue looks before removal:   ");
	    OSCQueuePrint(q);
	    OSCQueueRemoveCurrentScanItem(q);
	    printf("How the queue looks after removal:   ");
	    OSCQueuePrint(q);
	}
    }
}
예제 #2
0
OSCQueue OSCNewQueue(int maxItems, void *(*InitTimeMalloc)(int numBytes)) {
  OSCQueue result;

  if (maxItems > CAPACITY) fatal_error("Increase CAPACITY in OSC-priority-queue.c");

  result = (*InitTimeMalloc)(sizeof(*result));
  if (result == 0) return 0;

  result->n = 0;

#ifdef DEBUG_OSC_PRIORITY_QUEUE
  OSCQueuePrint(result);
#endif
  return result;
}
예제 #3
0
void main (void) {
    OSCQueue q;
    myObj *item;

    q = OSCNewQueue(100, Allocator);
    if (q == 0) {
	printf("OSCNewQueue() returned 0!\n");
	return;
    }

    printf("Made an empty queue:  ");
    OSCQueuePrint(q);

    printf("Inserting three objects.\n");
    objects[0].timetag = 5;
    objects[0].data = "five";
    objects[1].timetag = 2;
    objects[1].data = "two";
    objects[2].timetag = 7;
    objects[2].data = "seven";

    if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[0])) == FALSE) {
	printf("OSCQueueInsert() returned FALSE!\n");
        return;
    }

    if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[1])) == FALSE) {
	printf("OSCQueueInsert() returned FALSE!\n");
        return;
    }

    if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[2])) == FALSE) {
	printf("OSCQueueInsert() returned FALSE!\n");
        return;
    }

    printf("Queue with three objects:   ");
    OSCQueuePrint(q);

    printf("Earliest time tag is %llu.\n", OSCQueueEarliestTimeTag(q));

    printf("Remove front item:\n");
    
    item = (myObj *) OSCQueueRemoveEarliest(q);
    printf("Time tag %llu, data %s\n", item->timetag, item->data);

    printf("Queue with two objects:   ");
    OSCQueuePrint(q);

    printf("Inserting three more objects.\n");
    objects[3].timetag = 11;
    objects[3].data = "eleven";
    objects[4].timetag = 6;
    objects[4].data = "six";
    objects[5].timetag = 3;
    objects[5].data = "three";
    
    if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[3])) == FALSE) {
        printf("OSCQueueInsert() returned FALSE!\n");
        return;
    }

    if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[4])) == FALSE) {
        printf("OSCQueueInsert() returned FALSE!\n");
        return;
    }

    if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[5])) == FALSE) {
        printf("OSCQueueInsert() returned FALSE!\n");
        return;
    }


    printf("Queue with five objects:   ");
    OSCQueuePrint(q);


    ScanTest(q);
    StressTest(q);

    printf("Done!\n");

}