source: launchers/macosx/obj-cpp/RouterTask.h @ f9fbc76

Last change on this file since f9fbc76 was f9fbc76, checked in by meeh <meeh@…>, 2 years ago

Code changes:

  • Port check to see if i2p is already running.
  • All buttons in the menu should work now.
  • Rewrote some C++ to Objective-C, which fits better with the integration.
  • Misc cleanup.
  • Made the launch of router repeatable.
  • Property mode set to 100644
File size: 1.8 KB
Line 
1#pragma once
2
3#include <dispatch/dispatch.h>
4#include <functional>
5#include <memory>
6#include <string>
7#include <vector>
8
9#include <Cocoa/Cocoa.h>
10#import <AppKit/AppKit.h>
11
12#include "optional.hpp"
13#include "subprocess.hpp"
14
15
16@class RTaskOptions;
17@interface RTaskOptions : NSObject
18@property (strong) NSString* binPath;
19@property (strong) NSArray<NSString *>* arguments;
20@property (strong) NSString* i2pBaseDir;
21@end
22
23@class I2PRouterTask;
24@interface I2PRouterTask : NSObject
25@property (strong) NSTask* routerTask;
26@property (strong) NSUserDefaults *userPreferences;
27@property (strong) NSFileHandle *readLogHandle;
28@property (strong) NSMutableData *totalLogData;
29@property (strong) NSPipe *processPipe;
30@property (strong) NSFileHandle *input;
31@property (atomic) BOOL isRouterRunning;
32@property (atomic) BOOL userRequestedRestart;
33- (instancetype) initWithOptions : (RTaskOptions*) options;
34- (int) execute;
35- (void) requestShutdown;
36- (void) requestRestart;
37- (BOOL) isRunning;
38- (int) getPID;
39- (void)routerStdoutData:(NSNotification *)notification;
40@end
41
42
43
44using namespace subprocess;
45
46class JavaRunner;
47
48typedef std::function<void(void)> fp_t;
49typedef std::function<void(JavaRunner *ptr)> fp_proc_t;
50
51
52
53/**
54 *
55 * class JavaRunner
56 *
57 **/
58class JavaRunner
59{
60public:
61  // copy fn
62  JavaRunner(std::string& javaBin, std::string& arguments, std::string& i2pBaseDir, const fp_proc_t& executingFn, const fp_t& cb);
63  ~JavaRunner() = default;
64
65  static const std::vector<NSString*> defaultStartupFlags;
66  static const std::vector<std::string> defaultFlagsForExtractorJob;
67
68  void requestRouterShutdown();
69
70  std::experimental::optional<std::future<int> > execute();
71  std::shared_ptr<Popen> javaProcess;
72  std::string javaBinaryPath;
73  std::string javaRouterArgs;
74  std::string execLine;
75  std::string _i2pBaseDir;
76private:
77  const fp_proc_t& executingFn;
78  const fp_t& exitCallbackFn;
79};
80
81
Note: See TracBrowser for help on using the repository browser.