MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / runApp

Method runApp

src/server/nc_apps.cpp:481–711  ·  view source on GitHub ↗

--- RUN APP --- string app_send(string appId, string data)

Source from the content-addressed store, hash-verified

479// --- RUN APP ---
480// string app_send(string appId, string data)
481bool NCApps::runApp(std::string name, std::string message, uint8_t format, std::string &result) {
482 NymphCastApp app = findApp(name);
483 if (app.id.empty()) {
484 std::cerr << "Failed to find a matching application for '" << name << "'." << std::endl;
485 result = "Failed to find a matching application for '" + name + "'.";
486 return false;
487 }
488
489 // Update active app ID.
490 activeAppMutex.lock();
491 activeAppId = name;
492 activeAppMutex.unlock();
493
494 // Compile the app if it hasn't been compiled yet.
495 if (app.asFunction == 0) {
496 // Initialise new instance of the app.
497 int r;
498
499 std::cout << "Loading " << app.id << " app..." << std::endl;
500
501 std::string script;
502 int len;
503 if (app.location == NYMPHCAST_APP_LOCATION_LOCAL) {
504 // We will load the script from a file on the disk.
505 FILE *f = fopen((appsFolder + app.url).c_str(), "rb");
506 if (f == 0) {
507 std::cout << "Failed to open the script file '" << app.url << "'." << std::endl;
508 result = "Failed to open the script file.";
509 return false;
510 }
511
512 // Determine the size of the file
513 fseek(f, 0, SEEK_END);
514 len = ftell(f);
515 fseek(f, 0, SEEK_SET);
516
517 // On Win32 it is possible to do the following instead
518 // int len = _filelength(_fileno(f));
519
520 // Read the entire file
521 script.resize(len);
522 size_t c = fread(&script[0], len, 1, f);
523 fclose(f);
524
525 if (c == 0) {
526 std::cerr << "Failed to load script file." << std::endl;
527 result = "Failed to load script file.";
528 return false;
529 }
530 }
531 else if (app.location == NYMPHCAST_APP_LOCATION_HTTP) {
532 // Load the script file from a remote location (HTTP or HTTPS).
533 // Determine whether to call the HTTP or HTTPS function.
534 std::string response;
535 if (app.url.substr(0, 5) == "https") {
536 std::string query = "";
537 if (!performHttpsQuery(query, response)) {
538 std::cerr << "Error while performing HTTPS query: " << query << std::endl;

Callers 1

app_sendFunction · 0.80

Calls 15

lockMethod · 0.80
unlockMethod · 0.80
c_strMethod · 0.80
lengthMethod · 0.80
AddScriptSectionMethod · 0.80
CreateContextMethod · 0.80
SetLineCallbackMethod · 0.80
GetFunctionByDeclMethod · 0.80
SetArgObjectMethod · 0.80
ExecuteMethod · 0.80
GetExceptionFunctionMethod · 0.80
GetDeclarationMethod · 0.80

Tested by

no test coverage detected