1 #include "pipe_opener_resource.h" 2 #include "pipe_opener_server.h" 3 #include "pipe_pager.h" 4 #include "resource_server.h" 5 6 7 8 /* Support for providing access to pipes. */ 9 10 PipeOpenerResource::PipeOpenerResource(PagesConserving *pages) 11 : _pages(pages) 12 { 13 } 14 15 int PipeOpenerResource::expected_items() 16 { 17 return PipeOpener_expected_items; 18 } 19 20 ipc_server_handler_type PipeOpenerResource::handler() 21 { 22 return (ipc_server_handler_type) handle_PipeOpener; 23 } 24 25 26 27 /* Pipe opener interface methods. */ 28 29 long PipeOpenerResource::pipe(l4_cap_idx_t *reader, l4_cap_idx_t *writer) 30 { 31 /* Both endpoints will employ a common paging coordinator. */ 32 33 PipePaging *paging = new PipePaging(); 34 35 /* Each endpoint will have its own pager. */ 36 37 /* NOTE: Failure to open an endpoint should invalidate both, plus the 38 paging object. Also, any active server thread would need to be 39 cancelled. */ 40 41 return open_endpoint(paging, false, reader) || open_endpoint(paging, true, writer); 42 } 43 44 long PipeOpenerResource::open_endpoint(PipePaging *paging, bool writer, l4_cap_idx_t *endpoint) 45 { 46 PipePager *pager = new PipePager(_pages, paging, writer); 47 48 /* Start the endpoint server in a new thread. 49 If the thread does not start, the resource should be finalised. */ 50 51 ResourceServer server(pager); 52 long err = server.start_thread(); 53 54 /* Return the server capability to the caller. */ 55 56 if (!err) 57 *endpoint = server.config()->server; 58 59 return err; 60 } 61 62 // vim: tabstop=4 expandtab shiftwidth=4