コード例 #1
0
ファイル: RemoteProcedure.java プロジェクト: unnch/spell-sat
 /**
  * *************************************************************************
  *
  * <p>************************************************************************
  */
 private void updateInfoFromRemote() throws Exception {
   IExecutorInfo info = new ExecutorInfo(m_procId);
   try {
     s_proxy.updateExecutorInfo(m_procId, info);
     m_executionInformation.copyFrom(info);
     ExecutorConfig cfg = new ExecutorConfig(m_procId);
     s_proxy.updateExecutorConfig(m_procId, cfg);
     m_properties.put(ProcProperties.PROC_NAME, info.getName());
     m_executionInformation.copyFrom(cfg);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
コード例 #2
0
 /**
  * ************************************************************************* Retrieve the source
  * code by sending a request to the {@link IContextProxy}
  *
  * @param codeId the codeId of the procedure which we request the code
  *     ************************************************************************
  */
 private String[] retrieveCode(String codeId, IProgressMonitor monitor) {
   List<String> lines = s_proxy.getProcedureCode(codeId, monitor);
   if (!monitor.isCanceled() && lines != null) {
     return lines.toArray(new String[0]);
   }
   return null;
 }
コード例 #3
0
ファイル: InputArea.java プロジェクト: Spacecraft-Code/SPELL
 /**
  * ************************************************************************* Cancel ongoing prompt
  * ************************************************************************
  */
 public void cancelPrompt() {
   m_promptData.setCancel();
   if (m_clientMode.equals(ClientMode.CONTROL)) {
     s_proxy.answerPrompt(m_promptData);
   }
   m_textInput.promptEnd();
   reset();
 }
コード例 #4
0
 /**
  * *************************************************************************
  *
  * <p>************************************************************************
  */
 @Override
 public void removeSharedScope(String scope) {
   if (scope.equals(GLOBAL_SCOPE)) return;
   if (m_tables.containsKey(scope)) {
     SPELLmessage msg = new SPELLmessageRemoveSharedVariableScope(s_proxy.getClientKey(), scope);
     SPELLmessage response;
     try {
       response = s_proxy.sendRequest(msg);
       if (response != null) {
         if (SPELLmessageRemoveSharedVariableScope.isSuccess(response)) {
           Logger.info("Remove shared scope " + scope, Level.PROC, this);
           m_tables.remove(scope);
         }
       }
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
 }
コード例 #5
0
  /**
   * ************************************************************************* Execute the command
   * ************************************************************************
   */
  @Override
  public void execute(Vector<String> args) throws CommandFailed {
    try {
      m_args = args;
      IServerProxy proxy = (IServerProxy) ServiceManager.get(IServerProxy.class);
      IContextProxy cproxy = (IContextProxy) ServiceManager.get(IContextProxy.class);
      if (!proxy.isConnected()) {
        throw new CommandFailed("Not connected to a server");
      }
      if (!cproxy.isConnected()) {
        throw new CommandFailed("Not attached to a context");
      }
      display(
          "Detaching from context at server " + proxy.getCurrentServer().getName(), Severity.INFO);
      proxy.detachContext();

      display("Detached.");
    } catch (CommandFailed ex) {
      throw ex;
    } catch (Exception ex) {
      throw new CommandFailed(ex.getLocalizedMessage());
    }
  }
コード例 #6
0
  @Override
  public void update(IProgressMonitor monitor) {
    List<String> scopes = null;
    SPELLmessage msg = new SPELLmessageGetSharedVariableScopes();
    SPELLmessage response;
    try {
      response = s_proxy.sendRequest(msg);
      if (response != null) {
        scopes = SPELLmessageGetSharedVariableScopes.getScopes(response);
      }
      if (scopes != null) {
        scopes.add(GLOBAL_SCOPE);
        // Create local model scope tables if needed
        for (String scope : scopes) {
          if (!m_tables.containsKey(scope)) {
            SharedScope table = new SharedScope(scope, s_proxy);
            m_tables.put(scope, table);
            Logger.debug("Added new scope during update: " + scope, Level.PROC, this);
          }
          if (monitor.isCanceled()) return;
        }
        // Clean local model scope tables if needed
        List<String> toRemove = new LinkedList<String>();
        for (String scope : m_tables.keySet()) {
          if (!scopes.contains(scope)) {
            toRemove.add(scope);
            Logger.debug("Remove scope during update: " + scope, Level.PROC, this);
          }
          if (monitor.isCanceled()) return;
        }
        for (String scope : toRemove) {
          m_tables.remove(scope);
          if (monitor.isCanceled()) return;
        }
      }

      // Once the set of scopes is aligned, update the tables
      for (ISharedScope table : m_tables.values()) {
        Logger.debug("Updating scope: " + table.getScopeName(), Level.PROC, this);
        table.update(monitor);
        if (monitor.isCanceled()) return;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #7
0
  /**
   * ************************************************************************* Update context
   * information ************************************************************************
   */
  private void updateContext(boolean connectionLost) {
    if (s_contextInfo != null) {
      String ctxName = s_contextInfo.getName();
      String domain = s_contextInfo.getSC();
      m_context.setText(" " + ctxName + " ");
      m_context.setBackground(s_okColor);

      m_domain.setText(" " + domain + " ");
      m_domain.setBackground(s_okColor);

      m_driver.setText(" " + s_contextInfo.getDriver() + " ");
      m_driver.setBackground(s_okColor);

      m_family.setText(" " + s_contextInfo.getFamily() + " ");
      m_family.setBackground(s_okColor);

      m_key.setText(s_proxy.getClientKey());
      m_key.setBackground(s_okColor);

      if (s_serverInfo != null) {
        ServerInfo.ServerRole role = s_serverInfo.getRole();
        m_mode.setText(role.equals(ServerInfo.ServerRole.COMMANDING) ? "CMD" : "MON");
        m_mode.setBackground(s_okColor);
      }
    } else {
      m_mode.setText(ConnectionStatusConstants.UNKNOWN);
      m_domain.setText(ConnectionStatusConstants.UNKNOWN);
      m_driver.setText(ConnectionStatusConstants.UNKNOWN);
      m_family.setText(ConnectionStatusConstants.UNKNOWN);
      m_key.setText("?");
      if (connectionLost) {
        m_context.setText(ConnectionStatusConstants.FAILURE);
        m_context.setBackground(s_errorColor);
      } else {
        m_context.setText(ConnectionStatusConstants.UNKNOWN);
        m_context.setBackground(s_warnColor);
      }
      m_mode.setBackground(s_warnColor);
      m_domain.setBackground(s_warnColor);
      m_driver.setBackground(s_warnColor);
      m_family.setBackground(s_warnColor);
      m_key.setBackground(s_warnColor);
    }
    m_base.getParent().pack();
  }
コード例 #8
0
ファイル: InputArea.java プロジェクト: Spacecraft-Code/SPELL
  /**
   * ************************************************************************* Handle a text command
   * ************************************************************************
   */
  private void handlePromptAnswer() {
    Logger.debug("Handle prompt answer", Level.GUI, this);

    String answer = m_textInput.getValue();
    if (answer.length() == 0 && m_selectedOption < 0) {
      MessageDialog.openError(getShell(), "Prompt error", "Cannot commit, no value given");
      m_textInput.reset();
      m_textInput.promptStart();

      return;
    }
    if (m_numericInput) {
      try {
        // Is it an int?
        Integer.parseInt(answer);
        m_promptData.setReturnValue(answer);
      } catch (NumberFormatException ex) {
        try {
          // Is it a double?
          Double.parseDouble(answer);
          m_promptData.setReturnValue(answer);
        } catch (NumberFormatException ex2) {
          try {
            // Is it a hex?
            if (answer.startsWith("0x")) {
              int a = Integer.parseInt(answer.substring(2), 16);
              m_promptData.setReturnValue(a + "");
            } else {
              throw new NumberFormatException("Hex out of range");
            }
          } catch (NumberFormatException ex3) {
            MessageDialog.openError(
                getShell(), "Prompt error", "Cannot commit, expected a numeric value");

            m_textInput.reset();
            m_textInput.promptStart();

            return;
          }
        }
      }
    } else if (m_expected != null) {
      Logger.debug("Have expected values", Level.GUI, this);
      // If the input text field has an answer
      if (!answer.isEmpty()) {
        Logger.debug("Current text field answer: '" + answer + "'", Level.GUI, this);
        // Check if there is a selected option
        if (m_selectedOption >= 0) {
          // If there is a choice, it must be consistent with the text
          // input
          String optString = m_expected.get(m_selectedOption);

          Logger.debug("Option string: '" + optString + "'", Level.GUI, this);

          if (!optString.equals(answer)) {
            MessageDialog.openError(
                getShell(),
                "Prompt error",
                "Conflicting values found between text area and buttons");

            resetOptions();

            m_textInput.reset();
            m_textInput.promptStart();

            return;
          }
        }
        // If there is no selected option, check that the text input
        // matches any of the expected values
        else {
          boolean accept = false;
          for (String opt : m_expected) {
            if (opt.equals(answer)) {
              accept = true;
              break;
            }
          }
          if (!accept) {
            String values = "";
            for (String exp : m_expected) values += exp + "\n";
            MessageDialog.openError(
                getShell(), "Prompt error", "Must enter one of the expected values:\n" + values);
            m_textInput.reset();
            m_textInput.promptStart();
            return;
          }
        }

        // If we reach this point it is ok. Set the prompt answer, but
        // getting the corresponding index of the option
        int idx = -1;
        int count = 0;
        for (String expected : m_expected) {
          if (expected.equals(answer)) {
            idx = count;
            break;
          }
          count++;
        }
        m_promptData.setReturnValue(Integer.toString(idx));
      }
      // If the text input does not have a text, at least there must be a
      // selected option in the list
      else if (m_selectedOption == -1) {
        String values = "";
        for (String exp : m_expected) values += exp + "\n";
        MessageDialog.openError(
            getShell(), "Prompt error", "Must enter one of the expected values:\n" + values);
        m_textInput.reset();
        m_textInput.promptStart();
        return;
      }
      // We have a selected option
      else {
        // Set the option index as return value
        m_promptData.setReturnValue(Integer.toString(m_selectedOption));
      }
    } else {
      m_promptData.setReturnValue(answer);
    }
    s_proxy.answerPrompt(m_promptData);
    m_parent.resetPrompt();
    m_textInput.promptEnd();
  }