Esempio n. 1
0
  /*
   * Wait until the device status becomes online
   *
   * @param serialNumber device serial number
   *
   * @param instance TmL instance, if it exists
   *
   * @return true if the device became online, false otherwise
   */
  private static boolean waitForDeviceToBeOnline(String serialNumber, ISerialNumbered instance) {
    AndmoreLogger.debug("Wait device to be online: " + serialNumber);

    boolean instanceOnline = false;
    long timeoutLimit = 0;

    if (instance != null) {
      Properties prop = ((IInstance) instance).getProperties();
      String timeout = prop.getProperty(RemoteDeviceInstance.PROPERTY_TIMEOUT);
      timeoutLimit = System.currentTimeMillis() + (Integer.parseInt(timeout) * 1000);
    } else {
      timeoutLimit = System.currentTimeMillis() + (RemoteDeviceConstants.DEFAULT_TIMEOUT * 1000);
    }

    while ((instanceOnline = DDMSFacade.isDeviceOnline(serialNumber)) == false) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        AndmoreLogger.error("Wait for device to be online: thread has been interrupted");
      }

      try {
        testTimeout(timeoutLimit);
      } catch (TimeoutException e) {
        AndmoreLogger.warn("Timeout reached wile wating device to be online: " + serialNumber);
        break;
      }
    }
    return instanceOnline;
  }
Esempio n. 2
0
  /**
   * Handle Remote Device disconnection
   *
   * @param serialNumber the serial number of the disconnected device
   */
  public static void disconnectDevice(String serialNumber) {
    if (DDMSFacade.isRemote(serialNumber)) {

      ISerialNumbered instance = DevicesManager.getInstance().getDeviceBySerialNumber(serialNumber);

      AndmoreLogger.debug(
          "Handle remote device disconnected event. Serial Number: "
              + serialNumber
              + " Instance: "
              + instance);

      if (instance != null) {
        Object volatileProperty =
            ((RemoteDeviceInstance) instance)
                .getProperties()
                .get(RemoteDeviceInstance.PROPERTY_VOLATILE);
        boolean isVolatile =
            ((volatileProperty != null) ? ((Boolean) volatileProperty).booleanValue() : false);

        if (!isVolatile) {
          try {
            AndmoreLogger.debug(
                "Disconnecting Remote Device: the device is NOT volatile, the TmL service will be called");

            Map<Object, Object> arguments = new HashMap<Object, Object>();
            arguments.put(RemoteDeviceConstants.DUMMY_TRANSITION, true);
            RemoteDevicePlugin.getDisconnectServiceHandler().run((IInstance) instance, arguments);
          } catch (Exception e) {
            AndmoreLogger.error("Error when running TmL disconnect service: " + e.getMessage());
          }
        } else {
          AndmoreLogger.debug(
              "Disconnecting Remote Device: the device is volatile, it will be deleted");
          DevicesManager.getInstance().deleteInstanceOfDevice(serialNumber);
        }
      }
    }
  }
Esempio n. 3
0
  /**
   * Initialize the scroll bars This include: a) setting the initial enabled state b) adding the
   * necessary listeners
   */
  private void initScrollBars() {

    ScrollBar horizontal = getHorizontalBar();
    horizontal.setEnabled(false);
    horizontal.addSelectionListener(
        new SelectionAdapter() {
          /** @see org.eclipse.swt.events.SelectionListener#widgetSelected(SelectionEvent) */
          @Override
          public void widgetSelected(SelectionEvent event) {
            // Updates the translation
            displayRectangle.x = ((ScrollBar) event.widget).getSelection();

            // Update the UI
            layout();
            redraw();
          }
        });

    ScrollBar vertical = getVerticalBar();
    vertical.setEnabled(false);
    vertical.addSelectionListener(
        new SelectionAdapter() {
          /** @see org.eclipse.swt.events.SelectionListener#widgetSelected(SelectionEvent) */
          @Override
          public void widgetSelected(SelectionEvent event) {
            // Updates the translation
            displayRectangle.y = ((ScrollBar) event.widget).getSelection();

            // Update the UI
            layout();
            redraw();
          }
        });

    debug("Initialized scroll bars");
  }