annotate Renderer/Test/writer.c @ 841:8d702fc5d77a draft

dynamic loading demo bug fix
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Wed, 02 Jun 2010 01:39:15 +0900
parents 278db3ca751d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <string.h>
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <unistd.h>
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <arpa/inet.h>
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
6 #include <sys/stat.h>
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
7 #include <sys/mman.h>
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #include "lindaapi.h"
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #define PORT 10000
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
13 #define SERIAL_REGIST_TUPLE_NO 1
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 void
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
16 mainLoop(int tid, int write_id, int fd)
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 {
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
18 void *addr;
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
19 struct stat sb;
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
21 if (fstat(fd, &sb) == -1) {
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
22 perror("fstat");
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
23 exit(1);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
24 }
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
25 addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
26 if (addr==NULL) {
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
27 perror("mmap");
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
28 exit(1);
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 }
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
31 printf("file size=%lld\n", sb.st_size);
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
33 psx_out(tid, write_id, (unsigned char *)addr, sb.st_size);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
34 psx_sync_n();
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 return;
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 }
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
39 int get_serial_id(int tid) {
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
40 char *data;
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
41 int serial;
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
42 int seq;
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
43
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
44 seq = psx_in(tid, 65535);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
45 do {
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
46 psx_sync_n();
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
47 data = (char *)psx_reply(seq);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
48 } while(data==0);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
49 serial = atoi(data + LINDA_HEADER_SIZE);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
50 psx_free(data);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
51
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
52 return serial;
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
53 }
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
54
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
55 void send_serial_id(int tid, int serial_id) {
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
56 int safe_id = htonl(serial_id);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
57
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
58 psx_out(tid, SERIAL_REGIST_TUPLE_NO, (unsigned char *)&safe_id, sizeof(safe_id));
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
59 psx_sync_n();
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
60 }
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 int
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 main(int argc, char *argv[]) {
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 int tspace;
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
65 int serial;
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
66 int xml_id;
841
8d702fc5d77a dynamic loading demo bug fix
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 619
diff changeset
67 char *linda_serv = (char *)"localhost";
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
68 if (argc > 1)
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
69 linda_serv = argv[1];
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 init_linda();
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
71 tspace = open_linda_java(linda_serv, PORT);
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 printf("open socket (tupple space id) = %d\n", tspace);
584
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
73 serial = get_serial_id(tspace);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
74 xml_id = serial * 10;
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
75 mainLoop(tspace, xml_id, fileno(stdin));
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
76 sleep(1);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
77 send_serial_id(tspace, serial);
6dfd8e6bdef3 fix writer.c
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 583
diff changeset
78 printf("send xml_id = %d, seciral = %d\n",xml_id, serial);
583
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 exit(EXIT_SUCCESS);
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 }
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
537a14d1956b add writer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 /* end */