mirror of
https://github.com/openharmony/tools_previewer.git
synced 2026-08-27 08:41:15 -04:00
9a476a6440
Signed-off-by: libenyao <libenyao@h-partners.com>
74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
|
* 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.
|
|
*/
|
|
|
|
#include "VirtualMessageImpl.h"
|
|
#include "PreviewerEngineLog.h"
|
|
|
|
using namespace std;
|
|
VirtualMessageImpl& VirtualMessageImpl::GetInstance()
|
|
{
|
|
static VirtualMessageImpl instance;
|
|
return instance;
|
|
}
|
|
|
|
void VirtualMessageImpl::RegistBundle(const char* bundleAppName, SuccessCallback success, FailCallback fail)
|
|
{
|
|
mutex.lock();
|
|
string buildeName(bundleAppName);
|
|
callBacks[buildeName] = make_pair(success, fail);
|
|
mutex.unlock();
|
|
}
|
|
|
|
void VirtualMessageImpl::UnregistBundle(const char* bundleAppName)
|
|
{
|
|
mutex.lock();
|
|
callBacks.erase(string(bundleAppName));
|
|
mutex.unlock();
|
|
}
|
|
|
|
std::vector<char> VirtualMessageImpl::StringToCharVector(string str) const
|
|
{
|
|
vector<char> vec(str.begin(), str.end());
|
|
vec.push_back('\0');
|
|
return vec;
|
|
}
|
|
|
|
void VirtualMessageImpl::SendVirtualMessage(MessageInfo info)
|
|
{
|
|
OHOS::FeatureAbilityDataInfo osInfo;
|
|
vector<char> deviceId = StringToCharVector(info.deviceID);
|
|
vector<char> bundleName = StringToCharVector(info.bundleName);
|
|
vector<char> abilityName = StringToCharVector(info.abilityName);
|
|
vector<char> message = StringToCharVector(info.message);
|
|
osInfo.deviceID = &deviceId[0];
|
|
osInfo.bundleName = &bundleName[0];
|
|
osInfo.abilityName = &abilityName[0];
|
|
osInfo.message = &message[0];
|
|
osInfo.messageLength = static_cast<uint32_t>(message.size());
|
|
|
|
mutex.lock();
|
|
if (callBacks.size() > 1) {
|
|
ILOG("VirtualMessage callBacks size > 1.");
|
|
}
|
|
|
|
for (auto iter = callBacks.begin(); iter != callBacks.end(); iter++) {
|
|
if (iter->second.first == nullptr) {
|
|
ILOG("VirtualAbilityKit::VirtualMessage callback is null");
|
|
}
|
|
iter->second.first((reinterpret_cast<void*>(&info)));
|
|
}
|
|
mutex.unlock();
|
|
}
|