[59e92f62] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Maurizio Lombardi
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libdrv
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <async.h>
|
---|
| 36 | #include <errno.h>
|
---|
| 37 | #include <time.h>
|
---|
| 38 |
|
---|
| 39 | #include <ops/clock_dev.h>
|
---|
| 40 | #include <ddf/driver.h>
|
---|
| 41 |
|
---|
| 42 | static void remote_clock_time_get(ddf_fun_t *, void *, ipc_callid_t,
|
---|
| 43 | ipc_call_t *);
|
---|
| 44 | static void remote_clock_time_set(ddf_fun_t *, void *, ipc_callid_t,
|
---|
| 45 | ipc_call_t *);
|
---|
| 46 |
|
---|
| 47 | /** Remote clock interface operations */
|
---|
| 48 | static remote_iface_func_ptr_t remote_clock_dev_iface_ops[] = {
|
---|
| 49 | &remote_clock_time_get,
|
---|
[aeb49e9] | 50 | &remote_clock_time_set,
|
---|
[59e92f62] | 51 | };
|
---|
| 52 |
|
---|
| 53 | /** Remote clock interface structure
|
---|
| 54 | *
|
---|
| 55 | * Interface for processing requests from remote clients
|
---|
| 56 | * addressed by the clock interface.
|
---|
| 57 | */
|
---|
| 58 | remote_iface_t remote_clock_dev_iface = {
|
---|
| 59 | .method_count = sizeof(remote_clock_dev_iface_ops) /
|
---|
| 60 | sizeof(remote_iface_func_ptr_t),
|
---|
| 61 | .methods = remote_clock_dev_iface_ops,
|
---|
| 62 | };
|
---|
| 63 |
|
---|
| 64 | /** Process the time_get() request from the remote client
|
---|
| 65 | *
|
---|
| 66 | * @param fun The function from which the time is read
|
---|
| 67 | * @param ops The local ops structure
|
---|
| 68 | */
|
---|
| 69 | static void
|
---|
| 70 | remote_clock_time_get(ddf_fun_t *fun, void *ops, ipc_callid_t callid,
|
---|
| 71 | ipc_call_t *call)
|
---|
| 72 | {
|
---|
| 73 | clock_dev_ops_t *clock_dev_ops = (clock_dev_ops_t *) ops;
|
---|
| 74 | ipc_callid_t cid;
|
---|
| 75 | struct tm t;
|
---|
| 76 | int rc;
|
---|
| 77 | size_t len;
|
---|
| 78 |
|
---|
| 79 | if (!async_data_read_receive(&cid, &len)) {
|
---|
| 80 | /* TODO: Handle protocol error */
|
---|
| 81 | async_answer_0(callid, EINVAL);
|
---|
| 82 | return;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | if (!clock_dev_ops->time_get) {
|
---|
| 86 | /* The driver does not provide the time_get() functionality */
|
---|
| 87 | async_data_read_finalize(cid, NULL, 0);
|
---|
| 88 | async_answer_0(callid, ENOTSUP);
|
---|
| 89 | return;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | rc = (*clock_dev_ops->time_get)(fun, &t);
|
---|
| 93 |
|
---|
| 94 | if (rc != EOK) {
|
---|
| 95 | /* Some error occurred */
|
---|
| 96 | async_data_read_finalize(cid, NULL, 0);
|
---|
| 97 | async_answer_0(callid, rc);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | /* The operation was successful */
|
---|
| 101 | async_data_read_finalize(cid, &t, sizeof(struct tm));
|
---|
| 102 | async_answer_1(callid, EOK, rc);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[aeb49e9] | 105 | /** Process the write request from the remote client
|
---|
| 106 | *
|
---|
| 107 | * @param fun The function to which the data are written
|
---|
| 108 | * @param ops The local ops structure
|
---|
| 109 | */
|
---|
| 110 | static void remote_clock_time_set(ddf_fun_t *fun, void *ops,
|
---|
| 111 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 112 | {
|
---|
| 113 | clock_dev_ops_t *clock_dev_ops = (clock_dev_ops_t *) ops;
|
---|
| 114 | int rc;
|
---|
| 115 | struct tm t;
|
---|
| 116 | ipc_callid_t cid;
|
---|
| 117 | size_t len;
|
---|
| 118 |
|
---|
| 119 | if (!async_data_write_receive(&cid, &len)) {
|
---|
| 120 | /* TODO: Handle protocol error */
|
---|
| 121 | async_answer_0(callid, EINVAL);
|
---|
| 122 | return;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | if (!clock_dev_ops->time_set) {
|
---|
| 126 | /* The driver does not support the time_set() functionality */
|
---|
| 127 | async_data_write_finalize(cid, NULL, 0);
|
---|
| 128 | async_answer_0(callid, ENOTSUP);
|
---|
| 129 | return;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | async_data_write_finalize(cid, &t, sizeof(struct tm));
|
---|
| 133 |
|
---|
| 134 | rc = (*clock_dev_ops->time_set)(fun, &t);
|
---|
| 135 | if (rc < 0) {
|
---|
| 136 | /* Some error occurred */
|
---|
| 137 | async_answer_0(callid, rc);
|
---|
| 138 | return;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | async_answer_1(callid, EOK, rc);
|
---|
| 142 | }
|
---|
[59e92f62] | 143 |
|
---|
| 144 | /**
|
---|
| 145 | * @}
|
---|
| 146 | */
|
---|
| 147 |
|
---|