| 57 | namespace err = rpc::handlers::errors; |
| 58 | |
| 59 | swoc::Rv<YAML::Node> |
| 60 | plugin_send_basic_msg(std::string_view const & /* id ATS_UNUSED */, YAML::Node const ¶ms) |
| 61 | { |
| 62 | // The rpc could be ready before plugins are initialized. |
| 63 | // We make sure it is ready. |
| 64 | if (!g_lifecycle_hooks) { |
| 65 | return err::make_errata(err::Codes::PLUGIN, "Plugin is not yet ready to handle any messages."); |
| 66 | } |
| 67 | |
| 68 | swoc::Rv<YAML::Node> resp; |
| 69 | try { |
| 70 | // keep the data. |
| 71 | PluginMsgInfo info = params.as<PluginMsgInfo>(); |
| 72 | |
| 73 | TSPluginMsg msg; |
| 74 | msg.tag = info.tag.c_str(); |
| 75 | msg.data = info.data.data(); |
| 76 | msg.data_size = info.data.size(); |
| 77 | |
| 78 | APIHook *hook = g_lifecycle_hooks->get(TS_LIFECYCLE_MSG_HOOK); |
| 79 | |
| 80 | while (hook) { |
| 81 | TSPluginMsg tmp(msg); // Just to make sure plugins don't mess this up for others. |
| 82 | hook->invoke(TS_EVENT_LIFECYCLE_MSG, &tmp); |
| 83 | hook = hook->next(); |
| 84 | } |
| 85 | } catch (std::exception const &ex) { |
| 86 | Dbg(dbg_ctl, "Invalid params %s", ex.what()); |
| 87 | resp = err::make_errata(err::Codes::PLUGIN, "Error parsing the incoming data: {}", ex.what()); |
| 88 | } |
| 89 | |
| 90 | return resp; |
| 91 | } |
| 92 | } // namespace rpc::handlers::plugins |