Ejemplo n.º 1
0
/**
 * Add the json representation of this port to the stringstream
 */
string OlaHttpServer::PortToJson(const OlaDevice &device,
                                 const OlaPort &port,
                                 bool is_output) {
    stringstream str;
    str << "    {" << endl;
    str << "      \"device\": \"" << EscapeString(device.Name())
        << "\"," << endl;
    str << "      \"description\": \"" <<
        EscapeString(port.Description()) << "\"," << endl;
    str << "      \"id\": \"" << device.Alias() << "-" <<
        (is_output ? "O" : "I") << "-" << port.Id() << "\"," << endl;
    str << "      \"is_output\": " << (is_output ? "true" : "false") << "," <<
        endl;

    if (port.PriorityCapability() != CAPABILITY_NONE) {
        str << "      \"priority\": {" << endl;
        str << "        \"value\": " << static_cast<int>(port.Priority()) <<
            "," << endl;
        if (port.PriorityCapability() == CAPABILITY_FULL) {
            str << "        \"current_mode\": \"" <<
                (port.PriorityMode() == PRIORITY_MODE_INHERIT ?
                 "inherit" : "override") << "\"," <<
                endl;
        }
        str << "      }" << endl;
    }
    str << "    }";
    return str.str();
}
Ejemplo n.º 2
0
/**
 * @brief Add the json representation of this port to the ostringstream
 */
void OladHTTPServer::PortToJson(JsonObject *json,
                                const OlaDevice &device,
                                const OlaPort &port,
                                bool is_output) {
  ostringstream str;
  str << device.Alias() << "-" << (is_output ? "O" : "I") << "-" << port.Id();

  json->Add("device", device.Name());
  json->Add("description", port.Description());
  json->Add("id", str.str());
  json->Add("is_output", is_output);

  JsonObject *priority_json = json->AddObject("priority");
  if (port.PriorityCapability() != CAPABILITY_NONE) {
    // This can be used as the default value for the priority input and because
    // inherit ports can return a 0 priority we shall set it to the default
    // here
    uint8_t priority = port.Priority();
    if (priority == 0) {
      // We check here because 0 is an invalid priority outside of Olad
      priority = dmx::SOURCE_PRIORITY_DEFAULT;
    }
    priority_json->Add("value", static_cast<int>(priority));
    priority_json->Add(
      "current_mode",
      (port.PriorityMode() == PRIORITY_MODE_INHERIT ?  "inherit" : "static"));
    priority_json->Add("priority_capability",
      (port.PriorityCapability() == CAPABILITY_STATIC ? "static" : "full"));
  }
}
Ejemplo n.º 3
0
/**
 * Add the json representation of this port to the stringstream
 */
void OladHTTPServer::PortToJson(JsonObject *json,
                               const OlaDevice &device,
                               const OlaPort &port,
                               bool is_output) {
  stringstream str;
  str << device.Alias() << "-" << (is_output ? "O" : "I") << "-" << port.Id();

  json->Add("device", device.Name());
  json->Add("description", port.Description());
  json->Add("id", str.str());
  json->Add("is_output", is_output);

  if (port.PriorityCapability() != CAPABILITY_NONE) {
    JsonObject *priority_json = json->AddObject("priority");
    priority_json->Add("value", static_cast<int>(port.Priority()));
    priority_json->Add(
      "current_mode",
      (port.PriorityMode() == PRIORITY_MODE_INHERIT ?  "inherit" : "override"));
  }
}