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