changeset 583:530d189ebf1a

add writer
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 25 Oct 2009 20:11:38 +0900
parents ea03c178fc30
children a13373114df4
files Renderer/Test/Makefile.macosx Renderer/Test/writer.c
diffstat 2 files changed, 92 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Test/Makefile.macosx	Sat Oct 24 18:15:18 2009 +0900
+++ b/Renderer/Test/Makefile.macosx	Sun Oct 25 20:11:38 2009 +0900
@@ -2,15 +2,15 @@
 
 LIBS += -lFifoManager -lCerium
 
-CFLAGS += `sdl-config --cflags` `xml2-config --cflags`
+CFLAGS += `sdl-config --cflags` `xml2-config --cflags` $(INCLUDE)
 LIBS   += `sdl-config --libs` `xml2-config --libs` -lSDL_image -Wl,-framework,OpenGL
 
 .SUFFIXES: .cc .o  .xml .xml.h .xml.cc
 
 .cc.o:
-	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+	$(CC) $(CFLAGS)  -c $< -o $@
 
-ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum send_linda dynamic
+ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum send_linda dynamic writer
 all: $(ALL)
 
 BALL_BOUND_OBJ = ball_bound.o
@@ -61,6 +61,10 @@
 send_linda : $(SENDLINDA_OBJ) 
 	$(CC) -o $@ $?    $(LIBS)
 
+WRITER_OBJ = writer.o
+writer : $(WRITER_OBJ) 
+	$(CC) -o $@ $?    $(LIBS)
+
 run: $(TARGET)
 	sudo ./$(TARGET) -width 576 -height 384 -bpp 32
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/writer.c	Sun Oct 25 20:11:38 2009 +0900
@@ -0,0 +1,85 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <arpa/inet.h>
+
+#include "lindaapi.h"
+
+#define PORT 10000
+
+void
+del_callback(unsigned char *data, void *arg)
+{
+	free(data);
+}
+void
+psx_del(int t, int id)
+{
+	psx_callback_in(t, id, del_callback, NULL);
+}
+
+
+void
+mainLoop(int tid, int write_id)
+{
+	int size=BUFSIZ;
+	char *buff = (char *)malloc(size);
+	int len;
+	uint32_t line_id=0;
+
+	if ( (buff=(char*)malloc(size))==NULL ) {
+		perror("malloc");
+		exit(EXIT_FAILURE);
+	}
+
+	/* '\0'も含めて送信  */
+	psx_out(tid, write_id, (unsigned char *)"\0\0\0\0aiueo", 10);
+	psx_sync_n();
+
+	while (1) {
+		char *data = buff+4;
+		/* 標準入力から読み込み、改行を削除  */
+		fgets(data, size-4, stdin);
+		len = strlen(data);
+		if (data[len-1]=='\n') {
+			data[--len] = '\0';
+		}
+		((uint32_t*)buff)[0] = htonl(line_id);
+
+		if (len==size) {
+			/* realloc  */
+		}
+
+		/* まえのデータを消す  */
+		psx_del(tid, write_id);
+		/* '\0'も含めて送信  */
+		psx_out(tid, write_id, (unsigned char *)buff, len+4+1);
+
+		psx_sync_n();
+		printf("send data[%d] line_id=%d, `%s'\n", len, line_id, data);
+		printf("line_id =%d\n", ntohl(((uint32_t*)buff)[0]));
+
+		line_id++;
+	}
+
+	return;
+}
+
+
+int
+main(int argc, char *argv[]) {
+	int tspace;
+
+	init_linda();
+	tspace = open_linda_java("localhost", PORT);
+	printf("open socket (tupple space id) = %d\n", tspace);
+
+	mainLoop(tspace, 10);
+
+	printf("mainLoop finished\n");
+	exit(EXIT_SUCCESS);
+}
+
+/* end */