public Object execute(List<String> argList) throws TclShellException {
    JSAPResult argv = parse(argList);
    if (argv == null) {
      return false;
    }

    if (argv.getBoolean(SmOptionPM.LIST_ATTR_OPTION)) {
      for (PWR_SRC_ATTR e : PWR_SRC_ATTR.values())
        System.out.println(
            " =>  "
                + e.arg
                + " :\n         "
                + e.help
                + (e.allowed == null ? "" : " = " + StringUtilities.join(", ", e.allowed) + ")"));

      return true;
    }

    String modelID = argv.getString(SmOption.MODEL_OPTION);
    ModelDB model =
        (modelID != null) ? ToolsDesign.getModel(modelID) : UnwCore.getDBProject().model();

    if (model == null) {
      Logger.error(ErrorList.DB3.errorName(), ErrorList.DB3.getMessage(modelID));
      throw new TclShellException("");
    }

    PMConfig cfg = PMResourceManager.instance.getPmconfig(model, null);

    String pwrsrcName = argv.getString(SmOptionPM.PWRSRC_OPTION);

    PowerSourceInstance powerSource = PMFindVDomainTools.findPowerSource(cfg, pwrsrcName);

    if (powerSource == null) {
      Logger.error(
          ErrorListPM.PM22.errorName(),
          ErrorListPM.PM22.getMessage(pwrsrcName + "in model " + model.getModelName()));
      throw new TclShellException("");
    }

    if (!argv.contains(SmOption.NAME_VALUE_OPTION)) {
      Logger.error("TCL", "no attribute specified");
      throw new TclShellException("");
    }

    String[] tokens = argv.getStringArray(SmOption.NAME_VALUE_OPTION);
    if (tokens.length % 2 != 0) {
      Logger.error(ErrorListPM.PM_TCL1.errorName(), ErrorListPM.PM_TCL1.getMessage());
      throw new TclShellException("");
    }

    String attrName;
    String attrValue;
    boolean error = false;

    for (int i = 0; i < tokens.length; i += 2) {
      attrName = tokens[i];
      attrValue = tokens[i + 1];

      PWR_SRC_ATTR id = PWR_SRC_ATTR.findAttr(attrName);

      if (id == null) {
        Logger.error(ErrorListPM.PM_TCL3.errorName(), ErrorListPM.PM_TCL3.getMessage(attrName));
        throw new TclShellException("");

      } else {

        CONNECT_DIRECTIVE direct = null;

        switch (id) {
          case CONNECT_IVOLT:
            try {
              direct = CONNECT_DIRECTIVE.valueOf(attrValue);
              powerSource.setConnectInputVoltage(direct);
            } catch (Exception e) {
              error = true;
            }
            break;

          case CONNECT_CTRL:
            try {
              direct = CONNECT_DIRECTIVE.valueOf(attrValue);
              powerSource.setConnectControl(direct);
            } catch (Exception e) {
              error = true;
            }
            break;

          case NAME:
            if (FormatValidation.isAlphaNumeric(attrValue, false)) {
              powerSource.setName(attrValue);
            } else error = true;

          default:
            break;
        }

        if (error) {
          Logger.error(
              ErrorListPM.PM_TCL2.errorName(),
              ErrorListPM.PM_TCL2.getMessage(attrValue + " for attribute " + attrName));
          throw new TclShellException("");
        }
      }
    }

    return true;
  }
