at::Type& getType(at::ScalarType scalarType, const THPLayout& layout, const at::Device& device) { const at::Backend backend = get_backend(device.type() == at::Device::Type::CUDA, layout.layout == at::Layout::Sparse); auto baseType = at::globalContext().getTypeOpt(backend, scalarType); if (!baseType) { std::ostringstream oss; oss << "Error attempting to use dtype " << getDtype(scalarType)->name << " with layout " << layout.name << " and device type " << device.type() << "."; if (device.type() == at::Device::Type::CUDA && !torch::utils::cuda_enabled()) { oss << " Torch not compiled with CUDA enabled." << std::endl; } throw std::runtime_error(oss.str()); } return *torch::autograd::VariableType::getType(*baseType); }
// find first range finder instance with the specified orientation AP_RangeFinder_Backend *RangeFinder::find_instance(enum Rotation orientation) const { for (uint8_t i=0; i<num_instances; i++) { AP_RangeFinder_Backend *backend = get_backend(i); if (backend == nullptr) { continue; } if (backend->orientation() != orientation) { continue; } return backend; } return nullptr; }
SWITCH_DECLARE(char *) switch_limit_status(const char *backend) { switch_limit_interface_t *limit = NULL; char *status = NULL; /* locate impl, call appropriate func */ if (!(limit = get_backend(backend))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Limit subsystem %s not found!\n", backend); switch_goto_status(strdup("-ERR"), end); } status = limit->status(); end: release_backend(limit); return status; }
SWITCH_DECLARE(switch_status_t) switch_limit_reset(const char *backend) { switch_limit_interface_t *limit = NULL; int status = SWITCH_STATUS_SUCCESS; /* locate impl, call appropriate func */ if (!(limit = get_backend(backend))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Limit subsystem %s not found!\n", backend); switch_goto_status(SWITCH_STATUS_GENERR, end); } status = limit->reset(); end: release_backend(limit); return status; }
SWITCH_DECLARE(int) switch_limit_usage(const char *backend, const char *realm, const char *resource, uint32_t *rcount) { switch_limit_interface_t *limit = NULL; int usage = 0; /* locate impl, call appropriate func */ if (!(limit = get_backend(backend))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Limit subsystem %s not found!\n", backend); goto end; } usage = limit->usage(realm, resource, rcount); end: release_backend(limit); return usage; }
SWITCH_DECLARE(switch_status_t) switch_limit_release(const char *backend, switch_core_session_t *session, const char *realm, const char *resource) { switch_limit_interface_t *limit = NULL; int status = SWITCH_STATUS_SUCCESS; /* locate impl, call appropriate func */ if (!(limit = get_backend(backend))) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Limit subsystem %s not found!\n", backend); switch_goto_status(SWITCH_STATUS_GENERR, end); } status = limit->release(session, realm, resource); end: release_backend(limit); return status; }
SWITCH_DECLARE(switch_status_t) switch_limit_incr(const char *backend, switch_core_session_t *session, const char *realm, const char *resource, const int max, const int interval) { switch_limit_interface_t *limit = NULL; switch_channel_t *channel = NULL; int status = SWITCH_STATUS_SUCCESS; if (session) { channel = switch_core_session_get_channel(session); } /* locate impl, call appropriate func */ if (!(limit = get_backend(backend))) { switch_limit_log(session, SWITCH_LOG_ERROR, "Limit subsystem %s not found!\n", backend); switch_goto_status(SWITCH_STATUS_GENERR, end); } switch_limit_log(session, SWITCH_LOG_INFO, "incr called: %s_%s max:%d, interval:%d\n", realm, resource, max, interval); if ((status = limit->incr(session, realm, resource, max, interval)) == SWITCH_STATUS_SUCCESS) { if (session) { /* race condition? what if another leg is doing the same thing? */ const char *existing = switch_channel_get_variable(channel, LIMIT_BACKEND_VARIABLE); if (existing) { if (!strstr(existing, backend)) { switch_channel_set_variable_printf(channel, LIMIT_BACKEND_VARIABLE, "%s,%s", existing, backend); } } else { switch_channel_set_variable(channel, LIMIT_BACKEND_VARIABLE, backend); switch_core_event_hook_add_state_change(session, limit_state_handler); } } } release_backend(limit); end: return status; }