source: mainline/uspace/lib/drv/generic/remote_clock_dev.c@ 8fd0675f

Last change on this file since 8fd0675f was d7f7a4a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 4 years ago

Replace some license headers with SPDX identifier

Headers are replaced using tools/transorm-copyright.sh only
when it can be matched verbatim with the license header used
throughout most of the codebase.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2012 Maurizio Lombardi
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/** @addtogroup libdrv
8 * @{
9 */
10/** @file
11 */
12
13#include <async.h>
14#include <errno.h>
15#include <time.h>
16#include <macros.h>
17#include <device/clock_dev.h>
18
19#include <ops/clock_dev.h>
20#include <ddf/driver.h>
21
22static void remote_clock_time_get(ddf_fun_t *, void *, ipc_call_t *);
23static void remote_clock_time_set(ddf_fun_t *, void *, ipc_call_t *);
24
25/** Remote clock interface operations */
26static const remote_iface_func_ptr_t remote_clock_dev_iface_ops[] = {
27 [CLOCK_DEV_TIME_GET] = remote_clock_time_get,
28 [CLOCK_DEV_TIME_SET] = remote_clock_time_set,
29};
30
31/** Remote clock interface structure
32 *
33 * Interface for processing requests from remote clients
34 * addressed by the clock interface.
35 */
36const remote_iface_t remote_clock_dev_iface = {
37 .method_count = ARRAY_SIZE(remote_clock_dev_iface_ops),
38 .methods = remote_clock_dev_iface_ops,
39};
40
41/** Process the time_get() request from the remote client
42 *
43 * @param fun The function from which the time is read
44 * @param ops The local ops structure
45 *
46 */
47static void remote_clock_time_get(ddf_fun_t *fun, void *ops, ipc_call_t *call)
48{
49 clock_dev_ops_t *clock_dev_ops = (clock_dev_ops_t *) ops;
50 struct tm t;
51 errno_t rc;
52
53 ipc_call_t data;
54 size_t len;
55 if (!async_data_read_receive(&data, &len)) {
56 /* TODO: Handle protocol error */
57 async_answer_0(call, EINVAL);
58 return;
59 }
60
61 if (!clock_dev_ops->time_get) {
62 /* The driver does not provide the time_get() functionality */
63 async_answer_0(&data, ENOTSUP);
64 async_answer_0(call, ENOTSUP);
65 return;
66 }
67
68 rc = (*clock_dev_ops->time_get)(fun, &t);
69
70 if (rc != EOK) {
71 /* Some error occurred */
72 async_answer_0(&data, rc);
73 async_answer_0(call, rc);
74 return;
75 }
76
77 /* The operation was successful */
78 async_data_read_finalize(&data, &t, sizeof(struct tm));
79 async_answer_0(call, rc);
80}
81
82/** Process the time_set() request from the remote client
83 *
84 * @param fun The function to which the data are written
85 * @param ops The local ops structure
86 *
87 */
88static void remote_clock_time_set(ddf_fun_t *fun, void *ops, ipc_call_t *call)
89{
90 clock_dev_ops_t *clock_dev_ops = (clock_dev_ops_t *) ops;
91 errno_t rc;
92 struct tm t;
93
94 ipc_call_t data;
95 size_t len;
96
97 if (!async_data_write_receive(&data, &len)) {
98 /* TODO: Handle protocol error */
99 async_answer_0(call, EINVAL);
100 return;
101 }
102
103 if (!clock_dev_ops->time_set) {
104 /* The driver does not support the time_set() functionality */
105 async_answer_0(&data, ENOTSUP);
106 async_answer_0(call, ENOTSUP);
107 return;
108 }
109
110 async_data_write_finalize(&data, &t, sizeof(struct tm));
111
112 rc = (*clock_dev_ops->time_set)(fun, &t);
113
114 async_answer_0(call, rc);
115}
116
117/**
118 * @}
119 */
Note: See TracBrowser for help on using the repository browser.