Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6029a370 authored by Yu Shan's avatar Yu Shan
Browse files

Separate VHAL emulator logic out.

Create EmulatedVehicleServer logic and moves emulator dependency
under it. This is part of the default VHAL refactoring. By letting
EmulatedVehicleServer depends on emulator, if we provides a
different VehicleServer implementation, it would not have emulator
dependency.

Create DefaultVehicleHal and let EmulatedVehicleHal inherits from
DefaultVehicleHal.

Test: Locally run in an emulator, test setting/getting properties
through emulator. Would add more tests in following CL.
Bug: 188204722

Change-Id: I20c4f69144277c717fed880a3bb9824f23ae0490
parent f8f35c99
Loading
Loading
Loading
Loading
+14 −26
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ cc_defaults {

cc_library_headers {
    name: "vhal_v2_0_common_headers",
    visibility: ["//visibility:public"],
    vendor: true,
    export_include_dirs: ["common/include/vhal_v2_0"],
}
@@ -58,6 +59,7 @@ cc_library {
    defaults: ["vhal_v2_0_target_defaults"],
    srcs: [
        "common/src/Obd2SensorStore.cpp",
        "common/src/ProtoMessageConverter.cpp",
        "common/src/SubscriptionManager.cpp",
        "common/src/VehicleHalManager.cpp",
        "common/src/VehicleObjectPool.cpp",
@@ -68,9 +70,13 @@ cc_library {
    ],
    shared_libs: [
        "libbase",
        "libprotobuf-cpp-lite",
    ],
    local_include_dirs: ["common/include/vhal_v2_0"],
    export_include_dirs: ["common/include"],
    static_libs: [
        "android.hardware.automotive.vehicle@2.0-libproto-native",
    ],
}

// Vehicle default VehicleHAL implementation
@@ -80,24 +86,16 @@ cc_library_static {
    defaults: ["vhal_v2_0_target_defaults"],
    cflags: ["-DENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING"],
    srcs: [
        "impl/vhal_v2_0/CommConn.cpp",
        "impl/vhal_v2_0/EmulatedVehicleConnector.cpp",
        "impl/vhal_v2_0/EmulatedVehicleHal.cpp",
        "impl/vhal_v2_0/DefaultVehicleHal.cpp",
        "impl/vhal_v2_0/VehicleHalClient.cpp",
        "impl/vhal_v2_0/VehicleHalServer.cpp",
        "impl/vhal_v2_0/VehicleEmulator.cpp",
        "impl/vhal_v2_0/PipeComm.cpp",
        "impl/vhal_v2_0/ProtoMessageConverter.cpp",
        "impl/vhal_v2_0/SocketComm.cpp",
        "impl/vhal_v2_0/DefaultVehicleHalServer.cpp",
        "impl/vhal_v2_0/LinearFakeValueGenerator.cpp",
        "impl/vhal_v2_0/JsonFakeValueGenerator.cpp",
        "impl/vhal_v2_0/GeneratorHub.cpp",
        "impl/vhal_v2_0/qemu_pipe.cpp",
    ],
    local_include_dirs: ["common/include/vhal_v2_0"],
    export_include_dirs: ["impl"],
    whole_static_libs: [
        "android.hardware.automotive.vehicle@2.0-emulated-user-hal-lib",
        "android.hardware.automotive.vehicle@2.0-manager-lib",
    ],
    shared_libs: [
@@ -110,19 +108,6 @@ cc_library_static {
    ],
}

// Library used  to emulate User HAL behavior through lshal debug requests.
cc_library_static {
    name: "android.hardware.automotive.vehicle@2.0-emulated-user-hal-lib",
    vendor: true,
    defaults: ["vhal_v2_0_target_defaults"],
    srcs: [
        "impl/vhal_v2_0/EmulatedUserHal.cpp",
    ],
    whole_static_libs: [
        "android.hardware.automotive.vehicle@2.0-user-hal-helper-lib",
    ],
}

// Vehicle HAL Server reference impl lib
cc_library_static {
    name: "android.hardware.automotive.vehicle@2.0-server-common-lib",
@@ -133,10 +118,14 @@ cc_library_static {
    export_include_dirs: ["common/include"],
    srcs: [
        "common/src/Obd2SensorStore.cpp",
        "common/src/ProtoMessageConverter.cpp",
        "common/src/VehicleObjectPool.cpp",
        "common/src/VehiclePropertyStore.cpp",
        "common/src/VehicleUtils.cpp",
    ],
    static_libs: [
        "android.hardware.automotive.vehicle@2.0-libproto-native",
    ],
}

// Vehicle HAL Server default implementation
@@ -151,8 +140,7 @@ cc_library_static {
        "impl/vhal_v2_0/GeneratorHub.cpp",
        "impl/vhal_v2_0/JsonFakeValueGenerator.cpp",
        "impl/vhal_v2_0/LinearFakeValueGenerator.cpp",
        "impl/vhal_v2_0/ProtoMessageConverter.cpp",
        "impl/vhal_v2_0/VehicleHalServer.cpp",
        "impl/vhal_v2_0/DefaultVehicleHalServer.cpp",
    ],
    whole_static_libs: [
        "android.hardware.automotive.vehicle@2.0-server-common-lib",
@@ -234,8 +222,8 @@ cc_binary {
    ],
    static_libs: [
        "android.hardware.automotive.vehicle@2.0-manager-lib",
        "android.hardware.automotive.vehicle@2.0-default-impl-lib",
        "android.hardware.automotive.vehicle@2.0-libproto-native",
        "//device/generic/car/emulator/vhal_v2_0:android.hardware.automotive.vehicle@2.0-emulator-impl-lib",
    ],
}

+4 −4
Original line number Diff line number Diff line
@@ -20,9 +20,9 @@

#include <iostream>

#include <vhal_v2_0/EmulatedUserHal.h>
#include <vhal_v2_0/EmulatedVehicleConnector.h>
#include <vhal_v2_0/EmulatedVehicleHal.h>
#include <EmulatedUserHal.h>
#include <EmulatedVehicleConnector.h>
#include <EmulatedVehicleHal.h>
#include <vhal_v2_0/VehicleHalManager.h>

using namespace android;
@@ -34,7 +34,7 @@ int main(int /* argc */, char* /* argv */ []) {
    auto connector = std::make_unique<impl::EmulatedVehicleConnector>();
    auto userHal = connector->getEmulatedUserHal();
    auto hal = std::make_unique<impl::EmulatedVehicleHal>(store.get(), connector.get(), userHal);
    auto emulator = std::make_unique<impl::VehicleEmulator>(hal.get());
    auto emulator = connector->getEmulator();
    auto service = std::make_unique<VehicleHalManager>(hal.get());
    connector->setValuePool(hal->getValuePool());

+0 −117
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef android_hardware_automotive_vehicle_V2_0_impl_CommBase_H_
#define android_hardware_automotive_vehicle_V2_0_impl_CommBase_H_

#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
#include <string>
#include <thread>
#include <vector>

#include "VehicleHalProto.pb.h"

namespace android {
namespace hardware {
namespace automotive {
namespace vehicle {
namespace V2_0 {

namespace impl {

/**
 * MessageProcess is an interface implemented by VehicleEmulator to process messages received
 * over a CommConn.
 */
class MessageProcessor {
   public:
    virtual ~MessageProcessor() = default;

    /**
     * Process a single message received over a CommConn. Populate the given respMsg with the reply
     * message we should send.
     */
    virtual void processMessage(vhal_proto::EmulatorMessage const& rxMsg,
                                vhal_proto::EmulatorMessage& respMsg) = 0;
};

/**
 * This is the interface that both PipeComm and SocketComm use to represent a connection. The
 * connection will listen for commands on a separate 'read' thread.
 */
class CommConn {
   public:
    CommConn(MessageProcessor* messageProcessor) : mMessageProcessor(messageProcessor) {}

    virtual ~CommConn() {}

    /**
     * Start the read thread reading messages from this connection.
     */
    virtual void start();

    /**
     * Closes a connection if it is open.
     */
    virtual void stop();

    /**
     * Returns true if the connection is open and available to send/receive.
     */
    virtual bool isOpen() = 0;

    /**
     * Blocking call to read data from the connection.
     *
     * @return std::vector<uint8_t> Serialized protobuf data received from emulator.  This will be
     *              an empty vector if the connection was closed or some other error occurred.
     */
    virtual std::vector<uint8_t> read() = 0;

    /**
     * Transmits a string of data to the emulator.
     *
     * @param data Serialized protobuf data to transmit.
     *
     * @return int Number of bytes transmitted, or -1 if failed.
     */
    virtual int write(const std::vector<uint8_t>& data) = 0;

    /**
     * Serialized and send the given message to the other side.
     */
    void sendMessage(vhal_proto::EmulatorMessage const& msg);

   protected:
    std::unique_ptr<std::thread> mReadThread;
    MessageProcessor* mMessageProcessor;

    /**
     * A thread that reads messages in a loop, and responds. You can stop this thread by calling
     * stop().
     */
    void readThread();
};

}  // namespace impl

}  // namespace V2_0
}  // namespace vehicle
}  // namespace automotive
}  // namespace hardware
}  // namespace android

#endif  // android_hardware_automotive_vehicle_V2_0_impl_CommBase_H_
Loading