Expand description
Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
This file is part of DMSC. The DMSC project belongs to the Dunimd Team.
Licensed under the Apache License, Version 2.0 (the “License”); You may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
§Core Module C API
This module provides C language bindings for DMSC’s core application infrastructure. The core module serves as the foundation for building DMSC applications, providing application lifecycle management, configuration handling, and initialization routines. This C API enables C/C++ applications to leverage DMSC’s powerful application builder and configuration management capabilities.
§Module Architecture
The core module comprises two essential components that form the backbone of any DMSC application:
-
DMSCAppBuilder: Fluent builder pattern implementation for constructing DMSC applications with type-safe configuration. The builder supports registration of modules, services, and middleware components through a declarative API. It handles dependency injection, service discovery, and lifecycle coordination across all registered components. The builder produces a fully initialized DMSCApp instance ready for execution.
-
DMSCConfig: Unified configuration management interface supporting multiple configuration sources including environment variables, command-line arguments, configuration files (YAML, TOML, JSON), and remote configuration services. The configuration system provides type-safe value retrieval with automatic type conversion, validation, and hot-reload capabilities for dynamic configuration updates in running applications.
§Application Lifecycle
DMSC applications follow a well-defined lifecycle:
-
Initialization Phase: Application builder creates and configures components. Services are registered, dependencies are wired, and configuration is loaded.
-
Startup Phase: All registered services and modules are initialized in dependency order. Health checks verify component readiness.
-
Running Phase: Application enters active state, processing requests or executing scheduled tasks. Components operate according to their configured behavior.
-
Shutdown Phase: Graceful shutdown initiates component cleanup in reverse dependency order. Resources are released, connections are closed, and state is persisted as needed.
§Configuration System
The configuration module implements a hierarchical configuration model:
-
Sources: Environment variables override file-based settings, which override default values. Multiple sources can coexist with configurable precedence.
-
Formats: Native support for YAML, TOML, JSON configuration files. Each format has optimized parsing and schema validation.
-
Validation: Configuration values undergo validation against defined schemas. Type mismatches, missing required fields, and constraint violations are detected.
-
Hot Reload: Configuration files are monitored for changes. Updates are applied atomically without application restart. Subscribers are notified of changes.
§Memory Management
All C API objects use opaque pointers with manual memory management:
- Constructor functions allocate new instances on the heap
- Destructor functions must be called to release memory
- Objects must not be used after being freed
- Null pointer checks are required before all operations
§Thread Safety
The underlying Rust implementations are thread-safe:
- Application builder operations require external synchronization
- Configuration reads are concurrent-safe after initialization
- Configuration writes require exclusive access
§Usage Example
// Create application configuration
CDMSCConfig* config = dmsc_config_new();
// Load configuration from file
int result = dmsc_config_load_file(config, "config.yaml");
// Get configuration value
char* value = dmsc_config_get_string(config, "database.url");
// Create application builder
CDMSCAppBuilder* builder = dmsc_app_builder_new();
// Configure builder with configuration
dmsc_app_builder_configure(builder, config);
// Build and run application
dmsc_app_builder_build(builder);
// Cleanup
dmsc_app_builder_free(builder);
dmsc_config_free(config);
dmsc_string_free(value);§Dependencies
This module depends on the following DMSC components:
crate::core: Rust core module implementationcrate::prelude: Common types and traits
§Feature Flags
The core module is always enabled as it provides fundamental infrastructure required by all other DMSC components.
Structs§
- CDMSC
AppBuilder - Opaque C wrapper structure for DMSCAppBuilder.
- CDMSC
Config - Opaque C wrapper structure for DMSCConfig.
Functions§
- dmsc_
app_ builder_ free - Frees a previously allocated CDMSCAppBuilder instance.
- dmsc_
app_ builder_ new - Creates a new CDMSCAppBuilder instance.
- dmsc_
config_ free - Frees a previously allocated CDMSCConfig instance.
- dmsc_
config_ get_ string - Retrieves a string configuration value by key.
- dmsc_
config_ new - Creates a new CDMSCConfig instance.