Files
open-im-sdk-flutter-m/windows/src/common/FLTService.cpp
2025-05-06 17:25:49 +08:00

83 lines
3.3 KiB
C++

// Copyright (c) 2022 NetEase, Inc. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.
#include "FLTService.h"
#include "../FLTConvert.h"
#include "ThreadUtil.h"
std::string FLTService::getServiceName() const { return m_serviceName; }
void notifyEvent(const std::string& eventName,
flutter::EncodableMap& arguments) {
arguments.insert(std::make_pair(flutter::EncodableValue("serviceName"),
flutter::EncodableValue("")));
std::string strLog;
strLog.append("en: ")
.append(eventName)
.append(", args: ")
.append(Convert::getInstance()->getStringFormMapForLog(&arguments));
std::list<std::string> logList;
Convert::getInstance()->getLogList(strLog, logList);
for (auto& it : logList) {
YXLOG_API(Info) << it << YXLOGEnd;
}
// Create shared pointers for the data to ensure copy constructibility
auto eventNameCopy = std::make_shared<std::string>(eventName);
auto argsCopy = std::make_shared<flutter::EncodableMap>(arguments);
// Ensure we're on the platform thread
ThreadUtil::RunOnPlatformThread([eventNameCopy, argsCopy]() {
NimCore::getInstance()->invokeMethod(*eventNameCopy, *argsCopy);
YXLOG_API(Info) << "notifyEvent invoke completation." << YXLOGEnd;
});
}
//void FLTService::notifyEvent(const std::string& eventName,
// flutter::EncodableMap& arguments,
// const NimCore::InvokeMehtodCallback& callback) {
// arguments.insert(std::make_pair(flutter::EncodableValue("serviceName"),
// flutter::EncodableValue(m_serviceName)));
// std::string strLog;
// strLog.append("en: ")
// .append(eventName)
// .append(", args: ")
// .append(Convert::getInstance()->getStringFormMapForLog(&arguments));
// std::list<std::string> logList;
// Convert::getInstance()->getLogList(strLog, logList);
// for (auto& it : logList) {
// YXLOG_API(Info) << it << YXLOGEnd;
// }
// NimCore::getInstance()->invokeMethod(eventName, arguments, callback);
// YXLOG_API(Info) << "notifyEvent invoke completation." << YXLOGEnd;
//}
void FLTService::notifyEventEx(const std::string& serviceName,
const std::string& eventName,
flutter::EncodableMap& arguments) {
arguments.insert(std::make_pair(flutter::EncodableValue("serviceName"),
flutter::EncodableValue(serviceName)));
std::string strLog;
strLog.append("en: ")
.append(eventName)
.append(", args: ")
.append(Convert::getInstance()->getStringFormMapForLog(&arguments));
std::list<std::string> logList;
Convert::getInstance()->getLogList(strLog, logList);
for (auto& it : logList) {
YXLOG_API(Info) << it << YXLOGEnd;
}
// Create shared pointers for the data to ensure copy constructibility
auto eventNameCopy = std::make_shared<std::string>(eventName);
auto argsCopy = std::make_shared<flutter::EncodableMap>(arguments);
// Ensure we're on the platform thread
ThreadUtil::RunOnPlatformThread([eventNameCopy, argsCopy]() {
NimCore::getInstance()->invokeMethod(*eventNameCopy, *argsCopy);
YXLOG_API(Info) << "notifyEventEx invoke completation." << YXLOGEnd;
});
}