1/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package [email protected];
17
18import ICanErrorListener;
19import ICanMessageListener;
20import ICloseHandle;
21
22/**
23 * Represents a CAN bus interface that's up and configured.
24 *
25 * Configuration part is done in ICanController.
26 */
27interface ICanBus {
28    /**
29     * Send CAN message.
30     *
31     * @param message CAN message to send out
32     * @return result OK in the case of success
33     *                PAYLOAD_TOO_LONG if the payload is too long
34     *                INTERFACE_DOWN if the bus is down
35     *                TRANSMISSION_FAILURE in case of transmission failure
36     */
37    send(CanMessage message) generates (Result result);
38
39    /**
40     * Requests HAL implementation to listen for specific CAN messages.
41     *
42     * HAL is responsible for maintaining listener set and sending out messages
43     * to each listener that matches given filter against received message.
44     *
45     * Empty filter list means no filtering. If two or more listeners requested
46     * different filters, HAL server must merge these to fulfill the superset of
47     * these filters. HAL must not send out a message to a listener which filter
48     * doesn't match given message id.
49     *
50     * If filtering is not supported at the hardware level (what's strongly
51     * recommended), it must be covered in the HAL.
52     *
53     * @param filter The set of requested filters
54     * @param listener The interface to receive the messages on
55     * @return result OK in the case of success
56     *                INTERFACE_DOWN if the bus is down
57     * @return close A handle to call in order to remove the listener
58     */
59    listen(vec<CanMessageFilter> filter, ICanMessageListener listener)
60            generates (Result result, ICloseHandle close);
61
62    /**
63     * Adds a new listener for CAN bus or interface errors.
64     *
65     * If the error is fatal, the client is supposed to drop any references to
66     * this specific ICanBus instance (see ICanErrorListener).
67     *
68     * @param listener The interface to receive the error events on
69     * @return close A handle to call in order to remove the listener
70     */
71    listenForErrors(ICanErrorListener listener) generates (ICloseHandle close);
72};
73