source: launchers/macosx/obj-cpp/JavaRunner.cpp @ 21b3864

Last change on this file since 21b3864 was 21b3864, checked in by meeh <meeh@…>, 23 months ago

Moved some logic to C++, which will extract i2p if it's not already,
and then secondly fire up the router in a second java process when
extraction is completed. Gonna use "optional" type in C++ to make
global variables a bit less painful to use.

  • Property mode set to 100644
File size: 1.0 KB
Line 
1#include "JavaRunner.h"
2
3#include <dispatch/dispatch.h>
4#include <subprocess.hpp>
5#include <future>
6
7using namespace subprocess;
8using namespace std::experimental;
9
10JavaRunner::JavaRunner(std::string javaBin, const fp_proc_t& execFn, const fp_t& cb)
11  : javaBinaryPath(javaBin), executingFn(execFn), exitCallbackFn(cb)
12{
13  javaProcess = std::shared_ptr<Popen>(new Popen({javaBin.c_str(), "-version"}, defer_spawn{true}));
14}
15
16optional<std::future<int> > JavaRunner::execute()
17{
18  try {
19    auto executingFn = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
20      this->executingFn(this);
21    });
22    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), executingFn);
23    dispatch_block_wait(executingFn, DISPATCH_TIME_FOREVER);
24
25    // Here, the process is done executing.
26
27    printf("Finished executingFn - Runs callbackFn\n");
28    this->exitCallbackFn();
29    return std::async(std::launch::async, []{ return 0; });
30  } catch (std::exception* ex) {
31    printf("ERROR: %s\n", ex->what());
32    return nullopt;
33  }
34}
Note: See TracBrowser for help on using the repository browser.