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