mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-19 22:54:50 -04:00
Support actor function
add GetResourceData interface to return targetFilePath Signed-off-by: y00576111 <yaojian16@huawei.com> Change-Id: I485357546e790ca8727f8c9db75f421c9d1f0290
This commit is contained in:
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
virtual bool GetAssetContent(const std::string& url, std::string& content) = 0;
|
||||
virtual bool GetAssetContent(const std::string& url, std::vector<uint8_t>& content) = 0;
|
||||
virtual bool GetResourceData(const std::string& fileUri, std::vector<uint8_t>& content) = 0;
|
||||
virtual bool GetResourceData(const std::string& fileUri, std::vector<uint8_t>& content, std::string& ami) = 0;
|
||||
virtual std::string GetAssetPath(const std::string& url) = 0;
|
||||
|
||||
virtual void AddTaskObserver(std::function<void()>&& task) = 0;
|
||||
|
||||
@@ -503,13 +503,14 @@ bool BackendDelegateImpl::ParseFileUri(
|
||||
return fileExist;
|
||||
}
|
||||
|
||||
bool BackendDelegateImpl::GetResourceData(const std::string& fileUri, std::vector<uint8_t>& content)
|
||||
bool BackendDelegateImpl::GetResourceData(const std::string& fileUri, std::vector<uint8_t>& content, std::string& ami)
|
||||
{
|
||||
std::string targetFilePath;
|
||||
if (!ParseFileUri(assetManager_, fileUri, targetFilePath)) {
|
||||
LOGE("GetResourceData parse file uri failed.");
|
||||
return false;
|
||||
}
|
||||
ami = assetManager_->GetAssetPath(targetFilePath) + targetFilePath;
|
||||
if (!Framework::GetAssetContentAllowEmpty(assetManager_, targetFilePath, content)) {
|
||||
LOGE("GetResourceData GetAssetContent failed.");
|
||||
return false;
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
|
||||
bool GetAssetContent(const std::string& url, std::string& content) override;
|
||||
bool GetAssetContent(const std::string& url, std::vector<uint8_t>& content) override;
|
||||
bool GetResourceData(const std::string& fileUri, std::vector<uint8_t>& content) override;
|
||||
bool GetResourceData(const std::string& fileUri, std::vector<uint8_t>& content, std::string& ami) override;
|
||||
std::string GetAssetPath(const std::string& url) override;
|
||||
|
||||
// JsEventHandler delegate functions.
|
||||
|
||||
@@ -661,7 +661,7 @@ void JsiPaEngine::RegisterInitWorkerFunc()
|
||||
void JsiPaEngine::RegisterAssetFunc()
|
||||
{
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content) {
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content, std::string& ami) {
|
||||
LOGI("WorkerCore RegisterAssetFunc called");
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
@@ -672,7 +672,7 @@ void JsiPaEngine::RegisterAssetFunc()
|
||||
if (index == std::string::npos) {
|
||||
LOGE("invalid uri");
|
||||
} else {
|
||||
delegate->GetResourceData(uri.substr(0, index) + ".abc", content);
|
||||
delegate->GetResourceData(uri.substr(0, index) + ".abc", content, ami);
|
||||
}
|
||||
};
|
||||
nativeEngine_->SetGetAssetFunc(assetFunc);
|
||||
|
||||
@@ -490,14 +490,14 @@ void QjsPaEngine::RegisterInitWorkerFunc()
|
||||
void QjsPaEngine::RegisterAssetFunc()
|
||||
{
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content) {
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content, std::string& ami) {
|
||||
LOGI("WorkerCore RegisterAssetFunc called");
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->GetResourceData(uri, content);
|
||||
delegate->GetResourceData(uri, content, ami);
|
||||
};
|
||||
nativeEngine_->SetGetAssetFunc(assetFunc);
|
||||
}
|
||||
|
||||
@@ -952,7 +952,7 @@ void JsiDeclarativeEngine::RegisterInitWorkerFunc()
|
||||
void JsiDeclarativeEngine::RegisterAssetFunc()
|
||||
{
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content) {
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content, std::string &ami) {
|
||||
LOGI("WorkerCore RegisterAssetFunc called");
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
@@ -963,7 +963,7 @@ void JsiDeclarativeEngine::RegisterAssetFunc()
|
||||
if (index == std::string::npos) {
|
||||
LOGE("invalid uri");
|
||||
} else {
|
||||
delegate->GetResourceData(uri.substr(0, index) + ".abc", content);
|
||||
delegate->GetResourceData(uri.substr(0, index) + ".abc", content, ami);
|
||||
}
|
||||
};
|
||||
nativeEngine_->SetGetAssetFunc(assetFunc);
|
||||
|
||||
@@ -140,14 +140,14 @@ void QJSDeclarativeEngine::RegisterInitWorkerFunc()
|
||||
void QJSDeclarativeEngine::RegisterAssetFunc()
|
||||
{
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content) {
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content, std::string& ami) {
|
||||
LOGI("WorkerCore RegisterAssetFunc called");
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->GetResourceData(uri, content);
|
||||
delegate->GetResourceData(uri, content, ami);
|
||||
};
|
||||
nativeEngine_->SetGetAssetFunc(assetFunc);
|
||||
}
|
||||
|
||||
@@ -984,7 +984,7 @@ void V8DeclarativeEngine::RegisterInitWorkerFunc()
|
||||
void V8DeclarativeEngine::RegisterAssetFunc()
|
||||
{
|
||||
auto weakAsset = WeakPtr<AssetManager>(engineInstance_->GetDelegate()->GetAssetManager());
|
||||
auto&& assetFunc = [weakAsset](const std::string& uri, std::vector<uint8_t>& content) {
|
||||
auto&& assetFunc = [weakAsset](const std::string& uri, std::vector<uint8_t>& content, std::string& ami) {
|
||||
LOGI("WorkerCore RegisterAssetFunc called");
|
||||
auto asset = weakAsset.Upgrade();
|
||||
if (!asset) {
|
||||
|
||||
@@ -3115,7 +3115,7 @@ void JsiEngine::RegisterInitWorkerFunc()
|
||||
void JsiEngine::RegisterAssetFunc()
|
||||
{
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content) {
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content, std::string& ami) {
|
||||
LOGI("WorkerCore RegisterAssetFunc called");
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
@@ -3126,7 +3126,7 @@ void JsiEngine::RegisterAssetFunc()
|
||||
if (index == std::string::npos) {
|
||||
LOGE("invalid uri");
|
||||
} else {
|
||||
delegate->GetResourceData(uri.substr(0, index) + ".abc", content);
|
||||
delegate->GetResourceData(uri.substr(0, index) + ".abc", content, ami);
|
||||
}
|
||||
};
|
||||
nativeEngine_->SetGetAssetFunc(assetFunc);
|
||||
|
||||
@@ -3196,14 +3196,14 @@ void QjsEngine::RegisterInitWorkerFunc()
|
||||
void QjsEngine::RegisterAssetFunc()
|
||||
{
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content) {
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content, std::string& ami) {
|
||||
LOGI("WorkerCore RegisterAssetFunc called");
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("delegate is nullptr");
|
||||
return;
|
||||
}
|
||||
delegate->GetResourceData(uri, content);
|
||||
delegate->GetResourceData(uri, content, ami);
|
||||
};
|
||||
nativeEngine_->SetGetAssetFunc(assetFunc);
|
||||
}
|
||||
|
||||
@@ -3732,7 +3732,7 @@ void V8Engine::RegisterInitWorkerFunc()
|
||||
void V8Engine::RegisterAssetFunc()
|
||||
{
|
||||
auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate()));
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content) {
|
||||
auto&& assetFunc = [weakDelegate](const std::string& uri, std::vector<uint8_t>& content, std::string& ami) {
|
||||
LOGI("WorkerCore RegisterAssetFunc called");
|
||||
auto delegate = weakDelegate.Upgrade();
|
||||
if (delegate == nullptr) {
|
||||
|
||||
@@ -80,6 +80,23 @@ bool FrontendDelegate::GetResourceData(const std::string& fileUri, T& content)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool FrontendDelegate::GetResourceData(const std::string& fileUri, T& content, std::string& ami)
|
||||
{
|
||||
std::string targetFilePath;
|
||||
if (!ParseFileUri(assetManager_, fileUri, targetFilePath)) {
|
||||
LOGE("GetResourceData parse file uri failed.");
|
||||
return false;
|
||||
}
|
||||
ami = assetManager_->GetAssetPath(targetFilePath) + targetFilePath;
|
||||
if (!GetAssetContentAllowEmpty(assetManager_, targetFilePath, content)) {
|
||||
LOGE("GetResourceData GetAssetContent failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool FrontendDelegate::GetResourceData(const std::string& fileUri, const RefPtr<AssetManager>& assetManager,
|
||||
T& content)
|
||||
@@ -99,6 +116,8 @@ bool FrontendDelegate::GetResourceData(const std::string& fileUri, const RefPtr<
|
||||
|
||||
template bool FrontendDelegate::GetResourceData(const std::string& fileUri, std::string& content);
|
||||
template bool FrontendDelegate::GetResourceData(const std::string& fileUri, std::vector<uint8_t>& content);
|
||||
template bool FrontendDelegate::GetResourceData(const std::string& fileUri, std::vector<uint8_t>& content,
|
||||
std::string& ami);
|
||||
template bool FrontendDelegate::GetResourceData(const std::string& fileUri, const RefPtr<AssetManager>& assetManager,
|
||||
std::vector<uint8_t>& content);
|
||||
|
||||
|
||||
@@ -178,6 +178,9 @@ public:
|
||||
template<typename T>
|
||||
bool ACE_EXPORT GetResourceData(const std::string& fileUri, T& content);
|
||||
|
||||
template<typename T>
|
||||
bool ACE_EXPORT GetResourceData(const std::string& fileUri, T& content, std::string& ami);
|
||||
|
||||
template<typename T>
|
||||
ACE_EXPORT static bool GetResourceData(const std::string& fileUri, const RefPtr<AssetManager>& assetManager,
|
||||
T& content);
|
||||
|
||||
Reference in New Issue
Block a user