ReXGlue SDK
Loading...
Searching...
No Matches
module.h File Reference

Interfaces, factory and module declaration. More...

#include <array>
#include <cstddef>
#include <span>
#include <string_view>
#include <type_traits>
#include <vector>
#include <rex/platform.h>
#include <rex/result.h>
#include <rex/types.h>
#include <rex/utility.h>
#include <rex/version.h>

Go to the source code of this file.

Classes

struct  rex::InterfaceType
class  rex::IInterface
class  rex::IInterfaceFactory
class  rex::IModule
class  rex::AppInterfaces

Namespaces

namespace  rex

Macros

#define REX_DECLARE_INTERFACE(Name, version)
#define REX_DECLARE_PRIVATE_INTERFACE(Name, version)
#define REX_INTERFACE(T)
#define REX_MODULE_SERVES(...)
#define REX_DECLARE_MODULE(ModuleClass)

Typedefs

using rex::CreateInterfaceFn = IInterface* (*)(const char* name, u32 version)
using rex::EnumerateInterfacesFn = u32 (*)(InterfaceType* out, u32 capacity)

Functions

template<typename... Interfaces, typename Module>
IInterface * rex::FindModuleInterface (Module &module, std::string_view name, u32 version)

Variables

constexpr const char * rex::kCreateInterfaceSymbol = "ReXCreateInterface"
constexpr const char * rex::kEnumerateInterfacesSymbol = "ReXEnumerateInterfaces"
constexpr const char * rex::kBuildIdentitySymbol = "ReXBuildIdentity"

Detailed Description

Interfaces, factory and module declaration.

License
BSD 3-Clause License See LICENSE file in the project root for full license text.

Macro Definition Documentation

◆ REX_DECLARE_INTERFACE

#define REX_DECLARE_INTERFACE ( Name,
version )
Value:
class REX_DETAIL_ID(Name) : public ::rex::IInterface { \
public: \
static constexpr ::rex::InterfaceType kInterface{::rex::detail::kTypeName<Name>, version};
Definition module.h:86

Opens an interface class that derives from IInterface and carries its identity as kInterface. The name is the qualified type name the compiler gives, so declare the class in a named namespace. The class body, the closing brace and the semicolon follow the macro.

Parameters
versionThe version of the interface layout.
namespace rex::example {
virtual int GetValue() const = 0;
};
} // namespace rex::example
#define REX_DECLARE_INTERFACE(Name, version)
Definition module.h:114

◆ REX_DECLARE_MODULE

#define REX_DECLARE_MODULE ( ModuleClass)
Value:
namespace { \
using ReXModuleType = ModuleClass; \
ReXModuleType& ReXModuleInstance() { \
static ModuleClass instance; \
return instance; \
} \
} \
extern "C" REX_DETAIL_EXPORT const char* ReXBuildIdentity() { \
return REXGLUE_BUILD_IDENTITY; \
} \
extern "C" REX_DETAIL_EXPORT ::rex::IInterface* ReXCreateInterface(const char* name, \
::rex::u32 version) { \
return ::rex::detail::CreateModuleInterface<ModuleClass>(ReXModuleInstance(), name, version); \
} \
extern "C" REX_DETAIL_EXPORT ::rex::u32 ReXEnumerateInterfaces(::rex::InterfaceType* out, \
::rex::u32 capacity) { \
return ::rex::detail::EnumerateModuleInterfaces(ReXModuleInstance(), out, capacity); \
}
const char * ReXBuildIdentity()
rex::u32 ReXEnumerateInterfaces(rex::InterfaceType *out, rex::u32 capacity)
rex::IInterface * ReXCreateInterface(const char *name, rex::u32 version)

Exports the module identity and its interfaces. Use once per module.

#define REX_DECLARE_MODULE(ModuleClass)
Definition module.h:366
Parameters
ModuleClassA class deriving from IModule, with a default constructor. One instance exists as long as the library.

◆ REX_DECLARE_PRIVATE_INTERFACE

#define REX_DECLARE_PRIVATE_INTERFACE ( Name,
version )
Value:
class REX_DETAIL_ID(Name) : public ::rex::IInterface { \
public: \
static constexpr ::rex::InterfaceType kInterface{::rex::detail::kTypeName<Name>, version, true};

Opens an interface like REX_DECLARE_INTERFACE that only the app and the kernel can reach. The public factory and AppInterfaces::Get never return it.

Parameters
versionThe version of the interface layout.

◆ REX_INTERFACE

#define REX_INTERFACE ( T)
Value:
static T * Get()
Definition module.h:266

◆ REX_MODULE_SERVES

#define REX_MODULE_SERVES ( ...)
Value:
::std::span<const ::rex::InterfaceType> GetServedInterfaces() const override { \
return ::rex::detail::ServedTypeList<__VA_ARGS__>::kList; \
}

Declares the interfaces a module class serves besides IModule. Use once in a public section of the class body.

class MyModule final : public rex::IModule {
public:
REX_MODULE_SERVES(IMyService)
};
Definition module.h:177
#define REX_MODULE_SERVES(...)
Definition module.h:351
Parameters
...The interfaces, each declared with REX_DECLARE_INTERFACE or REX_DECLARE_PRIVATE_INTERFACE.