-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
derived from device/generic/car/emulator/vhal_aidl Test-Done: can communicate with vhal emulator Tracked-On: OAM-126204 Signed-off-by: Qi Zhang <qi1.zhang@intel.com>
- Loading branch information
Showing
20 changed files
with
1,840 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2022 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. | ||
|
||
package { | ||
default_applicable_licenses: ["Android-Apache-2.0"], | ||
} | ||
|
||
cc_library { | ||
name: "VhalCommConn", | ||
vendor: true, | ||
srcs: [ | ||
"*.cpp", | ||
], | ||
shared_libs: [ | ||
"liblog", | ||
"libprotobuf-cpp-lite", | ||
], | ||
export_include_dirs: ["include"], | ||
static_libs: [ | ||
"android.hardware.automotive.vehicle.intel@2.0-libproto-native", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (C) 2018 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. | ||
*/ | ||
|
||
#define LOG_TAG "CommConn" | ||
|
||
#include <thread> | ||
|
||
#include <log/log.h> | ||
|
||
#include "CommConn.h" | ||
|
||
namespace android { | ||
namespace hardware { | ||
namespace automotive { | ||
namespace vehicle { | ||
namespace V2_0 { | ||
|
||
namespace impl { | ||
|
||
void CommConn::start() { | ||
mReadThread = std::make_unique<std::thread>(std::bind(&CommConn::readThread, this)); | ||
} | ||
|
||
void CommConn::stop() { | ||
if (mReadThread->joinable()) { | ||
mReadThread->join(); | ||
} | ||
} | ||
|
||
void CommConn::sendMessage(vhal_proto::VmcuMessage const& msg) { | ||
int numBytes = msg.ByteSize(); | ||
std::vector<uint8_t> buffer(static_cast<size_t>(numBytes)); | ||
if (!msg.SerializeToArray(buffer.data(), numBytes)) { | ||
ALOGE("%s: SerializeToString failed!", __func__); | ||
return; | ||
} | ||
|
||
std::lock_guard<std::mutex> lock(mSendMessageLock); | ||
|
||
write(buffer); | ||
} | ||
|
||
void CommConn::readThread() { | ||
std::vector<uint8_t> buffer; | ||
while (isOpen()) { | ||
buffer = read(); | ||
if (buffer.size() == 0) { | ||
ALOGI("%s: Read returned empty message, exiting read loop.", __func__); | ||
break; | ||
} | ||
|
||
vhal_proto::VmcuMessage rxMsg; | ||
if (rxMsg.ParseFromArray(buffer.data(), static_cast<int32_t>(buffer.size()))) { | ||
vhal_proto::VmcuMessage respMsg; | ||
mMessageProcessor->processMessage(rxMsg, &respMsg); | ||
|
||
sendMessage(respMsg); | ||
} | ||
} | ||
} | ||
|
||
} // namespace impl | ||
|
||
} // namespace V2_0 | ||
} // namespace vehicle | ||
} // namespace automotive | ||
} // namespace hardware | ||
} // namespace android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* 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_EMULATORCOMMCONN_COMMCONN_H | ||
#define ANDROID_EMULATORCOMMCONN_COMMCONN_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 VehicleVmcu 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(const vhal_proto::VmcuMessage& rxMsg, | ||
vhal_proto::VmcuMessage* respMsg) = 0; | ||
}; | ||
|
||
/** | ||
* This is a pure virtual interface that could start/stop and send message. | ||
* This is implemented by CommConn and SocketComm. | ||
*/ | ||
class MessageSender { | ||
public: | ||
virtual ~MessageSender() {} | ||
|
||
/** | ||
* Starts the read thread reading messages from this connection. | ||
*/ | ||
virtual void start() = 0; | ||
|
||
/** | ||
* Closes a connection if it is open. | ||
*/ | ||
virtual void stop() = 0; | ||
|
||
/** | ||
* Serializes and sends the given message to the other side. | ||
*/ | ||
virtual void sendMessage(const vhal_proto::VmcuMessage& msg) = 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 MessageSender { | ||
public: | ||
CommConn(MessageProcessor* messageProcessor) : mMessageProcessor(messageProcessor) {} | ||
|
||
virtual ~CommConn() {} | ||
|
||
/** | ||
* Start the read thread reading messages from this connection. | ||
*/ | ||
void start() override; | ||
|
||
/** | ||
* Closes a connection if it is open. | ||
*/ | ||
void stop() override; | ||
|
||
/** | ||
* Returns true if the connection is open and available to send/receive. | ||
*/ | ||
virtual bool isOpen() = 0; | ||
|
||
/** | ||
* Serialized and send the given message to the other side. | ||
*/ | ||
void sendMessage(const vhal_proto::VmcuMessage& msg) final; | ||
|
||
protected: | ||
MessageProcessor* mMessageProcessor; | ||
|
||
private: | ||
std::unique_ptr<std::thread> mReadThread; | ||
std::mutex mSendMessageLock; | ||
|
||
/** | ||
* A thread that reads messages in a loop, and responds. You can stop this thread by calling | ||
* stop(). | ||
*/ | ||
void readThread(); | ||
|
||
/** | ||
* 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; | ||
}; | ||
|
||
} // namespace impl | ||
|
||
} // namespace V2_0 | ||
} // namespace vehicle | ||
} // namespace automotive | ||
} // namespace hardware | ||
} // namespace android | ||
|
||
#endif // ANDROID_EMULATORCOMMCONN_COMMCONN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (C) 2022 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. | ||
|
||
package { | ||
default_applicable_licenses: ["Android-Apache-2.0"], | ||
} | ||
|
||
cc_library { | ||
name: "VhalPipeComm", | ||
vendor: true, | ||
srcs: [ | ||
"*.cpp", | ||
], | ||
shared_libs: [ | ||
"libbase", | ||
"liblog", | ||
"libprotobuf-cpp-lite", | ||
], | ||
export_include_dirs: ["include"], | ||
static_libs: [ | ||
"android.hardware.automotive.vehicle.intel@2.0-libproto-native", | ||
"VhalCommConn", | ||
], | ||
whole_static_libs: [ | ||
"//device/generic/goldfish:libqemud.ranchu", | ||
], | ||
} |
Oops, something went wrong.