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 #pragma once
18 
19 #include <vhal_v2_0/VehicleObjectPool.h>
20 #include <vhal_v2_0/VehiclePropertyStore.h>
21 #include <vhal_v2_0/VehicleServer.h>
22 
23 #include "GeneratorHub.h"
24 
25 namespace android::hardware::automotive::vehicle::V2_0::impl {
26 
27 // This contains the common server operations that will be used by
28 // both native and virtualized VHAL server. Notice that in the virtualized
29 // scenario, the server may be run on a different OS than Android.
30 class VehicleHalServer : public IVehicleServer {
31   public:
32     VehicleHalServer();
33 
34     void sendAllValuesToClient();
35 
36     // Methods from IVehicleServer
37 
38     std::vector<VehiclePropConfig> onGetAllPropertyConfig() const override;
39 
40     StatusCode onSetProperty(const VehiclePropValue& value, bool updateStatus) override;
41 
42     // Set the Property Value Pool used in this server
43     void setValuePool(VehiclePropValuePool* valuePool);
44 
45   private:
46     using VehiclePropValuePtr = recyclable_ptr<VehiclePropValue>;
47 
48     GeneratorHub* getGenerator();
49 
50     VehiclePropValuePool* getValuePool() const;
51 
52     void onFakeValueGenerated(const VehiclePropValue& value);
53 
54     StatusCode handleGenerateFakeDataRequest(const VehiclePropValue& request);
55 
56     VehiclePropValuePtr createApPowerStateReq(VehicleApPowerStateReq req, int32_t param);
57 
58     VehiclePropValuePtr createHwInputKeyProp(VehicleHwKeyInputAction action, int32_t keyCode,
59                                              int32_t targetDisplay);
60 
61   private:
62     GeneratorHub mGeneratorHub{
63             std::bind(&VehicleHalServer::onFakeValueGenerated, this, std::placeholders::_1)};
64 
65     VehiclePropValuePool* mValuePool{nullptr};
66     VehiclePropertyStore mServerSidePropStore;
67 };
68 
69 }  // namespace android::hardware::automotive::vehicle::V2_0::impl
70