Core Services
Feature: Core Services
Section titled “Feature: Core Services”EntropyCore provides foundational services for application lifecycle and communication.
Service Registry (EntropyServiceRegistry)
Section titled “Service Registry (EntropyServiceRegistry)”The central orchestrator for pluggable subsystems. It manages the lifecycle and dependencies of all registered services.
Lifecycle
Section titled “Lifecycle”Services transition through specific states, orchestrated by the registry:
stateDiagram-v2
[*] --> Registered
Registered --> Loaded: load()
Loaded --> Started: start()
Started --> Stopped: stop()
Stopped --> Unloaded: unload()
Unloaded --> [*]
Dependency Resolution
Section titled “Dependency Resolution”Services declare dependencies using dependsOnTypes(). The registry uses a topological sort to ensure services are initialized in the correct order.
graph TD
App --> Registry
Registry -->|1. Load| Physics
Registry -->|2. Load| Renderer
Renderer -->|Depends On| Physics
Implementing a Service
Section titled “Implementing a Service”Inherit from EntropyService and implement the lifecycle hooks.
#include <EntropyCore/Core/EntropyService.h>
class PhysicsService : public EntropyService {public: ENTROPY_REGISTER_TYPE(PhysicsService);
// Identity const char* id() const override { return "com.entropy.physics"; } const char* name() const override { return "Physics Service"; }
// Lifecycle void initialize() { Log::info("Initializing Physics Subsystem..."); } void start() override { Log::info("Starting Physics Simulation..."); } void stop() override { Log::info("Stopping Physics..."); }
// Dependencies std::vector<TypeSystem::TypeID> dependsOnTypes() const override { return { TypeSystem::createTypeId<WorkService>() }; }};// 1. Access Registry via Applicationauto& app = EntropyApplication::shared();auto& registry = app.services();
// 2. Register Serviceregistry.registerService(makeRef<PhysicsService>());
// 3. Lifecycle (typically handled by Application internally)// registry.loadAll();// registry.startAll();
// 4. Access Serviceauto physics = registry.get<PhysicsService>();Event Bus
Section titled “Event Bus”A type-safe publish-subscribe system for decoupled communication. Designed to be embedded in objects (Application, UIWidget) rather than global.
// 1. Define Eventstruct UserLoggedInEvent { int userId; };
// 2. Embed EventBus in your classclass Application {public: EventBus events;};
// 3. Subscribeapp.events.subscribe<UserLoggedInEvent>([](const auto& e) { Log::info("User {} logged in", e.userId);});
// 4. Publishapp.events.publish(UserLoggedInEvent{1});Timer Service
Section titled “Timer Service”Provides high-precision timing and scheduling. Accessed via EntropyApplication.
auto& app = EntropyApplication::shared();auto timers = app.services().get<TimerService>();
// Schedule a callback in 5 secondstimers->scheduleTimer(5.0f, []() { Log::info("5 seconds passed");});