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