1 /*
2  * Copyright (C) 2020 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  */
16 
17 package android.car.userlib;
18 
19 import android.annotation.IntDef;
20 import android.annotation.Nullable;
21 
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 
25 /**
26  * Callback used on async methods.
27  *
28  * @param <R> response type.
29  */
30 public interface HalCallback<R> {
31 
32     int STATUS_INVALID = -1; // Used for logging purposes only
33     int STATUS_OK = 1;
34     int STATUS_HAL_SET_TIMEOUT = 2;
35     int STATUS_HAL_RESPONSE_TIMEOUT = 3;
36     int STATUS_WRONG_HAL_RESPONSE = 4;
37     int STATUS_CONCURRENT_OPERATION = 5;
38     int STATUS_HAL_NOT_SUPPORTED = 6;
39 
40     /** @hide */
41     @IntDef(prefix = { "STATUS_" }, value = {
42             STATUS_OK,
43             STATUS_HAL_SET_TIMEOUT,
44             STATUS_HAL_RESPONSE_TIMEOUT,
45             STATUS_WRONG_HAL_RESPONSE,
46             STATUS_CONCURRENT_OPERATION,
47             STATUS_HAL_NOT_SUPPORTED
48     })
49     @Retention(RetentionPolicy.SOURCE)
50     @interface HalCallbackStatus{}
51 
52     /**
53      * Called when the HAL generated an event responding to that callback (or when an error
54      * occurred).
55      *
56      * @param status status of the request.
57      * @param response HAL response (or {@code null} in case of error).
58      */
onResponse(@alCallbackStatus int status, @Nullable R response)59     void onResponse(@HalCallbackStatus int status, @Nullable R response);
60 }
61