DebugServer2
Loading...
Searching...
No Matches
ProcessSpawner.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include "DebugServer2/Types.h"
14
15#include <functional>
16
17namespace ds2 {
18namespace Host {
19
21protected:
22 std::string _executablePath;
23 StringCollection _arguments;
24 EnvironmentBlock _environment;
25 std::string _workingDirectory;
26 ProcessId _pid;
27 HANDLE _handle;
28 ThreadId _tid;
29 HANDLE _threadHandle;
30
31public:
34
35protected:
36 typedef std::function<void(void *buf, size_t size)> RedirectDelegate;
37
38public:
39 bool setExecutable(std::string const &path);
40 bool setShellCommand(std::string const &command);
41 bool setWorkingDirectory(std::string const &path);
42
43public:
44 bool setArguments(StringCollection const &args);
45
46 template <typename... Args> inline bool setArguments(Args const &... args) {
47 std::string args_[] = {args...};
48 return setArguments(StringCollection(&args_[0], &args_[sizeof...(Args)]));
49 }
50
51public:
52 bool setEnvironment(EnvironmentBlock const &args);
53 bool addEnvironment(std::string const &key, std::string const &val);
54
55public:
56 bool redirectInputToConsole() { return false; }
57 bool redirectOutputToConsole() { return false; }
58 bool redirectErrorToConsole() { return false; }
59
60public:
61 bool redirectInputToNull() { return false; }
62 bool redirectOutputToNull() { return false; }
63 bool redirectErrorToNull() { return false; }
64
65public:
66 bool redirectInputToFile(std::string const &path) { return false; }
67 bool redirectOutputToFile(std::string const &path) { return false; }
68 bool redirectErrorToFile(std::string const &path) { return false; }
69
70public:
71 bool redirectOutputToBuffer() { return false; }
72 bool redirectErrorToBuffer() { return false; }
73
74public:
75 bool redirectInputToTerminal() { return false; }
76
77public:
78 bool redirectOutputToDelegate(RedirectDelegate delegate) { return false; }
79 bool redirectErrorToDelegate(RedirectDelegate delegate) { return false; }
80
81public:
82 ErrorCode run(std::function<bool()> preExecAction = []() { return true; });
83 ErrorCode wait() { return kErrorUnsupported; }
84 bool isRunning() const { return false; }
85 void flushAndExit() {}
86
87public:
88 inline ProcessId pid() const { return _pid; }
89 inline HANDLE handle() const { return _handle; }
90 inline ThreadId tid() const { return _tid; }
91 inline HANDLE threadHandle() const { return _threadHandle; }
92 inline int exitStatus() const { return 0; }
93 inline int signalCode() const { return 0; }
94 inline std::string const &executable() const { return _executablePath; }
95 inline StringCollection const &arguments() const { return _arguments; }
96 inline EnvironmentBlock const &environment() const { return _environment; }
97
98public:
99 ErrorCode input(ByteVector const &buf) { return kErrorUnsupported; }
100
101 inline std::string const &output() const {
102 static std::string s;
103 return s;
104 }
105
106private:
107 void redirectionThread();
108};
109} // namespace Host
110} // namespace ds2
Definition ProcessSpawner.h:20