1
2
3
4
5
6 #include <cmajor/rt/Process.hpp>
7 #include <cmajor/rt/String.hpp>
8 #include <soulng/util/Process.hpp>
9
10 void* RtCreateProcess(const char* command, int32_t redirections, int32_t& errorStringHandle)
11 {
12 std::string cmd(command);
13 errorStringHandle = -1;
14 try
15 {
16 soulng::util::Process* process = new soulng::util::Process(cmd, static_cast<soulng::util::Process::Redirections>(redirections));
17 return process;
18 }
19 catch (const std::exception& ex;)
20 {
21 errorStringHandle = cmajor::rt::InstallString("error creating process '" + cmd + "': " + ex.what());
22 }
23 return nullptr;
24 }
25
26 void RtDeleteProcess(void* process)
27 {
28 delete static_cast<soulng::util::Process*>(process);
29 }
30
31 const char* RtGetString(int32_t stringHandle)
32 {
33 return cmajor::rt::GetString(stringHandle);
34 }
35
36 void RtDisposeString(int32_t stringHandle)
37 {
38 cmajor::rt::DisposeString(stringHandle);
39 }
40
41 bool RtProcessRunning(void* process, int32_t& errorStringHandle)
42 {
43 try
44 {
45 errorStringHandle = -1;
46 return static_cast<soulng::util::Process*>(process)->Running();
47 }
48 catch (const std::exception& ex;)
49 {
50 errorStringHandle = cmajor::rt::InstallString(ex.what());
51 return false;
52 }
53 }
54
55 bool RtProcessWaitForExit(void* process, int32_t& errorStringHandle)
56 {
57 try
58 {
59 errorStringHandle = -1;
60 static_cast<soulng::util::Process*>(process)->WaitForExit();
61 return true;
62 }
63 catch (const std::exception& ex;)
64 {
65 errorStringHandle = cmajor::rt::InstallString(ex.what());
66 return false;
67 }
68 }
69
70 int RtProcessExitCode(void* process, int32_t& errorStringHandle)
71 {
72 try
73 {
74 errorStringHandle = -1;
75 return static_cast<soulng::util::Process*>(process)->ExitCode();
76 }
77 catch (const std::exception& ex;)
78 {
79 errorStringHandle = cmajor::rt::InstallString(ex.what());
80 return 1;
81 }
82 }
83
84 bool RtProcessTerminate(void* process, int32_t& errorStringHandle)
85 {
86 try
87 {
88 errorStringHandle = -1;
89 static_cast<soulng::util::Process*>(process)->Terminate();
90 }
91 catch (const std::exception& ex;)
92 {
93 errorStringHandle = cmajor::rt::InstallString(ex.what());
94 return false;
95 }
96 return true;
97 }
98
99 bool RtProcessEof(void* process, int handle, int32_t& errorStringHandle)
100 {
101 try
102 {
103 errorStringHandle = -1;
104 return static_cast<soulng::util::Process*>(process)->Eof(static_cast<soulng::util::Process::StdHandle>(handle));
105 }
106 catch (const std::exception& ex;)
107 {
108 errorStringHandle = cmajor::rt::InstallString(ex.what());
109 return true;
110 }
111 }
112
113 int32_t RtProcessReadLine(void* process, int handle, int32_t& errorStringHandle)
114 {
115 try
116 {
117 errorStringHandle = -1;
118 std::string line = static_cast<soulng::util::Process*>(process)->ReadLine(static_cast<soulng::util::Process::StdHandle>(handle));
119 return cmajor::rt::InstallString(line);
120 }
121 catch (const std::exception& ex;)
122 {
123 errorStringHandle = cmajor::rt::InstallString(ex.what());
124 return -1;
125 }
126 }
127
128 int32_t RtProcessReadToEnd(void* process, int handle, int32_t& errorStringHandle)
129 {
130 try
131 {
132 errorStringHandle = -1;
133 std::string str = static_cast<soulng::util::Process*>(process)->ReadToEnd(static_cast<soulng::util::Process::StdHandle>(handle));
134 return cmajor::rt::InstallString(str);
135 }
136 catch (const std::exception& ex;)
137 {
138 errorStringHandle = cmajor::rt::InstallString(ex.what());
139 return -1;
140 }
141 }
142
143 bool RtProcessWriteLine(void* process, const char* line, int32_t& errorStrHandle)
144 {
145 try
146 {
147 errorStrHandle = -1;
148 std::string lineStr(line);
149 static_cast<soulng::util::Process*>(process)->WriteLine(lineStr);
150 }
151 catch (const std::exception& ex;)
152 {
153 errorStrHandle = cmajor::rt::InstallString(ex.what());
154 return false;
155 }
156 return true;
157 }