Exemple #1
0
static void packOSC_sendbuffer(t_packOSC *x)
{
    int             i;
    int             length;
    unsigned char   *buf;

#ifdef DEBUG
    post("packOSC_sendbuffer: Sending buffer...\n");
#endif
    if (OSC_isBufferEmpty(x->x_oscbuf))
    {
        post("packOSC_sendbuffer() called but buffer empty");
        return;
    }
    if (!OSC_isBufferDone(x->x_oscbuf))
    {
        post("packOSC_sendbuffer() called but buffer not ready!, not exiting");
        return;
    }
    length = OSC_packetSize(x->x_oscbuf);
    buf = (unsigned char *)OSC_getPacket(x->x_oscbuf);
#ifdef DEBUG
    post ("packOSC_sendbuffer: length: %lu", length);
#endif
    /* convert the bytes in the buffer to floats in a list */
    for (i = 0; i < length; ++i) SETFLOAT(&x->x_bufferForOSClist[i], buf[i]);
    /* send the list out the outlet */
    outlet_list(x->x_listout, &s_list, length, x->x_bufferForOSClist);
}
Exemple #2
0
void PrintPacket(OSCbuf *b) {
    char *p = OSC_getPacket(b);
    int size = OSC_packetSize(b);
    unsigned int *intp;
    int i;

    printf("PrintPacket: packet at %p, size %d\n", p, size);
    if (p == 0 || size == 0) return;

    printf("Hex version:");
    for (i = 0, intp = (unsigned int *)p; i < size; i += 4, intp++) {
	if (i % 40 == 0) printf("\n");
	printf("%x ", *intp);
    }

    printf("\n\nString version:");
    for (i = 0; i < size; i++) {
	if (i % 40 == 0) printf("\n");
	if (isprint(p[i])) {
	    printf("%c", p[i]);
	} else {
	    printf("\\%x", p[i] & 0x000000ff);
	}
    }
    printf("\n");
}
Exemple #3
0
void SendBuffer(void *htmsocket, OSCbuf *buf) {
#ifdef DEBUG
    printf("Sending buffer...\n");
#endif
    if (OSC_isBufferEmpty(buf)) return;
    if (!OSC_isBufferDone(buf)) {
	fatal_error("SendBuffer() called but buffer not ready!");
	exit(5);
    }
    SendData(htmsocket, OSC_packetSize(buf), OSC_getPacket(buf));
}
Exemple #4
0
void SendBuffer(void *htmsocket, OSCbuf *buf)
{
#ifdef DEBUG
  printf("Sending buffer...\n");
#endif
  if (OSC_isBufferEmpty(buf))
  {
		post("SendBuffer() called but buffer empty");
		return;
  }
  if (!OSC_isBufferDone(buf))
  {
		fatal_error("SendBuffer() called but buffer not ready!, not exiting");
		return;	//{{raf}}
  }
  SendData(htmsocket, OSC_packetSize(buf), OSC_getPacket(buf));
}
Exemple #5
0
int
Osc_TerminateThread(void)
{
	struct Osc_QueueElement *next;

	if (SDL_LockMutex(Osc_QueueMutex))
		return -1;

	for (struct Osc_QueueElement *el = Osc_QueueHead.next; el; el = next) {
		next = el->next;

		free(OSC_getPacket(&el->buffer));
		free(el);
	}

	Osc_QueueHead.next = NULL;
	Osc_QueueTail = &Osc_QueueHead;

	return SDL_UnlockMutex(Osc_QueueMutex) ||
	       SDL_SemPost(Osc_QueueSemaphore);
}
Exemple #6
0
static int SDLCALL
Osc_DequeueThread(void *ud)
{
	int fd = *(int*)ud;

	static const SDL_Event abort = {
		.type = SDL_USEREVENT,
		.user = {
			.type = SDL_USEREVENT,
			.code = CONTROLLER_ERR_THREAD
		}
	};

	for (;;) {
		struct Osc_QueueElement	*el;
		char			*data;

		fd_set		wrset;
		ssize_t		r;

		struct timeval timeout = {
			.tv_sec = 30,
			.tv_usec = 0
		};

		if (SDL_SemWait(Osc_QueueSemaphore) ||
		    SDL_LockMutex(Osc_QueueMutex))
			THREAD_ABORT();

		if (!(el = Osc_QueueHead.next)) { /* gentle thread termination */
			SDL_DestroyMutex(Osc_QueueMutex);
			SDL_DestroySemaphore(Osc_QueueSemaphore);
			Osc_QueueMutex = NULL;
			Osc_QueueSemaphore = NULL;

			return 0;
		}

		if (SDL_UnlockMutex(Osc_QueueMutex))
			THREAD_ABORT();

		FD_ZERO(&wrset);
		FD_SET(fd, &wrset);

		if (select(fd + 1, NULL, &wrset, NULL, &timeout) <= 0)
			THREAD_ABORT();

		data = OSC_getPacket(&el->buffer);

		do
			r = send(fd, data, OSC_packetSize(&el->buffer), 0);
		while (r < 0 && errno == EINTR);

		if (r <= 0 ||
		    SDL_LockMutex(Osc_QueueMutex))
			THREAD_ABORT();

		if (!(Osc_QueueHead.next = el->next))
			Osc_QueueTail = &Osc_QueueHead;

		if (SDL_UnlockMutex(Osc_QueueMutex))
			THREAD_ABORT();

		free(data);
		free(el);
	}
}

static inline Uint32
Osc_StrPad32(Uint32 l)
{
	Uint32 m = ++l % sizeof(Uint32);
	return m ? l + sizeof(Uint32) - m : l;
}