Skip to content

EntropyCanvas::Schema::ComponentSchemaRegistry

EntropyCanvas::Schema::ComponentSchemaRegistry

Section titled “EntropyCanvas::Schema::ComponentSchemaRegistry”

Thread-safe registry for component schemas. More…

#include <ComponentSchemaRegistry.h>

Name
using std::function< void(ComponentTypeHash typeHash)>SchemaUnpublishedCallback
Callback invoked when a schema is unpublished (made private).
using std::function< void(ComponentSchemaRegistry &)>SchemaRegistrationCallback
Callback for auto-registration during construction.
using std::function< void(ComponentTypeHash typeHash, const ComponentSchema &schema)>SchemaPublishedCallback
Callback invoked when a schema is published (made public).
Name
~ComponentSchemaRegistry() =default
Result< void >validateDetailedCompatibility(ComponentTypeHash source, ComponentTypeHash target) const
Validate detailed compatibility.
Result< void >unpublishSchema(ComponentTypeHash typeHash)
Unpublish a public schema.
voidsetSchemaUnpublishedCallback(SchemaUnpublishedCallback callback)
Set callback for schema unpublish events.
voidsetSchemaPublishedCallback(SchemaPublishedCallback callback)
Set callback for schema publish events.
size_tschemaCount() const
Get total schema count.
Result< ComponentTypeHash >registerSchema(const ComponentSchema & schema)
Register a component schema.
Result< void >publishSchema(ComponentTypeHash typeHash)
Publish a private schema.
size_tpublicSchemaCount() const
Get public schema count.
ComponentSchemaRegistry &operator=(const ComponentSchemaRegistry & ) =delete
ComponentSchemaRegistry &operator=(ComponentSchemaRegistry && ) =delete
boolisRegistered(ComponentTypeHash typeHash) const
Check if schema is registered.
boolisPublic(ComponentTypeHash typeHash) const
Check if schema is public.
voidgetStats(size_t & totalCount, size_t & publicCount, std::vector< ComponentSchema > & publicSchemas) const
Get consistent snapshot of registry stats.
std::optional< ComponentSchema >getSchema(ComponentTypeHash typeHash) const
Lookup schema by type hash.
std::vector< ComponentSchema >getPublicSchemas() const
Get all public schemas.
std::vector< ComponentTypeHash >findCompatibleSchemas(ComponentTypeHash typeHash) const
Find schemas compatible with given type hash.
boolareCompatible(ComponentTypeHash a, ComponentTypeHash b) const
Check if two schemas are structurally compatible.
ComponentSchemaRegistry() =default
ComponentSchemaRegistry(SchemaRegistrationCallback initCallback)
Construct with auto-registration callback.
ComponentSchemaRegistry(const ComponentSchemaRegistry & ) =delete
ComponentSchemaRegistry(ComponentSchemaRegistry && ) =delete
class EntropyCanvas::Schema::ComponentSchemaRegistry;

Thread-safe registry for component schemas.

Provides opt-in schema discovery and compatibility validation. Applications can:

  • Register schemas (public or private)
  • Query schemas by hash
  • Find compatible schemas
  • Validate compatibility

Default behavior: Schemas are private unless explicitly published.

Thread Safety:

  • All operations are thread-safe using shared_mutex
  • Multiple concurrent readers, single writer
  • Pre-lock validation for performance

Memory Efficiency:

  • Single registry instance per server
  • Structural hash indexing for fast compatibility queries
  • Public/private schema separation
using EntropyEngine::Networking::ComponentSchemaRegistry::SchemaUnpublishedCallback = std::function<void(ComponentTypeHash typeHash)>;

Callback invoked when a schema is unpublished (made private).

using EntropyEngine::Networking::ComponentSchemaRegistry::SchemaRegistrationCallback = std::function<void(ComponentSchemaRegistry&)>;

Callback for auto-registration during construction.

using EntropyEngine::Networking::ComponentSchemaRegistry::SchemaPublishedCallback = std::function<void(ComponentTypeHash typeHash, const ComponentSchema& schema)>;

Callback invoked when a schema is published (made public).

~ComponentSchemaRegistry() =default
Result< void > validateDetailedCompatibility(
ComponentTypeHash source,
ComponentTypeHash target
) const

Validate detailed compatibility.

Parameters:

  • source Source schema
  • target Target schema

Return: Result with detailed error messages if incompatible

Performs field-by-field validation. More expensive than structural hash check. Application decides what to do with the result.

@threadsafety Thread-safe (read lock)

Result< void > unpublishSchema(
ComponentTypeHash typeHash
)

Unpublish a public schema.

Parameters:

  • typeHash Component type hash

Return: Result indicating success or error

Makes a public schema private (no longer discoverable).

@threadsafety Thread-safe (write lock)

