mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[sim] Add API for extensions to discover each other (#2681)
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "hal/Extensions.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/Path.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/StringRef.h>
|
||||
@@ -37,6 +39,10 @@
|
||||
#define DLERROR dlerror()
|
||||
#endif
|
||||
|
||||
static std::vector<std::pair<const char*, void*>> gExtensionRegistry;
|
||||
static std::vector<std::pair<void*, void (*)(void*, const char*, void*)>>
|
||||
gExtensionListeners;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeExtensions() {}
|
||||
@@ -116,6 +122,20 @@ int HAL_LoadExtensions(void) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
void HAL_RegisterExtension(const char* name, void* data) {
|
||||
gExtensionRegistry.emplace_back(name, data);
|
||||
for (auto&& listener : gExtensionListeners)
|
||||
listener.second(listener.first, name, data);
|
||||
}
|
||||
|
||||
void HAL_RegisterExtensionListener(void* param,
|
||||
void (*func)(void*, const char* name,
|
||||
void* data)) {
|
||||
gExtensionListeners.emplace_back(param, func);
|
||||
for (auto&& extension : gExtensionRegistry)
|
||||
func(param, extension.first, extension.second);
|
||||
}
|
||||
|
||||
void HAL_SetShowExtensionsNotFoundMessages(HAL_Bool showMessage) {
|
||||
GetShowNotFoundMessage() = showMessage;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user