Skip to content

Commit 65379fc

Browse files
authored
Merge pull request #163 from CerebusOSS/159-fix-getters-in-central-compat
Fix getters using Central
2 parents 7f63f3a + 2b126c3 commit 65379fc

1 file changed

Lines changed: 46 additions & 9 deletions

File tree

src/cbsdk/src/sdk_session.cpp

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,7 @@ struct SdkSession::Impl {
143143

144144
void rebuildChannelTypeCache() {
145145
for (uint32_t ch = 0; ch < cbMAXCHANS; ++ch) {
146-
const cbPKT_CHANINFO* ci = nullptr;
147-
if (device_session) {
148-
ci = device_session->getChanInfo(ch + 1);
149-
} else if (shmem_session) {
150-
const auto* native = shmem_session->getNativeConfigBuffer();
151-
if (native) ci = &native->chaninfo[ch];
152-
}
146+
const auto* ci = getChanInfoPtr(ch);
153147
channel_type_cache[ch] = ci ? classifyChannelByCaps(*ci) : ChannelType::ANY;
154148
}
155149
channel_cache_valid = true;
@@ -1115,6 +1109,9 @@ const cbPKT_SYSINFO* SdkSession::getSysInfo() const {
11151109
const auto* native = m_impl->shmem_session->getNativeConfigBuffer();
11161110
if (native)
11171111
return &native->sysinfo;
1112+
const auto* legacy = m_impl->shmem_session->getLegacyConfigBuffer();
1113+
if (legacy)
1114+
return &legacy->sysinfo;
11181115
}
11191116
return nullptr;
11201117
}
@@ -1126,6 +1123,9 @@ const cbPKT_CHANINFO* SdkSession::getChanInfo(const uint32_t chan_id) const {
11261123
const auto* native = m_impl->shmem_session->getNativeConfigBuffer();
11271124
if (native)
11281125
return &native->chaninfo[chan_id - 1];
1126+
const auto* legacy = m_impl->shmem_session->getLegacyConfigBuffer();
1127+
if (legacy)
1128+
return &legacy->chaninfo[chan_id - 1];
11291129
}
11301130
return nullptr;
11311131
}
@@ -1141,6 +1141,12 @@ const cbPKT_GROUPINFO* SdkSession::getGroupInfo(uint32_t group_id) const {
11411141
const auto* native = m_impl->shmem_session->getNativeConfigBuffer();
11421142
if (native)
11431143
return &native->groupinfo[group_id - 1];
1144+
const auto* legacy = m_impl->shmem_session->getLegacyConfigBuffer();
1145+
if (legacy) {
1146+
int32_t inst = getCentralInstrumentIndex(m_impl->config.device_type);
1147+
if (inst >= 0)
1148+
return &legacy->groupinfo[inst][group_id - 1];
1149+
}
11441150
}
11451151
return nullptr;
11461152
}
@@ -1156,6 +1162,12 @@ const cbPKT_FILTINFO* SdkSession::getFilterInfo(const uint32_t filter_id) const
11561162
const auto* native = m_impl->shmem_session->getNativeConfigBuffer();
11571163
if (native)
11581164
return &native->filtinfo[filter_id];
1165+
const auto* legacy = m_impl->shmem_session->getLegacyConfigBuffer();
1166+
if (legacy) {
1167+
int32_t inst = getCentralInstrumentIndex(m_impl->config.device_type);
1168+
if (inst >= 0)
1169+
return &legacy->filtinfo[inst][filter_id];
1170+
}
11591171
}
11601172
return nullptr;
11611173
}
@@ -1167,16 +1179,39 @@ uint32_t SdkSession::getRunLevel() const {
11671179
uint32_t SdkSession::getProtocolVersion() const {
11681180
if (m_impl->device_session)
11691181
return static_cast<uint32_t>(m_impl->device_session->getProtocolVersion());
1170-
return 0; // CLIENT mode — no protocol version available
1182+
if (m_impl->shmem_session) {
1183+
const auto* native = m_impl->shmem_session->getNativeConfigBuffer();
1184+
if (native)
1185+
return native->version;
1186+
const auto* legacy = m_impl->shmem_session->getLegacyConfigBuffer();
1187+
if (legacy) {
1188+
int32_t inst = getCentralInstrumentIndex(m_impl->config.device_type);
1189+
if (inst >= 0)
1190+
return legacy->procinfo[inst].version;
1191+
}
1192+
}
1193+
return 0;
11711194
}
11721195

11731196
std::string SdkSession::getProcIdent() const {
11741197
if (m_impl->device_session) {
11751198
const auto& config = m_impl->device_session->getDeviceConfig();
1176-
// ident is a fixed-size char array, may not be null-terminated
11771199
return std::string(config.procinfo.ident,
11781200
strnlen(config.procinfo.ident, sizeof(config.procinfo.ident)));
11791201
}
1202+
if (m_impl->shmem_session) {
1203+
const auto* native = m_impl->shmem_session->getNativeConfigBuffer();
1204+
if (native)
1205+
return std::string(native->procinfo.ident,
1206+
strnlen(native->procinfo.ident, sizeof(native->procinfo.ident)));
1207+
const auto* legacy = m_impl->shmem_session->getLegacyConfigBuffer();
1208+
if (legacy) {
1209+
int32_t inst = getCentralInstrumentIndex(m_impl->config.device_type);
1210+
if (inst >= 0)
1211+
return std::string(legacy->procinfo[inst].ident,
1212+
strnlen(legacy->procinfo[inst].ident, sizeof(legacy->procinfo[inst].ident)));
1213+
}
1214+
}
11801215
return {};
11811216
}
11821217

@@ -1238,6 +1273,8 @@ const cbPKT_CHANINFO* SdkSession::Impl::getChanInfoPtr(uint32_t idx) const {
12381273
} else if (shmem_session) {
12391274
const auto* native = shmem_session->getNativeConfigBuffer();
12401275
if (native) return &native->chaninfo[idx];
1276+
const auto* legacy = shmem_session->getLegacyConfigBuffer();
1277+
if (legacy) return &legacy->chaninfo[idx];
12411278
}
12421279
return nullptr;
12431280
}

0 commit comments

Comments
 (0)