78
79 MessageResponse PosixPlatform::ShowResponseMessage(TString title,
80 TString description) {
81 MessageResponse result = mrCancel;
82
83 printf("%s %s (Y/N)\n", PlatformString(title).toPlatformString(),
84 PlatformString(description).toPlatformString());
85 fflush(stdout);
86
87 std::string input;
88 std::cin >> input;
89
90 if (input == "Y") {
91 result = mrOK;
92 }
93
94 return result;
95 }
96
97 void PosixPlatform::SetCurrentDirectory(TString Value) {
98 chdir(StringToFileSystemString(Value));
99 }
100
101 Module PosixPlatform::LoadLibrary(TString FileName) {
102 return dlopen(StringToFileSystemString(FileName), RTLD_LAZY);
103 }
104
105 void PosixPlatform::FreeLibrary(Module AModule) {
106 dlclose(AModule);
107 }
108
109 Procedure PosixPlatform::GetProcAddress(Module AModule,
110 std::string MethodName) {
111 return dlsym(AModule, PlatformString(MethodName));
112 }
113
114 Process* PosixPlatform::CreateProcess() {
115 return new PosixProcess();
116 }
117
118 void PosixPlatform::addPlatformDependencies(JavaLibrary *pJavaLibrary) {
195 }
196
197 bool PosixProcess::ReadOutput() {
198 bool result = false;
199
200 if (FOutputHandle != 0 && IsRunning() == true) {
201 char buffer[4096] = {0};
202
203 ssize_t count = read(FOutputHandle, buffer, sizeof (buffer));
204
205 if (count == -1) {
206 if (errno == EINTR) {
207 // continue;
208 } else {
209 perror("read");
210 exit(1);
211 }
212 } else if (count == 0) {
213 // break;
214 } else {
215 if (buffer[count - 1] == EOF) {
216 buffer[count - 1] = '\0';
217 }
218
219 std::list<TString> output = Helpers::StringToArray(buffer);
220 FOutput.splice(FOutput.end(), output, output.begin(), output.end());
221 result = true;
222 }
223 }
224
225 return false;
226 }
227
228 bool PosixProcess::IsRunning() {
229 bool result = false;
230
231 if (kill(FChildPID, 0) == 0) {
232 result = true;
233 }
234
235 return result;
236 }
237
238 bool PosixProcess::Terminate() {
293 printf("child continued\n");
294 #endif // WIFCONTINUED
295 } else { // Non-standard case -- may never happen
296 printf("Unexpected status (0x%x)\n", status);
297 }
298 #endif // DEBUG
299
300 if (wpid != -1) {
301 result = true;
302 }
303
304 return result;
305 }
306
307 TProcessID PosixProcess::GetProcessID() {
308 return FChildPID;
309 }
310
311 void PosixProcess::SetInput(TString Value) {
312 if (FInputHandle != 0) {
313 write(FInputHandle, Value.data(), Value.size());
314 }
315 }
316
317 std::list<TString> PosixProcess::GetOutput() {
318 ReadOutput();
319 return Process::GetOutput();
320 }
|
78
79 MessageResponse PosixPlatform::ShowResponseMessage(TString title,
80 TString description) {
81 MessageResponse result = mrCancel;
82
83 printf("%s %s (Y/N)\n", PlatformString(title).toPlatformString(),
84 PlatformString(description).toPlatformString());
85 fflush(stdout);
86
87 std::string input;
88 std::cin >> input;
89
90 if (input == "Y") {
91 result = mrOK;
92 }
93
94 return result;
95 }
96
97 void PosixPlatform::SetCurrentDirectory(TString Value) {
98 int ignored = chdir(StringToFileSystemString(Value));
99 }
100
101 Module PosixPlatform::LoadLibrary(TString FileName) {
102 return dlopen(StringToFileSystemString(FileName), RTLD_LAZY);
103 }
104
105 void PosixPlatform::FreeLibrary(Module AModule) {
106 dlclose(AModule);
107 }
108
109 Procedure PosixPlatform::GetProcAddress(Module AModule,
110 std::string MethodName) {
111 return dlsym(AModule, PlatformString(MethodName));
112 }
113
114 Process* PosixPlatform::CreateProcess() {
115 return new PosixProcess();
116 }
117
118 void PosixPlatform::addPlatformDependencies(JavaLibrary *pJavaLibrary) {
195 }
196
197 bool PosixProcess::ReadOutput() {
198 bool result = false;
199
200 if (FOutputHandle != 0 && IsRunning() == true) {
201 char buffer[4096] = {0};
202
203 ssize_t count = read(FOutputHandle, buffer, sizeof (buffer));
204
205 if (count == -1) {
206 if (errno == EINTR) {
207 // continue;
208 } else {
209 perror("read");
210 exit(1);
211 }
212 } else if (count == 0) {
213 // break;
214 } else {
215 std::list<TString> output = Helpers::StringToArray(buffer);
216 FOutput.splice(FOutput.end(), output, output.begin(), output.end());
217 result = true;
218 }
219 }
220
221 return false;
222 }
223
224 bool PosixProcess::IsRunning() {
225 bool result = false;
226
227 if (kill(FChildPID, 0) == 0) {
228 result = true;
229 }
230
231 return result;
232 }
233
234 bool PosixProcess::Terminate() {
289 printf("child continued\n");
290 #endif // WIFCONTINUED
291 } else { // Non-standard case -- may never happen
292 printf("Unexpected status (0x%x)\n", status);
293 }
294 #endif // DEBUG
295
296 if (wpid != -1) {
297 result = true;
298 }
299
300 return result;
301 }
302
303 TProcessID PosixProcess::GetProcessID() {
304 return FChildPID;
305 }
306
307 void PosixProcess::SetInput(TString Value) {
308 if (FInputHandle != 0) {
309 ssize_t ignored = write(FInputHandle, Value.data(), Value.size());
310 }
311 }
312
313 std::list<TString> PosixProcess::GetOutput() {
314 ReadOutput();
315 return Process::GetOutput();
316 }
|