void setSchemaUnpublishedCallback(
SchemaUnpublishedCallback callback
)

Set callback for schema unpublish events.

Parameters:

  • callback Function to call on unpublish (invoked under lock)

Called when unpublishSchema() makes a public schema private. Useful for notifying clients that schema is no longer available.

@threadsafety Not thread-safe - set before unpublishing schemas

void setSchemaPublishedCallback(
SchemaPublishedCallback callback
)

Set callback for schema publish events.

Parameters:

  • callback Function to call on publish (invoked under lock)

Called when publishSchema() makes a private schema public. Useful for broadcasting schema availability to connected clients.

@threadsafety Not thread-safe - set before publishing schemas

size_t schemaCount() const

Get total schema count.

Return: Number of registered schemas (public + private)

@threadsafety Thread-safe (read lock)

Result< ComponentTypeHash > registerSchema(
const ComponentSchema & schema
)

Register a component schema.

Parameters:

  • schema Component schema to register

Return: Result with ComponentTypeHash on success

Schemas are private by default unless isPublic=true. Re-registering the same schema (same typeHash) is idempotent.

@threadsafety Thread-safe (write lock)

ComponentSchemaRegistry registry;
auto schema = ComponentSchema::create("App", "Transform", 1, properties, 40, false);
if (schema.success()) {
auto result = registry.registerSchema(schema.value());
if (result.success()) {
ENTROPY_LOG_INFO("Registered schema: {}", toString(result.value()));
}
}
Result< void > publishSchema(
ComponentTypeHash typeHash
)

Publish a private schema.

Parameters:

  • typeHash Component type hash

Return: Result indicating success or error

Makes a previously private schema public for discovery.

@threadsafety Thread-safe (write lock)

size_t publicSchemaCount() const

Get public schema count.

Return: Number of public schemas

@threadsafety Thread-safe (read lock)

ComponentSchemaRegistry & operator=(
const ComponentSchemaRegistry &
) =delete
ComponentSchemaRegistry & operator=(
ComponentSchemaRegistry &&
) =delete
bool isRegistered(
ComponentTypeHash typeHash
) const

Check if schema is registered.

Parameters:

  • typeHash Component type hash

Return: true if registered (public or private)

@threadsafety Thread-safe (read lock)

bool isPublic(
ComponentTypeHash typeHash
) const

Check if schema is public.

Parameters:

  • typeHash Component type hash

Return: true if schema is published for discovery

@threadsafety Thread-safe (read lock)

void getStats(
size_t & totalCount,
size_t & publicCount,
std::vector< ComponentSchema > & publicSchemas
) const

Get consistent snapshot of registry stats.

Parameters:

  • totalCount Total number of schemas
  • publicCount Number of public schemas
  • publicSchemas Vector of public schemas

Returns all stats under a single lock to ensure consistency. Useful for concurrent readers that need consistent view of state.

@threadsafety Thread-safe (read lock)

std::optional< ComponentSchema > getSchema(
ComponentTypeHash typeHash
) const

Lookup schema by type hash.

Parameters:

  • typeHash Component type hash

Return: Optional schema if found

Returns schema if registered (public or private).

@threadsafety Thread-safe (read lock)

std::vector< ComponentSchema > getPublicSchemas() const

Get all public schemas.

Return: Vector of public schemas

Returns only schemas marked as public. Used for schema discovery by other applications.

@threadsafety Thread-safe (read lock)

std::vector< ComponentTypeHash > findCompatibleSchemas(
ComponentTypeHash typeHash
) const

Find schemas compatible with given type hash.

Parameters:

  • typeHash Component type hash to match

Return: Vector of compatible component type hashes

Returns all public schemas that are structurally compatible (matching structural hash).

@threadsafety Thread-safe (read lock)

bool areCompatible(
ComponentTypeHash a,
ComponentTypeHash b
) const

Check if two schemas are structurally compatible.

Parameters:

  • a First component type hash
  • b Second component type hash

Return: true if structurally compatible

Fast check using structural hash comparison.

@threadsafety Thread-safe (read lock)

ComponentSchemaRegistry() =default
explicit ComponentSchemaRegistry(
SchemaRegistrationCallback initCallback
)

Construct with auto-registration callback.

Parameters:

  • initCallback Function called during construction to register schemas

Allows registering schemas during construction, e.g., for built-in schemas.

ComponentSchemaRegistry registry([](ComponentSchemaRegistry& reg) {
EntropyCanvas::Schema::registerBuiltinSchemas(reg);
});
ComponentSchemaRegistry(
const ComponentSchemaRegistry &
) =delete
ComponentSchemaRegistry(
ComponentSchemaRegistry &&
) =delete

Updated on 2026-01-26 at 17:14:35 -0500