| 351 | } |
| 352 | |
| 353 | bool ProcessorClient::load(const String& settings, const String& layout, uint64 monoChannels, String& err) { |
| 354 | traceScope(); |
| 355 | |
| 356 | if (!isOk()) { |
| 357 | err = "load failed: client not ok"; |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | logln("loading " << m_id << "..."); |
| 362 | |
| 363 | std::lock_guard<std::mutex> lock(m_cmdMtx); |
| 364 | |
| 365 | TimeStatistic::Timeout timeout(15000); |
| 366 | MessageHelper::Error e; |
| 367 | |
| 368 | Message<AddPlugin> msgAddPlugin(this); |
| 369 | PLD(msgAddPlugin) |
| 370 | .setJson({{"id", m_id.toStdString()}, |
| 371 | {"settings", settings.toStdString()}, |
| 372 | {"layout", layout.toStdString()}, |
| 373 | {"monoChannels", monoChannels}}); |
| 374 | |
| 375 | if (msgAddPlugin.send(m_sockCmdOut.get())) { |
| 376 | Message<AddPluginResult> msgResult(this); |
| 377 | if (!msgResult.read(m_sockCmdOut.get(), &e, timeout.getMillisecondsLeft())) { |
| 378 | err = "seems like the plugin did not load or crash: " + e.toString(); |
| 379 | setAndLogError(err); |
| 380 | m_sockCmdOut->close(); |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | auto jresult = msgResult.payload.getJson(); |
| 385 | if (!jresult["success"].get<bool>()) { |
| 386 | err = jresult["err"].get<std::string>(); |
| 387 | setAndLogError("load failed: " + err); |
| 388 | m_sockCmdOut->close(); |
| 389 | return false; |
| 390 | } |
| 391 | |
| 392 | if (timeout.getMillisecondsLeft() == 0) { |
| 393 | err = "load failed: timeout"; |
| 394 | setAndLogError(err); |
| 395 | m_sockCmdOut->close(); |
| 396 | return false; |
| 397 | } |
| 398 | |
| 399 | logln("reading presets..."); |
| 400 | |
| 401 | Message<Presets> msgPresets(this); |
| 402 | if (!msgPresets.read(m_sockCmdOut.get(), &e, timeout.getMillisecondsLeft())) { |
| 403 | err = "failed to read presets: " + e.toString(); |
| 404 | setAndLogError(err); |
| 405 | m_sockCmdOut->close(); |
| 406 | return false; |
| 407 | } |
| 408 | m_presets = StringArray::fromTokens(msgPresets.payload.getString(), "|", ""); |
| 409 | |
| 410 | if (timeout.getMillisecondsLeft() == 0) { |