--- APP SEND --- string app_send(string appId, string data, uint8 format)
| 1567 | // --- APP SEND --- |
| 1568 | // string app_send(string appId, string data, uint8 format) |
| 1569 | NymphMessage* app_send(int session, NymphMessage* msg, void* data) { |
| 1570 | NymphMessage* returnMsg = msg->getReplyMessage(); |
| 1571 | |
| 1572 | // Validate the application ID, try to find running instance, else launch new app instance. |
| 1573 | std::string appId = msg->parameters()[0]->getString(); |
| 1574 | std::string message = msg->parameters()[1]->getString(); |
| 1575 | |
| 1576 | // Get the desired output format. |
| 1577 | // 0 - CLI - Text with tab (\t) separators and \n terminator. |
| 1578 | // 1 - HTML - HTML format. |
| 1579 | uint8_t format = msg->parameters()[2]->getUint8(); |
| 1580 | |
| 1581 | // Find the application details. |
| 1582 | std::string* result = new std::string(); |
| 1583 | NymphCastApp app = nc_apps.findApp(appId); |
| 1584 | if (app.id.empty()) { |
| 1585 | NYMPH_LOG_FATAL("Failed to find a matching application for '" + appId + "'."); |
| 1586 | returnMsg->setResultValue(new NymphType(result, true)); |
| 1587 | msg->discard(); |
| 1588 | |
| 1589 | return returnMsg; |
| 1590 | } |
| 1591 | |
| 1592 | NYMPH_LOG_INFORMATION("Found " + appId + " app."); |
| 1593 | |
| 1594 | if (!nc_apps.runApp(appId, message, format, *result)) { |
| 1595 | NYMPH_LOG_ERROR("Error running app: " + *result); |
| 1596 | |
| 1597 | // Report back error to client. |
| 1598 | NYMPH_LOG_FATAL("Failed to run application for '" + appId + "'."); |
| 1599 | returnMsg->setResultValue(new NymphType(result, true)); |
| 1600 | msg->discard(); |
| 1601 | |
| 1602 | return returnMsg; |
| 1603 | } |
| 1604 | |
| 1605 | returnMsg->setResultValue(new NymphType(result, true)); |
| 1606 | msg->discard(); |
| 1607 | |
| 1608 | return returnMsg; |
| 1609 | } |
| 1610 | |
| 1611 | |
| 1612 | // --- APP LOAD RESOURCE --- |