aboutsummaryrefslogtreecommitdiff
path: root/platform/slpi/host_link.cc
diff options
context:
space:
mode:
Diffstat (limited to 'platform/slpi/host_link.cc')
-rw-r--r--platform/slpi/host_link.cc330
1 files changed, 150 insertions, 180 deletions
diff --git a/platform/slpi/host_link.cc b/platform/slpi/host_link.cc
index a8bdfec9..8a316d34 100644
--- a/platform/slpi/host_link.cc
+++ b/platform/slpi/host_link.cc
@@ -28,25 +28,22 @@
#include "chre/platform/log.h"
#include "chre/platform/memory.h"
#include "chre/platform/shared/host_protocol_chre.h"
-#include "chre/platform/shared/nanoapp_load_manager.h"
-#ifdef CHRE_USE_BUFFERED_LOGGING
-#include "chre/platform/shared/log_buffer_manager.h"
-#endif
#include "chre/platform/slpi/fastrpc.h"
+#include "chre/platform/slpi/nanoapp_load_manager.h"
#include "chre/platform/slpi/power_control_util.h"
#include "chre/platform/slpi/system_time.h"
#include "chre/platform/system_time.h"
#include "chre/platform/system_timer.h"
#include "chre/util/fixed_size_blocking_queue.h"
-#include "chre/util/flatbuffers/helpers.h"
#include "chre/util/macros.h"
-#include "chre/util/nested_data_ptr.h"
#include "chre/util/unique_ptr.h"
#include "chre_api/chre/version.h"
#include <inttypes.h>
#include <limits.h>
+using flatbuffers::FlatBufferBuilder;
+
namespace chre {
namespace {
@@ -57,6 +54,14 @@ constexpr size_t kOutboundQueueSize = 32;
//! TODO: Make this a member of HostLinkBase
Nanoseconds gLastTimeSyncRequestNanos(0);
+//! Used to pass the client ID through the user data pointer in deferCallback
+union HostClientIdCallbackData {
+ uint16_t hostClientId;
+ void *ptr;
+};
+static_assert(sizeof(uint16_t) <= sizeof(void *),
+ "Pointer must at least fit a u16 for passing the host client ID");
+
struct LoadNanoappCallbackData {
uint64_t appId;
uint32_t transactionId;
@@ -66,7 +71,7 @@ struct LoadNanoappCallbackData {
};
struct NanoappListData {
- ChreFlatBufferBuilder *builder;
+ FlatBufferBuilder *builder;
DynamicVector<NanoappListEntryOffset> nanoappEntries;
uint16_t hostClientId;
};
@@ -84,7 +89,6 @@ enum class PendingMessageType {
LowPowerMicAccessRequest,
LowPowerMicAccessRelease,
EncodedLogMessage,
- SelfTestResponse,
};
struct PendingMessage {
@@ -99,7 +103,7 @@ struct PendingMessage {
data.msgToHost = msgToHost;
}
- PendingMessage(PendingMessageType msgType, ChreFlatBufferBuilder *builder) {
+ PendingMessage(PendingMessageType msgType, FlatBufferBuilder *builder) {
type = msgType;
data.builder = builder;
}
@@ -108,7 +112,7 @@ struct PendingMessage {
union {
const MessageToHost *msgToHost;
uint16_t hostClientId;
- ChreFlatBufferBuilder *builder;
+ FlatBufferBuilder *builder;
} data;
};
@@ -122,14 +126,12 @@ struct UnloadNanoappCallbackData {
/**
* @see buildAndEnqueueMessage()
*/
-typedef void(MessageBuilderFunction)(ChreFlatBufferBuilder &builder,
- void *cookie);
+typedef void(MessageBuilderFunction)(FlatBufferBuilder &builder, void *cookie);
FixedSizeBlockingQueue<PendingMessage, kOutboundQueueSize> gOutboundQueue;
-int copyToHostBuffer(const ChreFlatBufferBuilder &builder,
- unsigned char *buffer, size_t bufferSize,
- unsigned int *messageLen) {
+int copyToHostBuffer(const FlatBufferBuilder &builder, unsigned char *buffer,
+ size_t bufferSize, unsigned int *messageLen) {
uint8_t *data = builder.GetBufferPointer();
size_t size = builder.GetSize();
int result;
@@ -171,12 +173,11 @@ bool enqueueMessage(PendingMessage message) {
/**
* Helper function that takes care of the boilerplate for allocating a
- * ChreFlatBufferBuilder on the heap and adding it to the outbound message
- * queue.
+ * FlatBufferBuilder on the heap and adding it to the outbound message queue.
*
* @param msgType Identifies the message while in the outboud queue
* @param initialBufferSize Number of bytes to reserve when first allocating the
- * ChreFlatBufferBuilder
+ * FlatBufferBuilder
* @param buildMsgFunc Synchronous callback used to encode the FlatBuffer
* message. Will not be invoked if allocation fails.
* @param cookie Opaque pointer that will be passed through to buildMsgFunc
@@ -188,7 +189,7 @@ bool buildAndEnqueueMessage(PendingMessageType msgType,
MessageBuilderFunction *msgBuilder, void *cookie) {
bool pushed = false;
- auto builder = MakeUnique<ChreFlatBufferBuilder>(initialBufferSize);
+ auto builder = MakeUnique<FlatBufferBuilder>(initialBufferSize);
if (builder.isNull()) {
LOGE("Couldn't allocate memory for message type %d",
static_cast<int>(msgType));
@@ -210,15 +211,14 @@ bool buildAndEnqueueMessage(PendingMessageType msgType,
}
/**
- * FlatBuffer message builder callback used with handleNanoappListRequest()
+ * FlatBuffer message builder callback used with constructNanoappListCallback()
*/
-void buildNanoappListResponse(ChreFlatBufferBuilder &builder, void *cookie) {
+void buildNanoappListResponse(FlatBufferBuilder &builder, void *cookie) {
auto nanoappAdderCallback = [](const Nanoapp *nanoapp, void *data) {
auto *cbData = static_cast<NanoappListData *>(data);
HostProtocolChre::addNanoappListEntry(
*(cbData->builder), cbData->nanoappEntries, nanoapp->getAppId(),
- nanoapp->getAppVersion(), true /*enabled*/, nanoapp->isSystemNanoapp(),
- nanoapp->getAppPermissions());
+ nanoapp->getAppVersion(), true /*enabled*/, nanoapp->isSystemNanoapp());
};
// Add a NanoappListEntry to the FlatBuffer for each nanoapp
@@ -230,9 +230,31 @@ void buildNanoappListResponse(ChreFlatBufferBuilder &builder, void *cookie) {
cbData->hostClientId);
}
-void finishLoadingNanoappCallback(SystemCallbackType /*type*/,
- UniquePtr<LoadNanoappCallbackData> &&data) {
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
+void constructNanoappListCallback(uint16_t /*eventType*/, void *deferCbData) {
+ HostClientIdCallbackData clientIdCbData;
+ clientIdCbData.ptr = deferCbData;
+
+ NanoappListData cbData = {};
+ cbData.hostClientId = clientIdCbData.hostClientId;
+
+ const EventLoop &eventLoop = EventLoopManagerSingleton::get()->getEventLoop();
+ size_t expectedNanoappCount = eventLoop.getNanoappCount();
+ if (!cbData.nanoappEntries.reserve(expectedNanoappCount)) {
+ LOG_OOM();
+ } else {
+ constexpr size_t kFixedOverhead = 48;
+ constexpr size_t kPerNanoappSize = 32;
+ size_t initialBufferSize =
+ (kFixedOverhead + expectedNanoappCount * kPerNanoappSize);
+
+ buildAndEnqueueMessage(PendingMessageType::NanoappListResponse,
+ initialBufferSize, buildNanoappListResponse,
+ &cbData);
+ }
+}
+
+void finishLoadingNanoappCallback(uint16_t /*eventType*/, void *data) {
+ auto msgBuilder = [](FlatBufferBuilder &builder, void *cookie) {
auto *cbData = static_cast<LoadNanoappCallbackData *>(cookie);
EventLoop &eventLoop = EventLoopManagerSingleton::get()->getEventLoop();
@@ -244,14 +266,17 @@ void finishLoadingNanoappCallback(SystemCallbackType /*type*/,
cbData->fragmentId);
};
+ // Re-wrap the callback data struct, so it is destructed and freed, ensuring
+ // we don't leak the embedded UniquePtr<Nanoapp>
+ UniquePtr<LoadNanoappCallbackData> dataWrapped(
+ static_cast<LoadNanoappCallbackData *>(data));
constexpr size_t kInitialBufferSize = 48;
buildAndEnqueueMessage(PendingMessageType::LoadNanoappResponse,
- kInitialBufferSize, msgBuilder, data.get());
+ kInitialBufferSize, msgBuilder, data);
}
-void handleUnloadNanoappCallback(SystemCallbackType /*type*/,
- UniquePtr<UnloadNanoappCallbackData> &&data) {
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
+void handleUnloadNanoappCallback(uint16_t /*eventType*/, void *data) {
+ auto msgBuilder = [](FlatBufferBuilder &builder, void *cookie) {
auto *cbData = static_cast<UnloadNanoappCallbackData *>(cookie);
bool success = false;
@@ -270,7 +295,8 @@ void handleUnloadNanoappCallback(SystemCallbackType /*type*/,
constexpr size_t kInitialBufferSize = 52;
buildAndEnqueueMessage(PendingMessageType::UnloadNanoappResponse,
- kInitialBufferSize, msgBuilder, data.get());
+ kInitialBufferSize, msgBuilder, data);
+ memoryFree(data);
}
int generateMessageToHost(const MessageToHost *msgToHost, unsigned char *buffer,
@@ -278,12 +304,11 @@ int generateMessageToHost(const MessageToHost *msgToHost, unsigned char *buffer,
// TODO: ideally we'd construct our flatbuffer directly in the
// host-supplied buffer
constexpr size_t kFixedSizePortion = 80;
- ChreFlatBufferBuilder builder(msgToHost->message.size() + kFixedSizePortion);
+ FlatBufferBuilder builder(msgToHost->message.size() + kFixedSizePortion);
HostProtocolChre::encodeNanoappMessage(
builder, msgToHost->appId, msgToHost->toHostData.messageType,
msgToHost->toHostData.hostEndpoint, msgToHost->message.data(),
- msgToHost->message.size(), msgToHost->toHostData.appPermissions,
- msgToHost->toHostData.messagePermissions);
+ msgToHost->message.size());
int result = copyToHostBuffer(builder, buffer, bufferSize, messageLen);
@@ -313,7 +338,7 @@ int generateHubInfoResponse(uint16_t hostClientId, unsigned char *buffer,
constexpr float kPeakPower = 15;
// Note that this may execute prior to EventLoopManager::lateInit() completing
- ChreFlatBufferBuilder builder(kInitialBufferSize);
+ FlatBufferBuilder builder(kInitialBufferSize);
HostProtocolChre::encodeHubInfoResponse(
builder, kHubName, kVendor, kToolchain, kLegacyPlatformVersion,
kLegacyToolchainVersion, kPeakMips, kStoppedPower, kSleepPower,
@@ -323,22 +348,12 @@ int generateHubInfoResponse(uint16_t hostClientId, unsigned char *buffer,
return copyToHostBuffer(builder, buffer, bufferSize, messageLen);
}
-int generateMessageFromBuilder(ChreFlatBufferBuilder *builder,
+int generateMessageFromBuilder(FlatBufferBuilder *builder,
unsigned char *buffer, size_t bufferSize,
- unsigned int *messageLen,
- bool isEncodedLogMessage) {
+ unsigned int *messageLen) {
CHRE_ASSERT(builder != nullptr);
int result = copyToHostBuffer(*builder, buffer, bufferSize, messageLen);
-
-#ifdef CHRE_USE_BUFFERED_LOGGING
- if (isEncodedLogMessage && LogBufferManagerSingleton::isInitialized()) {
- LogBufferManagerSingleton::get()->onLogsSentToHost();
- }
-#else
- UNUSED_VAR(isEncodedLogMessage);
-#endif
-
- builder->~ChreFlatBufferBuilder();
+ builder->~FlatBufferBuilder();
memoryFree(builder);
return result;
}
@@ -351,7 +366,7 @@ void sendDebugDumpData(uint16_t hostClientId, const char *debugStr,
size_t debugStrSize;
};
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
+ auto msgBuilder = [](FlatBufferBuilder &builder, void *cookie) {
const auto *data = static_cast<const DebugDumpMessageData *>(cookie);
HostProtocolChre::encodeDebugDumpData(builder, data->hostClientId,
data->debugStr, data->debugStrSize);
@@ -374,7 +389,7 @@ void sendDebugDumpResponse(uint16_t hostClientId, bool success,
uint32_t dataCount;
};
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
+ auto msgBuilder = [](FlatBufferBuilder &builder, void *cookie) {
const auto *data = static_cast<const DebugDumpResponseData *>(cookie);
HostProtocolChre::encodeDebugDumpResponse(builder, data->hostClientId,
data->success, data->dataCount);
@@ -389,26 +404,6 @@ void sendDebugDumpResponse(uint16_t hostClientId, bool success,
msgBuilder, &data);
}
-void sendSelfTestResponse(uint16_t hostClientId, bool success) {
- struct SelfTestResponseData {
- uint16_t hostClientId;
- bool success;
- };
-
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
- const auto *data = static_cast<const SelfTestResponseData *>(cookie);
- HostProtocolChre::encodeSelfTestResponse(builder, data->hostClientId,
- data->success);
- };
-
- constexpr size_t kInitialSize = 52;
- SelfTestResponseData data;
- data.hostClientId = hostClientId;
- data.success = success;
- buildAndEnqueueMessage(PendingMessageType::SelfTestResponse, kInitialSize,
- msgBuilder, &data);
-}
-
void sendFragmentResponse(uint16_t hostClientId, uint32_t transactionId,
uint32_t fragmentId, bool success) {
struct FragmentedLoadInfoResponse {
@@ -418,7 +413,7 @@ void sendFragmentResponse(uint16_t hostClientId, uint32_t transactionId,
bool success;
};
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
+ auto msgBuilder = [](FlatBufferBuilder &builder, void *cookie) {
auto *cbData = static_cast<FragmentedLoadInfoResponse *>(cookie);
HostProtocolChre::encodeLoadNanoappResponse(
builder, cbData->hostClientId, cbData->transactionId, cbData->success,
@@ -440,7 +435,7 @@ void sendFragmentResponse(uint16_t hostClientId, uint32_t transactionId,
* Sends a request to the host for a time sync message.
*/
void sendTimeSyncRequest() {
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
+ auto msgBuilder = [](FlatBufferBuilder &builder, void *cookie) {
HostProtocolChre::encodeTimeSyncRequest(builder);
};
@@ -501,8 +496,7 @@ UniquePtr<Nanoapp> handleLoadNanoappFile(uint16_t hostClientId,
if (nanoapp.isNull()) {
LOG_OOM();
- } else if (!nanoapp->setAppInfo(appId, appVersion, appFilename,
- targetApiVersion) ||
+ } else if (!nanoapp->setAppInfo(appId, appVersion, appFilename) ||
!nanoapp->isLoaded()) {
nanoapp.reset(nullptr);
}
@@ -518,7 +512,6 @@ UniquePtr<Nanoapp> handleLoadNanoappFile(uint16_t hostClientId,
* @param transactionId the ID of the transaction
* @param appId the ID of the app to load
* @param appVersion the version of the app to load
- * @param appFlags The flags provided by the app being loaded
* @param targetApiVersion the API version this nanoapp is targeted for
* @param buffer the nanoapp binary data. May be only part of the nanoapp's
* binary if it's being sent over multiple fragments
@@ -529,23 +522,20 @@ UniquePtr<Nanoapp> handleLoadNanoappFile(uint16_t hostClientId,
* @return A valid pointer to a nanoapp that can be loaded into the system. A
* nullptr if the preparation process fails.
*/
-UniquePtr<Nanoapp> handleLoadNanoappData(uint16_t hostClientId,
- uint32_t transactionId, uint64_t appId,
- uint32_t appVersion, uint32_t appFlags,
- uint32_t targetApiVersion,
- const void *buffer, size_t bufferLen,
- uint32_t fragmentId,
- size_t appBinaryLen) {
+UniquePtr<Nanoapp> handleLoadNanoappData(
+ uint16_t hostClientId, uint32_t transactionId, uint64_t appId,
+ uint32_t appVersion, uint32_t targetApiVersion, const void *buffer,
+ size_t bufferLen, uint32_t fragmentId, size_t appBinaryLen) {
static NanoappLoadManager sLoadManager;
bool success = true;
if (fragmentId == 0 || fragmentId == 1) { // first fragment
size_t totalAppBinaryLen = (fragmentId == 0) ? bufferLen : appBinaryLen;
LOGD("Load nanoapp request for app ID 0x%016" PRIx64 " ver 0x%" PRIx32
- " flags 0x%" PRIx32 " target API 0x%08" PRIx32
- " size %zu (txnId %" PRIu32 " client %" PRIu16 ")",
- appId, appVersion, appFlags, targetApiVersion, totalAppBinaryLen,
- transactionId, hostClientId);
+ " target API 0x%08" PRIx32 " size %zu (txnId %" PRIu32
+ " client %" PRIu16 ")",
+ appId, appVersion, targetApiVersion, totalAppBinaryLen, transactionId,
+ hostClientId);
if (sLoadManager.hasPendingLoadTransaction()) {
FragmentedLoadInfo info = sLoadManager.getTransactionInfo();
@@ -555,8 +545,7 @@ UniquePtr<Nanoapp> handleLoadNanoappData(uint16_t hostClientId,
}
success = sLoadManager.prepareForLoad(hostClientId, transactionId, appId,
- appVersion, appFlags,
- totalAppBinaryLen, targetApiVersion);
+ appVersion, totalAppBinaryLen);
}
success &= sLoadManager.copyNanoappFragment(
hostClientId, transactionId, (fragmentId == 0) ? 1 : fragmentId, buffer,
@@ -571,6 +560,38 @@ UniquePtr<Nanoapp> handleLoadNanoappData(uint16_t hostClientId,
return nanoapp;
}
+bool getSettingFromFbs(fbs::Setting setting, Setting *chreSetting) {
+ bool success = true;
+ switch (setting) {
+ case fbs::Setting::LOCATION:
+ *chreSetting = Setting::LOCATION;
+ break;
+ default:
+ LOGE("Unknown setting %" PRIu8, setting);
+ success = false;
+ }
+
+ return success;
+}
+
+bool getSettingStateFromFbs(fbs::SettingState state,
+ SettingState *chreSettingState) {
+ bool success = true;
+ switch (state) {
+ case fbs::SettingState::DISABLED:
+ *chreSettingState = SettingState::DISABLED;
+ break;
+ case fbs::SettingState::ENABLED:
+ *chreSettingState = SettingState::ENABLED;
+ break;
+ default:
+ LOGE("Unknown state %" PRIu8, state);
+ success = false;
+ }
+
+ return success;
+}
+
/**
* FastRPC method invoked by the host to block on messages
*
@@ -622,10 +643,8 @@ extern "C" int chre_slpi_get_message_to_host(unsigned char *buffer,
case PendingMessageType::LowPowerMicAccessRequest:
case PendingMessageType::LowPowerMicAccessRelease:
case PendingMessageType::EncodedLogMessage:
- case PendingMessageType::SelfTestResponse:
- result = generateMessageFromBuilder(
- pendingMsg.data.builder, buffer, bufferSize, messageLen,
- pendingMsg.type == PendingMessageType::EncodedLogMessage);
+ result = generateMessageFromBuilder(pendingMsg.data.builder, buffer,
+ bufferSize, messageLen);
break;
default:
@@ -717,51 +736,6 @@ bool HostLinkBase::flushOutboundQueue() {
return (waitCount >= 0);
}
-void HostLinkBase::sendLogMessage(const uint8_t *logMessage,
- size_t logMessageSize) {
- struct LogMessageData {
- const uint8_t *logMsg;
- size_t logMsgSize;
- };
-
- LogMessageData logMessageData;
-
- logMessageData.logMsg = logMessage;
- logMessageData.logMsgSize = logMessageSize;
-
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
- const auto *data = static_cast<const LogMessageData *>(cookie);
- HostProtocolChre::encodeLogMessages(builder, data->logMsg,
- data->logMsgSize);
- };
-
- constexpr size_t kInitialSize = 128;
- buildAndEnqueueMessage(PendingMessageType::EncodedLogMessage, kInitialSize,
- msgBuilder, &logMessageData);
-}
-
-void HostLinkBase::sendLogMessageV2(const uint8_t *logMessage,
- size_t logMessageSize,
- uint32_t numLogsDropped) {
- struct LogMessageData {
- const uint8_t *logMsg;
- size_t logMsgSize;
- uint32_t numLogsDropped;
- };
-
- LogMessageData logMessageData{logMessage, logMessageSize, numLogsDropped};
-
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
- const auto *data = static_cast<const LogMessageData *>(cookie);
- HostProtocolChre::encodeLogMessagesV2(
- builder, data->logMsg, data->logMsgSize, data->numLogsDropped);
- };
-
- constexpr size_t kInitialSize = 128;
- buildAndEnqueueMessage(PendingMessageType::EncodedLogMessage, kInitialSize,
- msgBuilder, &logMessageData);
-}
-
void HostLinkBase::shutdown() {
// Push a null message so the blocking call in chre_slpi_get_message_to_host()
// returns and the host can exit cleanly. If the queue is full, try again to
@@ -792,7 +766,7 @@ void HostLinkBase::shutdown() {
}
void sendAudioRequest() {
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
+ auto msgBuilder = [](FlatBufferBuilder &builder, void *cookie) {
HostProtocolChre::encodeLowPowerMicAccessRequest(builder);
};
@@ -802,7 +776,7 @@ void sendAudioRequest() {
}
void sendAudioRelease() {
- auto msgBuilder = [](ChreFlatBufferBuilder &builder, void *cookie) {
+ auto msgBuilder = [](FlatBufferBuilder &builder, void *cookie) {
HostProtocolChre::encodeLowPowerMicAccessRelease(builder);
};
@@ -835,48 +809,28 @@ void HostMessageHandlers::handleHubInfoRequest(uint16_t hostClientId) {
}
void HostMessageHandlers::handleNanoappListRequest(uint16_t hostClientId) {
- auto callback = [](uint16_t /*type*/, void *data, void * /*extraData*/) {
- uint16_t cbHostClientId = NestedDataPtr<uint16_t>(data);
-
- NanoappListData cbData = {};
- cbData.hostClientId = cbHostClientId;
-
- size_t expectedNanoappCount =
- EventLoopManagerSingleton::get()->getEventLoop().getNanoappCount();
- if (!cbData.nanoappEntries.reserve(expectedNanoappCount)) {
- LOG_OOM();
- } else {
- constexpr size_t kFixedOverhead = 48;
- constexpr size_t kPerNanoappSize = 32;
- size_t initialBufferSize =
- (kFixedOverhead + expectedNanoappCount * kPerNanoappSize);
-
- buildAndEnqueueMessage(PendingMessageType::NanoappListResponse,
- initialBufferSize, buildNanoappListResponse,
- &cbData);
- }
- };
-
LOGD("Nanoapp list request from client ID %" PRIu16, hostClientId);
+ HostClientIdCallbackData cbData = {};
+ cbData.hostClientId = hostClientId;
EventLoopManagerSingleton::get()->deferCallback(
- SystemCallbackType::NanoappListResponse,
- NestedDataPtr<uint16_t>(hostClientId), callback);
+ SystemCallbackType::NanoappListResponse, cbData.ptr,
+ constructNanoappListCallback);
}
void HostMessageHandlers::handleLoadNanoappRequest(
uint16_t hostClientId, uint32_t transactionId, uint64_t appId,
- uint32_t appVersion, uint32_t appFlags, uint32_t targetApiVersion,
- const void *buffer, size_t bufferLen, const char *appFileName,
- uint32_t fragmentId, size_t appBinaryLen, bool respondBeforeStart) {
+ uint32_t appVersion, uint32_t targetApiVersion, const void *buffer,
+ size_t bufferLen, const char *appFileName, uint32_t fragmentId,
+ size_t appBinaryLen) {
UniquePtr<Nanoapp> pendingNanoapp;
if (appFileName != nullptr) {
pendingNanoapp =
handleLoadNanoappFile(hostClientId, transactionId, appId, appVersion,
targetApiVersion, appFileName);
} else {
- pendingNanoapp = handleLoadNanoappData(
- hostClientId, transactionId, appId, appVersion, appFlags,
- targetApiVersion, buffer, bufferLen, fragmentId, appBinaryLen);
+ pendingNanoapp = handleLoadNanoappData(hostClientId, transactionId, appId,
+ appVersion, targetApiVersion, buffer,
+ bufferLen, fragmentId, appBinaryLen);
}
if (!pendingNanoapp.isNull()) {
@@ -893,7 +847,7 @@ void HostMessageHandlers::handleLoadNanoappRequest(
// Note that if this fails, we'll generate the error response in
// the normal deferred callback
EventLoopManagerSingleton::get()->deferCallback(
- SystemCallbackType::FinishLoadingNanoapp, std::move(cbData),
+ SystemCallbackType::FinishLoadingNanoapp, cbData.release(),
finishLoadingNanoappCallback);
}
}
@@ -905,7 +859,7 @@ void HostMessageHandlers::handleUnloadNanoappRequest(
LOGD("Unload nanoapp request (txnID %" PRIu32 ") for appId 0x%016" PRIx64
" system %d",
transactionId, appId, allowSystemNanoappUnload);
- auto cbData = MakeUnique<UnloadNanoappCallbackData>();
+ auto *cbData = memoryAlloc<UnloadNanoappCallbackData>();
if (cbData == nullptr) {
LOG_OOM();
} else {
@@ -915,7 +869,7 @@ void HostMessageHandlers::handleUnloadNanoappRequest(
cbData->allowSystemNanoappUnload = allowSystemNanoappUnload;
EventLoopManagerSingleton::get()->deferCallback(
- SystemCallbackType::HandleUnloadNanoapp, std::move(cbData),
+ SystemCallbackType::HandleUnloadNanoapp, cbData,
handleUnloadNanoappCallback);
}
}
@@ -938,20 +892,36 @@ void HostMessageHandlers::handleDebugDumpRequest(uint16_t hostClientId) {
}
}
+void HostLink::sendLogMessage(const char *logMessage, size_t logMessageSize) {
+ struct LogMessageData {
+ const char *logMsg;
+ size_t logMsgSize;
+ };
+
+ LogMessageData logMessageData;
+
+ logMessageData.logMsg = logMessage;
+ logMessageData.logMsgSize = logMessageSize;
+
+ auto msgBuilder = [](FlatBufferBuilder &builder, void *cookie) {
+ const auto *data = static_cast<const LogMessageData *>(cookie);
+ HostProtocolChre::encodeLogMessages(builder, data->logMsg,
+ data->logMsgSize);
+ };
+
+ constexpr size_t kInitialSize = 128;
+ buildAndEnqueueMessage(PendingMessageType::EncodedLogMessage, kInitialSize,
+ msgBuilder, &logMessageData);
+}
+
void HostMessageHandlers::handleSettingChangeMessage(fbs::Setting setting,
fbs::SettingState state) {
Setting chreSetting;
SettingState chreSettingState;
- if (HostProtocolChre::getSettingFromFbs(setting, &chreSetting) &&
- HostProtocolChre::getSettingStateFromFbs(state, &chreSettingState)) {
+ if (getSettingFromFbs(setting, &chreSetting) &&
+ getSettingStateFromFbs(state, &chreSettingState)) {
postSettingChange(chreSetting, chreSettingState);
}
}
-void HostMessageHandlers::handleSelfTestRequest(uint16_t hostClientId) {
- // TODO(b/182201569): Run test
- bool success = true;
- sendSelfTestResponse(hostClientId, success);
-}
-
} // namespace chre