示例#2
0
  static {
    probeNameOptionF =
        new FlaggedOption(PROBENAME)
            .setStringParser(JSAP.STRING_PARSER)
            .setRequired(true)
            .setShortFlag('x')
            .setLongFlag(JSAP.NO_LONGFLAG)
            .setUsageName(PROBENAME);
    probeNameOptionF.setHelp("the name of the probe in the x-axis (required)");

    probeNameOptionUF =
        new UnflaggedOption(PROBENAME)
            .setStringParser(JSAP.STRING_PARSER)
            .setRequired(true)
            .setUsageName(PROBENAME);
    probeNameOptionUF.setHelp("the name of the probe (required)");

    valueOptionUF =
        new UnflaggedOption(VALUE)
            .setStringParser(JSAP.STRING_PARSER)
            .setRequired(false)
            .setUsageName(VALUE);

    optionsOptionF =
        new FlaggedOption(OPTIONS)
            .setStringParser(JSAP.STRING_PARSER)
            .setRequired(false)
            .setLongFlag(OPTIONS)
            .setUsageName(OPTIONS);

    currentTypeOptionF =
        new FlaggedOption(PROBE_TYPE)
            .setStringParser(
                EnumeratedStringParser.getParser(
                    StringUtilities.join(
                        ";",
                        new String[] {
                          VIRTPORT_TYPE.CURRENT_DYN.getTclOption(),
                          VIRTPORT_TYPE.CURRENT_LEAK.getTclOption(),
                          VIRTPORT_TYPE.CURRENT_TOT.getTclOption(),
                          VIRTPORT_TYPE.CURRENT_DYN_ALL.getTclOption(),
                          VIRTPORT_TYPE.CURRENT_LEAK_ALL.getTclOption(),
                          VIRTPORT_TYPE.CURRENT_TOT_ALL.getTclOption(),
                          VIRTPORT_TYPE.POWER_DYN.getTclOption(),
                          VIRTPORT_TYPE.POWER_LEAK.getTclOption(),
                          VIRTPORT_TYPE.POWER_TOT.getTclOption(),
                          VIRTPORT_TYPE.POWER_DYN_ALL.getTclOption(),
                          VIRTPORT_TYPE.POWER_LEAK_ALL.getTclOption(),
                          VIRTPORT_TYPE.POWER_TOT_ALL.getTclOption()
                        })))
            .setRequired(false)
            .setShortFlag('t')
            .setLongFlag(PROBE_TYPE)
            .setUsageName(PROBE_TYPE);

    orderOptionF =
        new FlaggedOption(ORDER_OPTION)
            .setStringParser(
                EnumeratedStringParser.getParser(
                    SLICE_ORDER.PARALLEL.getText() + ";" + SLICE_ORDER.SERIAL.getText()))
            .setRequired(false)
            .setShortFlag('o')
            .setLongFlag(ORDER_OPTION)
            .setUsageName(SLICE_ORDER.PARALLEL.getText() + "|" + SLICE_ORDER.SERIAL.getText());

    activityOptionF =
        new FlaggedOption(ACTIVTY)
            .setStringParser(JSAP.FLOAT_PARSER)
            .setRequired(false)
            .setShortFlag('a')
            .setLongFlag(ACTIVTY)
            .setUsageName("% of activity of the scenario");

    configOption_S = new Switch(CONFIG_OPTION).setLongFlag(CONFIG_OPTION);

    configOption_S.setHelp("specify a config state");

    defaultOption_S = new Switch(DEFAULT_OPTION).setLongFlag(DEFAULT_OPTION);

    defaultOption_S.setHelp("specify a default content");

    tilltime_F =
        new FlaggedOption(TILLTIME_OPTION)
            .setStringParser(JSAP.FLOAT_PARSER)
            .setRequired(false)
            .setLongFlag(TILLTIME_OPTION)
            .setUsageName(TILLTIME_OPTION);

    setOnlyS = new Switch(SETONLY_OPTION).setLongFlag(SETONLY_OPTION);
    setOnlyS.setHelp("force only the signal, and do to recompute the state of");

    bundleS = new Switch(BUNDLE_OPTION).setLongFlag(BUNDLE_OPTION);
    bundleS.setHelp("create a bundle");

    removeS = new Switch(REMOVE_OPTION).setLongFlag(REMOVE_OPTION);
    removeS.setHelp("remove the force command");

    addS = new Switch(ADD_OPTION).setLongFlag(ADD_OPTION).setShortFlag('a');
    addS.setHelp("add the probe to the table");

    datapoints_S = new Switch(DATAPOINTS_OPTION).setLongFlag(DATAPOINTS_OPTION).setShortFlag('d');
    datapoints_S.setHelp("return all data points");

    pathOptionF =
        new FlaggedOption(PATH_OPTION)
            .setStringParser(JSAP.STRING_PARSER)
            .setRequired(true)
            .setShortFlag('p')
            .setLongFlag(PATH_OPTION)
            .setUsageName("scenario|slice|activity path");
  }