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