diff options
author | eschneider <eschneider@88473608-6f18-0410-8b6c-91216bd3049c> | 2008-01-15 22:08:26 +0000 |
---|---|---|
committer | eschneider <eschneider@88473608-6f18-0410-8b6c-91216bd3049c> | 2008-01-15 22:08:26 +0000 |
commit | ddacd58365cb1a72b611801ea10e17bc843d1b08 (patch) | |
tree | 86beeb3bfb8a278f9bd967c5e5f94f122cd1b8a3 | |
parent | d46fe2c8c0029665deb8e30feaceb586749fe8ca (diff) |
updated import_buffer
git-svn-id: svn+ssh://svn-nitpicker.cl.cam.ac.uk/linpicker/trunk@149 88473608-6f18-0410-8b6c-91216bd3049c
-rw-r--r-- | client.c | 4 | ||||
-rw-r--r-- | nitpicker-common.c | 6 | ||||
-rw-r--r-- | nitpicker-skelimpl.c | 57 | ||||
-rw-r--r-- | nitpicker-stubs.c | 4 | ||||
-rw-r--r-- | nitpicker-test-client.c | 81 | ||||
-rw-r--r-- | nitpicker.h | 6 | ||||
-rw-r--r-- | nitpicker.idl | 2 | ||||
-rw-r--r-- | sysfuncs.c | 7 |
8 files changed, 73 insertions, 94 deletions
@@ -95,6 +95,7 @@ int nitpicker_donate_memory( CORBA_Object _obj, const char *ds, int max_views, i { char *addr; + int retval; if (!ds) return -2; @@ -107,9 +108,10 @@ int nitpicker_donate_memory( CORBA_Object _obj, const char *ds, int max_views, i + sizeof(client), 0, L4DM_RW, (void **)&addr), "Cannot attach dataspace");*/ - attach_buffer( ds, + retval = attach_buffer( ds, sizeof(buffer)*max_buffers + sizeof(view)*max_views + sizeof(client), 0, (void**) &addr ); + if (retval) return retval; /* * FIXME: We need to revoke the access right diff --git a/nitpicker-common.c b/nitpicker-common.c index e3a364e..2f8cdb3 100644 --- a/nitpicker-common.c +++ b/nitpicker-common.c @@ -28,8 +28,8 @@ CORBA_long (*_impl_get_screen_info)(PortableServer_Servant _servant, CORBA_long* *(CORBA_long *)_o_retval = _impl_get_screen_info (_o_servant, *(CORBA_long* *)_o_args[0], *(CORBA_long* *)_o_args[1], *(CORBA_long* *)_o_args[2], _o_ev); } void _ORBIT_skel_small_nitpicker_import_buffer(POA_nitpicker *_o_servant, gpointer _o_retval,gpointer *_o_args,CORBA_Context _o_ctx,CORBA_Environment *_o_ev, -CORBA_long (*_impl_import_buffer)(PortableServer_Servant _servant, const shared_buffer_info_t* ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev)) { -*(CORBA_long *)_o_retval = _impl_import_buffer (_o_servant, (const shared_buffer_info_t*)_o_args[0], *(const CORBA_long *)_o_args[1], *(const CORBA_long *)_o_args[2], _o_ev); +CORBA_long (*_impl_import_buffer)(PortableServer_Servant _servant, const CORBA_char * ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev)) { +*(CORBA_long *)_o_retval = _impl_import_buffer (_o_servant, *(const CORBA_char * *)_o_args[0], *(const CORBA_long *)_o_args[1], *(const CORBA_long *)_o_args[2], _o_ev); } void _ORBIT_skel_small_nitpicker_remove_buffer(POA_nitpicker *_o_servant, gpointer _o_retval,gpointer *_o_args,CORBA_Context _o_ctx,CORBA_Environment *_o_ev, void (*_impl_remove_buffer)(PortableServer_Servant _servant, const CORBA_long buf_id, CORBA_Environment *ev)) { @@ -206,7 +206,7 @@ static ORBit_IArg nitpicker_get_screen_info__arginfo [] = { { TC_CORBA_long, ORBit_I_ARG_OUT | ORBit_I_COMMON_FIXED_SIZE, (char *)"mode" } }; static ORBit_IArg nitpicker_import_buffer__arginfo [] = { - { TC_shared_buffer_info_t, ORBit_I_ARG_IN | ORBit_I_COMMON_FIXED_SIZE, (char *)"ds" }, + { TC_CORBA_string, ORBit_I_ARG_IN , (char *)"ds" }, { TC_CORBA_long, ORBit_I_ARG_IN | ORBit_I_COMMON_FIXED_SIZE, (char *)"w" }, { TC_CORBA_long, ORBit_I_ARG_IN | ORBit_I_COMMON_FIXED_SIZE, (char *)"h" } }; diff --git a/nitpicker-skelimpl.c b/nitpicker-skelimpl.c index 9685f3f..1a9ad2d 100644 --- a/nitpicker-skelimpl.c +++ b/nitpicker-skelimpl.c @@ -80,7 +80,7 @@ CORBA_Environment *ev); #define _decl_impl_nitpicker_import_buffer_ 1 static CORBA_long impl_nitpicker_import_buffer(impl_POA_nitpicker *servant, -const shared_buffer_info_t* ds, +const CORBA_char * ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev); @@ -246,6 +246,26 @@ static POA_nitpicker__vepv impl_nitpicker_vepv = { /*** Stub implementations ***/ + /* TODO: Need to properly convert impl_POA_nitpicker to CORBA_Object. + * typedef struct { + * POA_nitpicker servant; + * PortableServer_POA poa; + * } impl_POA_nitpicker; + * + * typedef struct { + * void *_private; + * POA_nitpicker__vepv *vepv; + * } POA_nitpicker; + * + * The whole point is that we want to know who the CALLER is. + * For 1-client, that's irrelevant, so we'll stub it out + * temporarily. The following code does it in a nasty, + * temporary way - but one that's very obvious so we can + * remove it later. + * + * */ +#define CONVERT_SERVANT(x) ((CORBA_Object) x) + #if !defined(_impl_Nitevent__create_) #define _impl_Nitevent__create_ 1 static Nitevent impl_Nitevent__create(PortableServer_POA poa, CORBA_Environment *ev) @@ -370,19 +390,8 @@ const CORBA_long max_views, const CORBA_long max_buffers, CORBA_Environment *ev) { -printf( "DEBUG: Server donation name is %s\n", ds); g_print( "; donation name=%d\n", ds ); -printf( "char[0] = %u\n", ((char *) ds[0]) ); -printf( "char[1] = %u\n", ((char *) ds[1]) ); -printf( "char[2] = %u\n", ((char *) ds[2]) ); -printf( "char[3] = %u\n", ((char *) ds[3]) ); -printf( "char[4] = %u\n", ((char *) ds[4]) ); -printf( "char[5] = %u\n", ((char *) ds[5]) ); -printf( "char[6] = %u\n", ((char *) ds[6]) ); -printf( "char[7] = %u\n", ((char *) ds[7]) ); -printf( "char[8] = %u\n", ((char *) ds[8]) ); -printf( "char[9] = %u\n", ((char *) ds[9]) ); /* ------ insert method code here ------ */ - return nitpicker_donate_memory( servant, ds, max_views, max_buffers, ev ); + return nitpicker_donate_memory( CONVERT_SERVANT(servant), ds, max_views, max_buffers, ev ); /* ------ ---------- end ------------ ------ */ } #endif @@ -411,31 +420,11 @@ return 0; } #endif - /* TODO: Need to properly convert impl_POA_nitpicker to CORBA_Object. - typedef struct { - POA_nitpicker servant; - PortableServer_POA poa; - } impl_POA_nitpicker; - - typedef struct { - void *_private; - POA_nitpicker__vepv *vepv; - } POA_nitpicker; - - The whole point is that we want to know who the CALLER is. - For 1-client, that's irrelevant, so we'll stub it out - temporarily. The following code does it in a nasty, - temporary way - but one that's very obvious so we can - remove it later. - - */ -#define CONVERT_SERVANT(x) ((CORBA_Object) x) - #if !defined(_impl_nitpicker_import_buffer_) #define _impl_nitpicker_import_buffer_ 1 static CORBA_long impl_nitpicker_import_buffer(impl_POA_nitpicker *servant, -const shared_buffer_info_t* ds, +const CORBA_char * ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev) diff --git a/nitpicker-stubs.c b/nitpicker-stubs.c index ecba3e5..185ce83 100644 --- a/nitpicker-stubs.c +++ b/nitpicker-stubs.c @@ -42,10 +42,10 @@ ORBit_c_stub_invoke (_obj, &nitpicker__iinterface.methods, 3, &_ORBIT_retval, _a return _ORBIT_retval; } -CORBA_long nitpicker_import_buffer(nitpicker _obj, const shared_buffer_info_t* ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev){ +CORBA_long nitpicker_import_buffer(nitpicker _obj, const CORBA_char * ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev){ CORBA_long _ORBIT_retval; gpointer _args[3]; -_args[0] = (gpointer)ds; +_args[0] = (gpointer)&ds; _args[1] = (gpointer)&w; _args[2] = (gpointer)&h; ORBit_c_stub_invoke (_obj, &nitpicker__iinterface.methods, 4, &_ORBIT_retval, _args, NULL, ev, nitpicker__classid, G_STRUCT_OFFSET (POA_nitpicker__epv, import_buffer), diff --git a/nitpicker-test-client.c b/nitpicker-test-client.c index db273c6..999f1a3 100644 --- a/nitpicker-test-client.c +++ b/nitpicker-test-client.c @@ -119,11 +119,12 @@ client_run (nitpicker service, const int max_getpid_len = 21; // Enough for a 64-bit pid. const int max_donation_name_len = strlen(donation_ds_name_template) + max_getpid_len; - char *donation_ds; - char *buffer_ds; - int donation_fd; // File descriptor - int buffer_fd; // File descriptor + char *donation_ds, *buffer_ds; + int donation_fd, buffer_fd; // File descriptor int scr_width, scr_height, scr_mode; + int buffer_size; + int buf_id; + short *addr; /* * use nitpicker service @@ -134,8 +135,7 @@ client_run (nitpicker service, g_print( "nitpicker_alive returned %d\n", ret ); if (etk_raised_exception (ev)) return; - snprintf(donation_ds, max_donation_name_len, - donation_ds_name_template, getpid()); + snprintf(donation_ds, max_donation_name_len, donation_ds_name_template, getpid()); donation_fd = shm_open(donation_ds, O_RDWR | O_CREAT, 0600); if (donation_fd < 0) { @@ -148,58 +148,49 @@ client_run (nitpicker service, shm_unlink(donation_ds); exit(1); } - g_print( "donation name=%d, donation fd=%d\n", donation_ds, donation_fd ); - ret = nitpicker_donate_memory( service, donation_ds, 10, 10, ev ); - g_print( "nitpicker_donate_memory returned %d\n", ret ); nitpicker_get_screen_info( service, &scr_width, &scr_height, &scr_mode, ev ); - g_print( "scr_width=%d, scr_height=%d, scr_mode=%d\n", scr_width, scr_height, scr_mode ); + printf( "scr_width=%d, scr_height=%d, scr_mode=%d\n", scr_width, scr_height, scr_mode ); /* TODO: We can't trust scr_mode, set to 32 */ scr_mode = 32; -// snprintf(buffer_ds.name, SHARED_BUFFER_INFO_NAME_LENGTH, "/testnit-%d-buffer", getpid()); -// buffer_fd = shm_open(buffer_ds.name, O_RDWR | O_CREAT, 0600); -// if (buffer_fd < 0) -// { -// perror("creating buffer shared memory object"); -// shm_unlink(donation_ds.name); -// exit(1); -// } -// /* buffer_size = BUF_W*BUF_H*scr_mode/8; */ -// /* Calculate buffer size. -// * Presumes width*height*mode divisible by 8 */ -// buffer_size = scr_width*scr_height*scr_mode/8; -// -// if (ftruncate(buffer_fd, buffer_size)) -// { -// perror("setting buffer shared memory size"); -// shm_unlink(donation_ds.name); -// shm_unlink(buffer_ds.name); -// exit(1); -// } -// addr = mmap(0, buffer_size, PROT_READ | PROT_WRITE, MAP_SHARED, -// buffer_fd, 0); -// + snprintf( buffer_ds, SHARED_BUFFER_INFO_NAME_LENGTH, "/testnit-%d-buffer", getpid() ); + buffer_fd = shm_open( buffer_ds, O_RDWR | O_CREAT, 0600 ); + if (buffer_fd < 0) + { + perror("creating buffer shared memory object"); + shm_unlink(donation_ds); + exit(1); + } + /* buffer_size = BUF_W*BUF_H*scr_mode/8; */ + /* Calculate buffer size. + * Presumes width*height*mode divisible by 8 */ + buffer_size = scr_width*scr_height*scr_mode/8; + + if (ftruncate(buffer_fd, buffer_size)) + { + perror("setting buffer shared memory size"); + shm_unlink(donation_ds); + shm_unlink(buffer_ds); + exit(1); + } + addr = mmap(0, buffer_size, PROT_READ | PROT_WRITE, MAP_SHARED, buffer_fd, 0); + // /* printf("l4dm_mem_ds_allocate returned %p\n", addr); */ // // /* ret = l4dm_share(&ds, nit, L4DM_RW); // * printf("l4dm_share returned %d\n", ret); */ // -// buf_id = nitpicker_import_buffer(service, &buffer_ds, scr_width, scr_height, ev); -// printf("nitpicker_import_buffer returned buf_id=%d\n", buf_id); + buf_id = nitpicker_import_buffer( service, buffer_ds, scr_width, scr_height, ev ); + printf("nitpicker_import_buffer returned buf_id=%d\n", buf_id); // -// /* Since the server has now opened our buffers, we can unlink them. */ -// if (shm_unlink(donation_ds.name)) -// { perror("unlinking shared memory object"); } -// if (shm_unlink(buffer_ds.name)) -// { perror("unlinking shared memory object"); } - - - - - + /* Since the server has now opened our buffers, we can unlink them. */ + if (shm_unlink(donation_ds)) + { perror("unlinking shared memory object"); } + if (shm_unlink(buffer_ds)) + { perror("unlinking shared memory object"); } } diff --git a/nitpicker.h b/nitpicker.h index 556c724..21fc132 100644 --- a/nitpicker.h +++ b/nitpicker.h @@ -122,7 +122,7 @@ CORBA_long (*alive)(PortableServer_Servant _servant, CORBA_Environment *ev); CORBA_long (*kill_graphics)(PortableServer_Servant _servant, CORBA_Environment *ev); CORBA_long (*donate_memory)(PortableServer_Servant _servant, const CORBA_char * ds, const CORBA_long max_views, const CORBA_long max_buffers, CORBA_Environment *ev); CORBA_long (*get_screen_info)(PortableServer_Servant _servant, CORBA_long* w, CORBA_long* h, CORBA_long* mode, CORBA_Environment *ev); -CORBA_long (*import_buffer)(PortableServer_Servant _servant, const shared_buffer_info_t* ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev); +CORBA_long (*import_buffer)(PortableServer_Servant _servant, const CORBA_char * ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev); void (*remove_buffer)(PortableServer_Servant _servant, const CORBA_long buf_id, CORBA_Environment *ev); void (*refresh)(PortableServer_Servant _servant, const CORBA_long buf_id, const CORBA_long x, const CORBA_long y, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev); CORBA_long (*new_view)(PortableServer_Servant _servant, const CORBA_long buf_id, const Nitevent listener, CORBA_Environment *ev); @@ -150,7 +150,7 @@ void _ORBIT_skel_small_nitpicker_alive(POA_nitpicker *_ORBIT_servant, gpointer _ void _ORBIT_skel_small_nitpicker_kill_graphics(POA_nitpicker *_ORBIT_servant, gpointer _ORBIT_retval, gpointer *_ORBIT_args, CORBA_Context ctx,CORBA_Environment *ev, CORBA_long (*_impl_kill_graphics)(PortableServer_Servant _servant, CORBA_Environment *ev)); void _ORBIT_skel_small_nitpicker_donate_memory(POA_nitpicker *_ORBIT_servant, gpointer _ORBIT_retval, gpointer *_ORBIT_args, CORBA_Context ctx,CORBA_Environment *ev, CORBA_long (*_impl_donate_memory)(PortableServer_Servant _servant, const CORBA_char * ds, const CORBA_long max_views, const CORBA_long max_buffers, CORBA_Environment *ev)); void _ORBIT_skel_small_nitpicker_get_screen_info(POA_nitpicker *_ORBIT_servant, gpointer _ORBIT_retval, gpointer *_ORBIT_args, CORBA_Context ctx,CORBA_Environment *ev, CORBA_long (*_impl_get_screen_info)(PortableServer_Servant _servant, CORBA_long* w, CORBA_long* h, CORBA_long* mode, CORBA_Environment *ev)); -void _ORBIT_skel_small_nitpicker_import_buffer(POA_nitpicker *_ORBIT_servant, gpointer _ORBIT_retval, gpointer *_ORBIT_args, CORBA_Context ctx,CORBA_Environment *ev, CORBA_long (*_impl_import_buffer)(PortableServer_Servant _servant, const shared_buffer_info_t* ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev)); +void _ORBIT_skel_small_nitpicker_import_buffer(POA_nitpicker *_ORBIT_servant, gpointer _ORBIT_retval, gpointer *_ORBIT_args, CORBA_Context ctx,CORBA_Environment *ev, CORBA_long (*_impl_import_buffer)(PortableServer_Servant _servant, const CORBA_char * ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev)); void _ORBIT_skel_small_nitpicker_remove_buffer(POA_nitpicker *_ORBIT_servant, gpointer _ORBIT_retval, gpointer *_ORBIT_args, CORBA_Context ctx,CORBA_Environment *ev, void (*_impl_remove_buffer)(PortableServer_Servant _servant, const CORBA_long buf_id, CORBA_Environment *ev)); void _ORBIT_skel_small_nitpicker_refresh(POA_nitpicker *_ORBIT_servant, gpointer _ORBIT_retval, gpointer *_ORBIT_args, CORBA_Context ctx,CORBA_Environment *ev, void (*_impl_refresh)(PortableServer_Servant _servant, const CORBA_long buf_id, const CORBA_long x, const CORBA_long y, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev)); void _ORBIT_skel_small_nitpicker_new_view(POA_nitpicker *_ORBIT_servant, gpointer _ORBIT_retval, gpointer *_ORBIT_args, CORBA_Context ctx,CORBA_Environment *ev, CORBA_long (*_impl_new_view)(PortableServer_Servant _servant, const CORBA_long buf_id, const Nitevent listener, CORBA_Environment *ev)); @@ -166,7 +166,7 @@ CORBA_long nitpicker_alive(nitpicker _obj, CORBA_Environment *ev); CORBA_long nitpicker_kill_graphics(nitpicker _obj, CORBA_Environment *ev); CORBA_long nitpicker_donate_memory(nitpicker _obj, const CORBA_char * ds, const CORBA_long max_views, const CORBA_long max_buffers, CORBA_Environment *ev); CORBA_long nitpicker_get_screen_info(nitpicker _obj, CORBA_long* w, CORBA_long* h, CORBA_long* mode, CORBA_Environment *ev); -CORBA_long nitpicker_import_buffer(nitpicker _obj, const shared_buffer_info_t* ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev); +CORBA_long nitpicker_import_buffer(nitpicker _obj, const CORBA_char * ds, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev); void nitpicker_remove_buffer(nitpicker _obj, const CORBA_long buf_id, CORBA_Environment *ev); void nitpicker_refresh(nitpicker _obj, const CORBA_long buf_id, const CORBA_long x, const CORBA_long y, const CORBA_long w, const CORBA_long h, CORBA_Environment *ev); CORBA_long nitpicker_new_view(nitpicker _obj, const CORBA_long buf_id, const Nitevent listener, CORBA_Environment *ev); diff --git a/nitpicker.idl b/nitpicker.idl index 346836e..2779f73 100644 --- a/nitpicker.idl +++ b/nitpicker.idl @@ -58,7 +58,7 @@ interface nitpicker { /*** INJECT NEW BUFFER ***/ - long import_buffer(in shared_buffer_info_t ds, in long w, in long h); + long import_buffer(in string ds, in long w, in long h); /*** REMOVE BUFFER ***/ @@ -41,7 +41,7 @@ static buffer_mapping_t *mapping_list_head = NULL; * memory. */ int -attach_buffer(shared_buffer_info_t *buf, unsigned size, unsigned offset, void **mapping_addr_out) +attach_buffer( char *buf, unsigned size, unsigned offset, void **mapping_addr_out ) { /* buf points to a structure which identifies a buffer (not currently mapped) * in another process's memory space. We use POSIX shared memory objects @@ -51,10 +51,7 @@ attach_buffer(shared_buffer_info_t *buf, unsigned size, unsigned offset, void ** int errsv; buffer_mapping_t *new_mapping_rec_ptr; - /* set null byte at end of buffer name, to prevent overrun */ - buf->name[SHARED_BUFFER_INFO_NAME_LENGTH - 1] = '\0'; - fd = shm_open(buf->name, O_RDWR, 0); - + fd = shm_open( buf, O_RDWR, 0 ); if (fd < 0) { perror("shm_opening buffer"); |