Files
allwpilib/simulation/halsim_lowfi/src/main/native/cpp/HALSimLowFi.cpp
Peter Johnson f84018af5f Move entirety of llvm namespace to wpi namespace.
During shared library loading, a different libLLVM can be pulled in, causing
llvm symbols from dependent libraries to resolve to that library instead of
this one. This has been seen in the wild with the Mesa OpenGL implementation
in JavaFX applications (see wpilibsuite/shuffleboard#361).

This is clearly a very breaking change. For some level of backwards
compatibility, a namespace alias from llvm to wpi is performed in the "llvm"
headers.  Unfortunately, forward declarations of llvm classes will still break,
but compilers seem to generate clear error messages in those cases
("namespace alias 'llvm' not allowed here, assuming 'wpi'").

This change also moves all the wpiutil headers to a single "wpi" subdirectory
from the previously split "llvm", "support", "tcpsockets", and "udpsockets".
Shim headers will be added for backwards compatibility in a later commit.
2018-04-30 10:22:54 -07:00

63 lines
2.1 KiB
C++

/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "HALSimLowFi.h"
#include <wpi/Twine.h>
void HALSimLowFi::Initialize() {
table = nt::NetworkTableInstance::GetDefault().GetTable("sim");
}
void HALSimNTProvider::Inject(std::shared_ptr<HALSimLowFi> parentArg,
std::string tableNameArg) {
parent = parentArg;
tableName = std::move(tableNameArg);
table = parent->table->GetSubTable(tableName);
this->Initialize();
}
void NTProviderBaseCallback(const char* name, void* param,
const struct HAL_Value* value) {
auto info =
static_cast<struct HALSimNTProvider::NTProviderCallbackInfo*>(param);
uint32_t chan = static_cast<uint32_t>(info->channel);
auto provider = info->provider;
auto table = info->table;
provider->OnCallback(chan, table);
}
void HALSimNTProvider::InitializeDefault(
int numChannels, HALCbRegisterIndexedFunc registerFunc) {
this->numChannels = numChannels;
cbInfos.reserve(numChannels);
for (int i = 0; i < numChannels; i++) {
struct NTProviderCallbackInfo info = {
this, table->GetSubTable(tableName + wpi::Twine(i)), i};
cbInfos.emplace_back(info);
}
for (auto& info : cbInfos) {
registerFunc(info.channel, NTProviderBaseCallback, &info, true);
OnInitializedChannel(info.channel, info.table);
}
}
void HALSimNTProvider::InitializeDefaultSingle(
HALCbRegisterSingleFunc registerFunc) {
struct NTProviderCallbackInfo info = {this, table, 0};
cbInfos.push_back(info);
for (auto& info : cbInfos) {
registerFunc(NTProviderBaseCallback, &info, true);
}
}
void HALSimNTProvider::OnInitializedChannel(
uint32_t channel, std::shared_ptr<nt::NetworkTable> table) {}