[sim] Add API for extensions to discover each other (#2681)

This commit is contained in:
Peter Johnson
2020-09-03 10:09:01 -07:00
committed by GitHub
parent 1593eb4d47
commit de0277713b
2 changed files with 46 additions and 1 deletions

View File

@@ -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;
}