Ejemplo n.º 1
0
void Battery::update()
{
    BatteryStatus status      = getStatusValue(mPathBatteryStatus);
    BatteryHealth health      = getHealthValue(mPathBatteryHealth);
    bool          ac_online   = getBooleanValue(mPathACOnline);
    bool          usb_online  = getBooleanValue(mPathUSBOnline);
    bool          present     = getBooleanValue(mPathBatteryPresent);
    int           capacity    = getIntegerValue(mPathBatteryCapacity);
    int           voltage     = getIntegerValue(mPathBatteryVoltage) / mVoltageDivisor;
    int           temperature = getIntegerValue(mPathBatteryTemperature);
    QString       technology  = getByteArray(mPathBatteryTechnology);

    bool changed = (status != mStatus || health != mHealth ||
		    ac_online != mACOnline || usb_online != mUSBOnline ||
		    present != mPresent || capacity != mCapacity ||
		    voltage != mVoltage || temperature != mTemperature ||
		    technology != mTechnology );

    if (changed) {
	mStatus      = status;
	mHealth      = health;
	mACOnline    = ac_online;
	mUSBOnline   = usb_online;
	mPresent     = present;
	mCapacity    = capacity;
	mVoltage     = voltage;
	mTemperature = temperature;
	mTechnology  = technology;
	emit dataChanged();
    }
}
Ejemplo n.º 2
0
static int is_true(Lexeme * condition, Lexeme * env) {
    Lexeme * result = evaluate(condition, env);
    if (! typeBoolean(result)) {
        fprintf(stderr, "Conditional error: A condition must evaluate to a Boolean, not <%s>.",
            getType(result));
        exit(-1);
    }
    return getBooleanValue(result);
}
Ejemplo n.º 3
0
void SetVariableCommand::setVariableValue(
  DebuggerSession* session,
  const std::string& name,
  const std::string& value,
  TypedValue* typedVariable,
  request_id_t requestId,
  folly::dynamic* result
) {
  switch (typedVariable->m_type) {
    case KindOfBoolean: {
        bool boolVal = getBooleanValue(value);
        typedVariable->m_data.num = boolVal ? 1 : 0;
      }
      break;

    case KindOfInt64:
      try {
        typedVariable->m_data.num = std::stoi(value, nullptr, 0);
      } catch (std::exception e) {
        throw DebuggerCommandException("Invalid value specified.");
      }
      break;

    case KindOfDouble:
      try {
        typedVariable->m_data.dbl = std::stod(value);
      } catch (std::exception e) {
        throw DebuggerCommandException("Invalid value specified.");
      }
      break;

    case KindOfPersistentString:
    case KindOfString: {
      const auto newSd = StringData::Make(
        value.c_str(),
        CopyString
      );

      if (typedVariable->m_type == KindOfString &&
          typedVariable->m_data.pstr != nullptr) {

        typedVariable->m_data.pstr->decRefCount();
      }

      typedVariable->m_data.pstr = newSd;
      typedVariable->m_type = KindOfString;
      break;
    }

    case KindOfUninit:
    case KindOfNull:
      // In the case of uninit and null, we don't even know how to interpret
      // the value from the client, because the object has no known type.
      // Fallthrough.
    case KindOfResource:
    case KindOfPersistentVec:
    case KindOfVec:
    case KindOfPersistentArray:
    case KindOfArray:
    case KindOfPersistentDict:
    case KindOfDict:
    case KindOfPersistentKeyset:
    case KindOfKeyset:
    case KindOfRef:
    case KindOfObject:
      // For complex types, we need to run PHP code to create a new object
      // or determine what reference to assign, making direct assignment via
      // reflection impractical, so we defer to the console REPL, which will use
      // an evaluation command to run PHP.
      // NOTE: It would be nice in the future to just run an eval command here
      // on the user's behalf. At the moment, if we are setting a child prop
      // on an object or array, we don't know the fully qualified name string
      // to pass to PHP though, since we only have a reference to the container.
      throw DebuggerCommandException(
        "Failed to set object value. Please use the console to set the value "
        "of complex objects."
      );

    default:
      throw DebuggerCommandException("Unexpected variable type");
  }

  Variant variable = tvAsVariant(typedVariable);
  *result = VariablesCommand::serializeVariable(
              session,
              requestId,
              name,
              variable
            );
}
Ejemplo n.º 4
0
void parse_xdg(const char *file, cb_add_menu_entry *addWMMenuEntryCallback)
{
	FILE *fp;
	char buf[1024];
	char *p, *tmp, *key;
	WMMenuEntry *wm;
	XDGMenuEntry *xdg;
	int InGroup;

	fp = fopen(file, "r");
	if (!fp) {
#if DEBUG
		fprintf(stderr, "Error opening file %s: %s\n", file, strerror(errno));
#endif
		return;
	}

	xdg = (XDGMenuEntry *)wmalloc(sizeof(XDGMenuEntry));
	wm = (WMMenuEntry *)wmalloc(sizeof(WMMenuEntry));
	InGroup = 0;
	memset(buf, 0, sizeof(buf));

	while (fgets(buf, sizeof(buf), fp)) {

		p = buf;

		/* skip whitespaces */
		while (isspace(*p))
			p++;
		/* skip comments, empty lines */
		if (*p == '\r' || *p == '\n' || *p == '#') {
			memset(buf, 0, sizeof(buf));
			continue;
		}
		/* trim crlf */
		buf[strcspn(buf, "\r\n")] = '\0';
		if (strlen(buf) == 0)
			continue;

		if (strcmp(p, "[Desktop Entry]") == 0) {
			/* if currently processing a group, we've just hit the
			 * end of its definition, try processing it
			 */
			if (InGroup && xdg_to_wm(&xdg, &wm)) {
				(*addWMMenuEntryCallback)(wm);
			}
			init_xdg_storage(&xdg);
			init_wm_storage(&wm);
			InGroup = 1;
			/* start processing group */
			memset(buf, 0, sizeof(buf));
			continue;
		}

		if (!InGroup) {
			memset(buf, 0, sizeof(buf));
			continue;
		}

		getKey(&key, p);
		if (key == NULL) { /* not `key' = `value' */
			memset(buf, 0, sizeof(buf));
			continue;
		}

		if (strcmp(key, "Type") == 0) {
			getStringValue(&tmp, p);
			if (strcmp(tmp, "Application") != 0)
				InGroup = 0;	/* if not application, skip current group */
			wfree(tmp);
			tmp = NULL;
		} else if (strcmp(key, "Name") == 0) {
			getLocalizedStringValue(&xdg->Name, p, &xdg->MatchLevel);
		} else if (strcmp(key, "NoDisplay") == 0) {
			if (getBooleanValue(p))	/* if nodisplay, skip current group */
				InGroup = 0;
		} else if (strcmp(key, "Hidden") == 0) {
			if (getBooleanValue(p))
				InGroup = 0;	/* if hidden, skip current group */
		} else if (strcmp(key, "TryExec") == 0) {
			getStringValue(&xdg->TryExec, p);
		} else if (strcmp(key, "Exec") == 0) {
			getStringValue(&xdg->Exec, p);
		} else if (strcmp(key, "Path") == 0) {
			getStringValue(&xdg->Path, p);
		} else if (strcmp(key, "Terminal") == 0) {
			if (getBooleanValue(p))
				xdg->Flags |= F_TERMINAL;
		} else if (strcmp(key, "Categories") == 0) {
			getStringValue(&xdg->Category, p);
			getMenuHierarchyFor(&xdg->Category);
		}

		wfree(key);
		key = NULL;
	}

	fclose(fp);

	/* at the end of the file, might as well try to menuize what we have
	 * unless there was no group at all or it was marked as hidden
	 */
	if (InGroup && xdg_to_wm(&xdg, &wm))
		(*addWMMenuEntryCallback)(wm);

}