< prev index next >

src/jdk.incubator.jpackage/unix/native/libapplauncher/PosixPlatform.cpp

Print this page




  77 }
  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) {
 119 }
 120 


 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 }


  77 }
  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 Module PosixPlatform::LoadLibrary(TString FileName) {
  98     return dlopen(StringToFileSystemString(FileName), RTLD_LAZY);
  99 }
 100 
 101 void PosixPlatform::FreeLibrary(Module AModule) {
 102     dlclose(AModule);
 103 }
 104 
 105 Procedure PosixPlatform::GetProcAddress(Module AModule,
 106         std::string MethodName) {
 107     return dlsym(AModule, PlatformString(MethodName));
 108 }
 109 
 110 Process* PosixPlatform::CreateProcess() {
 111     return new PosixProcess();
 112 }
 113 
 114 void PosixPlatform::addPlatformDependencies(JavaLibrary *pJavaLibrary) {
 115 }
 116 


 191 }
 192 
 193 bool PosixProcess::ReadOutput() {
 194     bool result = false;
 195 
 196     if (FOutputHandle != 0 && IsRunning() == true) {
 197         char buffer[4096] = {0};
 198 
 199         ssize_t count = read(FOutputHandle, buffer, sizeof (buffer));
 200 
 201         if (count == -1) {
 202             if (errno == EINTR) {
 203                 // continue;
 204             } else {
 205                 perror("read");
 206                 exit(1);
 207             }
 208         } else if (count == 0) {
 209             // break;
 210         } else {




 211             std::list<TString> output = Helpers::StringToArray(buffer);
 212             FOutput.splice(FOutput.end(), output, output.begin(), output.end());
 213             result = true;
 214         }
 215     }
 216 
 217     return false;
 218 }
 219 
 220 bool PosixProcess::IsRunning() {
 221     bool result = false;
 222 
 223     if (kill(FChildPID, 0) == 0) {
 224         result = true;
 225     }
 226 
 227     return result;
 228 }
 229 
 230 bool PosixProcess::Terminate() {


 285         printf("child continued\n");
 286 #endif // WIFCONTINUED
 287     } else { // Non-standard case -- may never happen
 288         printf("Unexpected status (0x%x)\n", status);
 289     }
 290 #endif // DEBUG
 291 
 292     if (wpid != -1) {
 293         result = true;
 294     }
 295 
 296     return result;
 297 }
 298 
 299 TProcessID PosixProcess::GetProcessID() {
 300     return FChildPID;
 301 }
 302 
 303 void PosixProcess::SetInput(TString Value) {
 304     if (FInputHandle != 0) {
 305         if (write(FInputHandle, Value.data(), Value.size()) < 0) {
 306             throw Exception(_T("Internal Error - write failed"));
 307         }
 308     }
 309 }
 310 
 311 std::list<TString> PosixProcess::GetOutput() {
 312     ReadOutput();
 313     return Process::GetOutput();
 314 }
< prev index next >