Mercurial > hg > Members > kono > Cerium
changeset 554:356bebf02461
add send_linda.cc
author | aaa |
---|---|
date | Thu, 22 Oct 2009 23:11:31 +0900 |
parents | ac9fb0d5a997 |
children | efbb6b527fa1 34c3be70b3f8 |
files | TaskManager/Test/test_render/Application/dynamic_create.cc TaskManager/Test/test_render/Application/send_linda.cc |
diffstat | 2 files changed, 113 insertions(+), 125 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Application/dynamic_create.cc Thu Oct 22 21:26:19 2009 +0900 +++ b/TaskManager/Test/test_render/Application/dynamic_create.cc Thu Oct 22 23:11:31 2009 +0900 @@ -15,67 +15,67 @@ #define SERIAL_REGIST_TUPLE_NO 1 /* -typedef struct { - caddr_t file_mmap; - off_t size; -} st_mmap_t; + typedef struct { + caddr_t file_mmap; + off_t size; + } st_mmap_t; */ typedef struct client_ { - int id; - SceneGraphPtr sgp; - struct client_ *next; + int id; + SceneGraphPtr sgp; + struct client_ *next; } client_t; typedef struct { int tid; - int sid; + int sid; int read_id; SceneGraphPtr node; - TaskManager *manager; - client_t *clist; + TaskManager *manager; + client_t *clist; } callback_arg; void client_list_init(TaskManager* manager, client_t *clist) { - clist->id = -1; - clist->next = clist; + clist->id = -1; + clist->next = clist; } void client_list_update(TaskManager *manager, client_t *clist, int id, SceneGraphPtr sgp) { - //client_t *c; - // for (c = clist->next; c != clist; c = c->next) { - // if (c->id == id) { - // c->sgp = sgp; - // return; - // } - // } + //client_t *c; + // for (c = clist->next; c != clist; c = c->next) { + // if (c->id == id) { + // c->sgp = sgp; + // return; + // } + // } - // c->next = (client_t *)manager->allocate(sizeof(client_t)); - // c->next->id = id; - // c->next->sgp = sgp; - // c->next->next = clist; + // c->next = (client_t *)manager->allocate(sizeof(client_t)); + // c->next->id = id; + // c->next->sgp = sgp; + // c->next->next = clist; } void client_list_delete(TaskManager *manager, client_t *clist, int id) { - client_t *c, *prev; - for (c = clist->next, prev = clist; c->next != clist; c = c->next) { - if (c->id == id) { - prev->next = c->next; - return; - } - prev = clist; + client_t *c, *prev; + for (c = clist->next, prev = clist; c->next != clist; c = c->next) { + if (c->id == id) { + prev->next = c->next; + return; } - if (c->id == id) { - prev->next = c->next; - return; - } + prev = clist; + } + if (c->id == id) { + prev->next = c->next; + return; + } } int @@ -120,7 +120,7 @@ static void earth_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) + SceneGraphPtr tree) { } @@ -141,110 +141,76 @@ static void earth_move(SceneGraphPtr node, int screen_w, int screen_h) { - // node->angle[1] += 1.0f; - // if (node->angle[1] > 360.0f) { - // node->angle[1] = 0.0f; - // } - - // node->xyz[0] += node->stack_xyz[0]; - // if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) { - // node->stack_xyz[0] = -node->stack_xyz[0]; - // } - - // node->xyz[1] += node->stack_xyz[1]; - // if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) { - // node->stack_xyz[1] = -node->stack_xyz[1]; - // } - - //Pad *pad = sgroot->getController(); - - /* - if (pad->circle.isPush()) { - SceneGraphPtr earth; - sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml"); - if (pad->right.isPush()) { - SceneGraphPtr earth; - - st_mmap_t m = my_mmap("xml_file/universe.xml"); - - //sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml"); - sgroot->createFromXMLmemory(sgroot->tmanager, m); - earth = sgroot->createSceneGraph("Earth"); - earth->set_move_collision(moon_move, moon_collision); - node->addChild(earth); - } - */ - psx_sync_n(); } SceneGraphPtr create_sg(TaskManager *manager, SceneGraphPtr node, unsigned char *data, int len, int serial_id) { - SceneGraphPtr earth; + SceneGraphPtr object; //sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml"); const char *objname = sgroot->createFromXMLmemory(sgroot->tmanager, (char *)data, len); - earth = sgroot->createSceneGraph(objname); - earth->id = serial_id; - earth->set_move_collision(moon_move, moon_collision); - node->addChild(earth); + object = sgroot->createSceneGraph(objname); + object->id = serial_id; + object->set_move_collision(moon_move, moon_collision); + node->addChild(object); - return earth; + return object; } void del_callback(unsigned char *data, void *arg) { - free(data); + free(data); } void psx_del(int t, int id) { - psx_callback_in(t, id, del_callback, NULL); + psx_callback_in(t, id, del_callback, NULL); } static void callback_get_xml(unsigned char *xml_tuple, void *arg) { int xml_len = psx_get_datalength(xml_tuple); callback_arg *carg = (callback_arg *)arg; - unsigned char *xml_data = xml_tuple+LINDA_HEADER_SIZE; + unsigned char *xml_data = xml_tuple+LINDA_HEADER_SIZE; SceneGraphPtr sgp; // ここで create sgp = create_sg(carg->manager, carg->node, xml_data, xml_len, carg->sid); - client_list_update(carg->manager, carg->clist, carg->sid, sgp); - free(arg); + client_list_update(carg->manager, carg->clist, carg->sid, sgp); + free(arg); free(xml_tuple); } static void callbacker(unsigned char *tuple, void *arg) { - int serial_id, xml_id; + int serial_id, xml_id; unsigned char *data; callback_arg *carg = (callback_arg *)arg; // 最初の4byteデータは使わない data = tuple+LINDA_HEADER_SIZE; - // clientのSerialIDを取得 - serial_id = ntohl(*(int *)data); - - // タプルを解放 - psx_del(carg->tid, SERIAL_REGIST_TUPLE_NO); - - // xml fileを取得する もうすでにxml fileが送信済みである事を期待 - // つまり、送信者がserial_idを送る前にxml fileを送信していなくてはならない - xml_id = serial_id * 10; - callback_arg *copy_arg = (callback_arg *)carg->manager->allocate(sizeof(callback_arg)); - *copy_arg = *carg; - copy_arg->sid = serial_id; - psx_callback_in(carg->tid, xml_id, callback_get_xml, (void *)copy_arg); - + // clientのSerialIDを取得 + serial_id = ntohl(*(int *)data); + + // タプルを解放 + psx_del(carg->tid, SERIAL_REGIST_TUPLE_NO); + + // xml fileを取得する もうすでにxml fileが送信済みである事を期待 + // つまり、送信者がserial_idを送る前にxml fileを送信していなくてはならない + xml_id = serial_id * 10; + callback_arg *copy_arg = (callback_arg *)carg->manager->allocate(sizeof(callback_arg)); + *copy_arg = *carg; + copy_arg->sid = serial_id; + psx_callback_in(carg->tid, xml_id, callback_get_xml, (void *)copy_arg); + /* dataは'\0'で終わっている事を期待 (writerで保証する) */ //printf("get data[%d]: `%s'\n", len, data); - free(tuple); - + free(tuple); + psx_callback_wait_rd(carg->tid, carg->read_id, callbacker, arg); } @@ -255,8 +221,7 @@ callback_arg *carg = (callback_arg *)manager->allocate(sizeof(callback_arg)); carg->tid = open_linda_java("localhost", PORT); - carg->read_id = SERIAL_REGIST_TUPLE_NO; - + carg->read_id = SERIAL_REGIST_TUPLE_NO; carg->node = node; carg->manager = manager; carg->clist = clist; @@ -266,24 +231,17 @@ void dynamic_init(TaskManager *manager) { - //SceneGraphPtr earth; + //SceneGraphPtr earth; sgroot->tmanager = manager; - client_t *clist; - clist = (client_t *)manager->allocate(sizeof(client_t)); + client_t *clist; + clist = (client_t *)manager->allocate(sizeof(client_t)); + + client_list_init(manager, clist); - client_list_init(manager, clist); -#if 0 - // テスト用に mmap したデータを第2引数に渡す予定でした - sgroot->createFromXMLmemory(manager, "xml_file/universe.xml"); - - // sglist に登録されている name から sgid を引き、sg_src[sgid] からコピーして返す - earth = sgroot->createSceneGraph("Earth"); -#else SceneGraphPtr parent; parent = sgroot->createSceneGraph(); parent->set_move_collision(earth_move, earth_collision); - parent->xyz[0] += 300; -#endif + parent->xyz[0] += 300; linda_init(manager, clist, parent);
--- a/TaskManager/Test/test_render/Application/send_linda.cc Thu Oct 22 21:26:19 2009 +0900 +++ b/TaskManager/Test/test_render/Application/send_linda.cc Thu Oct 22 23:11:31 2009 +0900 @@ -105,38 +105,68 @@ void -send_xml(int fd, int id, void *addr, int size) { - psx_out(fd, id, (unsigned char *)addr, size); +send_xml(int tspace, int xml_id, void *addr, int size) { + psx_out(tspace, xml_id, (unsigned char *)addr, size); psx_sync_n(); } +/* +void +mainLoop(int tid, int write_id, int fd) +{ + void *addr; + struct stat sb; + + if (fstat(fd, &sb) == -1) { + perror("fstat"); + exit(1); + } + addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (addr==NULL) { + perror("mmap"); + exit(1); + } + + printf("file size=%d\n", sb.st_size); + + psx_out(tid, write_id, addr, sb.st_size); + psx_sync_n(); + + return; +} +*/ + void send_linda_init(TaskManager *manager, const char *xml) { void *addr; int size; - int fd; - int tuple_id; + int tspace; + int serial; + int xml_id; SceneGraphPtr sgp; SceneGraphPtr root; root = sgroot->createSceneGraph(); root->set_move_collision(root_move, root_collision); - // createFromXMLfile で object name のリストを生成するべき + // createFromXMLfile で object name のリストを生成して返したい sgroot->createFromXMLfile(manager, xml); // 今だけは決め打ち、本当はリストを回して object 数 create したい sgp = sgroot->createSceneGraph("Ball"); - sgp->set_move_collision(move, collision); + sgp->set_move_collision(move, collision); root->addChild(sgp); - sgroot->setSceneData(root); - + + init_linda(); addr = file_map(xml, &size); - fd = open_linda_java(HOSTNAME, PORT_NUM); - tuple_id = get_serial_id(fd); - send_xml(fd, tuple_id*MULTI_NUM, addr, size); + tspace = open_linda_java(HOSTNAME, PORT_NUM); + serial = get_serial_id(tspace); + xml_id = serial * 10; + send_xml(tspace, xml_id, addr, size); + + int client_id = htonl(serial); + send_xml(tspace, LISTEN_PORT, (void *)client_id, sizeof(int)); - int client_id = htonl(tuple_id); - send_xml(fd, LISTEN_PORT, (void *)client_id, sizeof(int)); + sgroot->setSceneData(root); }