Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

55
LINES

< > BotCompany Repo | #1027258 // Run Vector SDK

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (6765L/34K).

!7

cmodule RunVectorSDK > DynPrintLogAndEnabled {
  transient Process process;
  transient PrintStream out;
  S toSay;
  
  start-thread {
    dm_reloadOnFieldChange enabled();
    if (!enabled) ret;
    //File script = userDir("vector-sdk/cam-stream-to-stdout.py");
    File script = userDir("vector-sdk/control-from-java.py");
    assertFileExists(script);
    makeExecutable(script);

    print("Calling " + script);
    process = Runtime.getRuntime().exec(platformQuoteOpt(script));
    print("SDK process started");
    print("PID: " + getOpt(process, "pid"));
  
    drainErrorStreamToConsole(process, line -> enabled, lambda0 enter);
    out = new PrintStream(process.getOutputStream());
    
    DataInputStream in = new(process.getInputStream());
    S line;
    while ((line = in.readLine()) != null) {
      if (enabled)
        print("Got line: " + takeFirst(100, line));
    }
  }

  void cleanMeUp_process {
    if (process != null) {
      print("Stopping SDK process");
      process.destroy/*Forcibly*/();
      print("Stopped SDK process, hopefully");
    }
  }
  
  visual centerAndSouthWithMargin(super, withMargin(
    dm_textFieldAndSubmit_q toSay(r { say(toSay) }, buttonText := "Say")));

  // API

  // returns true if (probably) successful
  bool say(S s) {
    if (out == null) false;
    s = newLinesToSpaces_trim(s);
    if (empty(s)) true;
    print("Making Vector say: " + s);
    out.println(s);
    out.flush();
    true;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027258
Snippet name: Run Vector SDK
Eternal ID of this version: #1027258/22
Text MD5: b04a5db1cb074e9d968e9e84b7926911
Transpilation MD5: 47f4cb2af5185a25a692278aeae8b92a
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-28 12:39:38
Source code size: 1515 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 146 / 467
Version history: 21 change(s)
Referenced in: [show references]