Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2013 Trillian Mobile AB
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version 2
   * of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
  */
 package org.robovm.compiler.target.ios;
 
 
java.lang.Process implementation which runs an app on a device using an org.robovm.libimobiledevice.util.AppLauncher.
 
 class AppLauncherProcess extends Process implements Launcher {
     private final AtomicInteger threadCounter = new AtomicInteger();
     private final Logger log;
     private final AppLauncher launcher;
     private final WaitInputStream in = new WaitInputStream();
     private final WaitInputStream err = new WaitInputStream();
     private final CountDownLatch countDownLatch = new CountDownLatch(1);
     private Thread launcherThread;
     private volatile boolean finished = false;
     private volatile int exitCode = -1;
     private OutputStream errStream;
 
     AppLauncherProcess(Logger logAppLauncher launcherLaunchParameters launchParameters) {
         this. = log;
         this. = launcher;
         if (launchParameters.getStderrFifo() != null) {
             this. = new OpenOnWriteFileOutputStream(launchParameters.getStderrFifo());
         }
     }
 
     @Override
     public Process execAsync() throws IOException {
         .install();
         this. = new Thread("AppLauncherThread-" + .getAndIncrement()) {
             @Override
             public void run() {
                 try {
                      = .launch();
                 } catch (Throwable t) {
                     .error("AppLauncher failed with an exception:"t.getMessage());
                     t.printStackTrace(new PrintStream(new ErrorOutputStream(), true));
                 } finally {
                     IOUtils.closeQuietly();
                      = true;
                     .countDown();
                 }
             }
         };
         this..start();
         return this;
     }
     
     @Override
     public OutputStream getOutputStream() {
         return new NullOutputStream();
     }
 
     @Override
     public InputStream getInputStream() {
         return ;
     }
 
     @Override
     public InputStream getErrorStream() {
         return ;
     }
 
     @Override
     public int waitFor() throws InterruptedException {
         .await();
        return ;
    }
    @Override
    public int exitValue() {
        if (!) {
            throw new IllegalThreadStateException("Not terminated");
        }
        return ;
    }
    @Override
    public void destroy() {
        .kill();
    }
    private class WaitInputStream extends InputStream {
        @Override
        public int read() throws IOException {
            try {
                .await();
            } catch (InterruptedException e) {
                throw new InterruptedIOException();
            }
            return -1;
        }
        
    }
New to GrepCode? Check out our FAQ X