/*
 * Set the priority of a set of ports
 */
void OlaServerServiceImpl::SetPortPriority(
    RpcController* controller,
    const ola::proto::PortPriorityRequest* request,
    Ack*,
    ola::rpc::RpcService::CompletionCallback* done) {
  ClosureRunner runner(done);
  AbstractDevice *device =
    m_device_manager->GetDevice(request->device_alias());

  if (!device)
    return MissingDeviceError(controller);

  bool status;

  bool inherit_mode = true;
  uint8_t value = 0;
  if (request->priority_mode() == PRIORITY_MODE_STATIC) {
    if (request->has_priority()) {
      inherit_mode = false;
      value = request->priority();
    } else {
      OLA_INFO << "In Set Port Priority, override mode was set but the value "
        "wasn't specified";
      controller->SetFailed(
          "Invalid SetPortPriority request, see logs for more info");
      return;
    }
  }

  if (request->is_output()) {
    OutputPort *port = device->GetOutputPort(request->port_id());
    if (!port)
      return MissingPortError(controller);

    if (inherit_mode)
      status = m_port_manager->SetPriorityInherit(port);
    else
      status = m_port_manager->SetPriorityStatic(port, value);
  } else {
    InputPort *port = device->GetInputPort(request->port_id());
    if (!port)
      return MissingPortError(controller);

    if (inherit_mode)
      status = m_port_manager->SetPriorityInherit(port);
    else
      status = m_port_manager->SetPriorityStatic(port, value);
  }

  if (!status)
    controller->SetFailed(
        "Invalid SetPortPriority request, see logs for more info");
}
Exemple #2
0
/*
 * Check for loops.
 */
bool ShowNetOutputPort::PreSetUniverse(Universe *old_universe,
                                       Universe *new_universe) {
  (void) old_universe;
  (void) new_universe;
  AbstractDevice *device = GetDevice();
  InputPort *input_port = device->GetInputPort(PortId());
  if (input_port && input_port->GetUniverse()) {
    OLA_WARN << "Avoiding possible shownet loop on " << Description();
    return false;
  }
  return true;
}
/*
 * Patch a port to a universe
 */
void OlaServerServiceImpl::PatchPort(
    RpcController* controller,
    const PatchPortRequest* request,
    Ack*,
    ola::rpc::RpcService::CompletionCallback* done) {
  ClosureRunner runner(done);
  AbstractDevice *device =
    m_device_manager->GetDevice(request->device_alias());

  if (!device)
    return MissingDeviceError(controller);

  bool result;
  if (request->is_output()) {
    OutputPort *port = device->GetOutputPort(request->port_id());
    if (!port)
      return MissingPortError(controller);

    if (request->action() == ola::proto::PATCH)
      result = m_port_manager->PatchPort(port, request->universe());
    else
      result = m_port_manager->UnPatchPort(port);
  } else {
    InputPort *port = device->GetInputPort(request->port_id());
    if (!port)
      return MissingPortError(controller);

    if (request->action() == ola::proto::PATCH)
      result = m_port_manager->PatchPort(port, request->universe());
    else
      result = m_port_manager->UnPatchPort(port);
  }

  if (!result)
    controller->SetFailed("Patch port request failed");
}