| 16 | } |
| 17 | |
| 18 | bool ChartBridge::InvokeMethod(const std::string &methodName, |
| 19 | const std::string ¶ms, |
| 20 | BridgeCallback callback) { |
| 21 | if (!callback) { |
| 22 | //没有callback 打印一个日志 |
| 23 | chart_->GetLogTracer()->trace("callback is nullptr"); |
| 24 | return false; |
| 25 | } |
| 26 | |
| 27 | if (!railing_) { |
| 28 | CallbackError(methodName, callback, "railing is nullptr"); |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | commonFunction_ = BridgeChannel::Callback([callback, this](const std::string &functionId, |
| 33 | const std::string ¶ms) -> const std::string { |
| 34 | //回调渲染动画 |
| 35 | if (functionId == chart_->GetRequestFrameFuncId()) { |
| 36 | railing_->PlayAnimation(params); |
| 37 | return params; |
| 38 | } |
| 39 | //内部回调方法 |
| 40 | else if (callbackFunctions_.find(functionId) != callbackFunctions_.end()) { |
| 41 | auto &function = callbackFunctions_[functionId]; |
| 42 | return function.Execute(functionId, params); |
| 43 | } |
| 44 | //直接通过bridge回调出去 |
| 45 | else { |
| 46 | nlohmann::json ret = {{"method","render"}, {"renderCallback", {{"functionId", functionId}, {"param", params}}}}; |
| 47 | callback(ret.dump()); |
| 48 | return params; |
| 49 | } |
| 50 | }); |
| 51 | chart_->SetCanvasContext(railing_->GetCanvasContext()); |
| 52 | |
| 53 | if (methodName == "render") { |
| 54 | auto chartConfig = json::ParseString(params); |
| 55 | if (!chartConfig.is_object()) { |
| 56 | chart_->GetLogTracer()->trace("dsl is not object %s " , params.c_str()); |
| 57 | CallbackError(methodName, callback, "dsl is not object"); |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | if (!chartConfig.contains("chartConfig")) { |
| 62 | chart_->GetLogTracer()->trace("dsl is not contains chartConfig %s " , params.c_str()); |
| 63 | CallbackError(methodName, callback, "dsl is not contains chartConfig key"); |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | auto position = json::GetObject(chartConfig, "getPosition"); |
| 68 | if (chartConfig["chartConfig"].is_object()) { |
| 69 | return InvokeRender(json::GetObject(chartConfig, "chartConfig"), |
| 70 | position, |
| 71 | callback); |
| 72 | } else { |
| 73 | const auto &dsl = json::ParseString(json::GetString(chartConfig, "chartConfig")); |
| 74 | return InvokeRender(dsl, position, callback); |
| 75 | } |
no test coverage detected