103 {
104
107
108 std::cout << "=== Multi-System Application Demo ===\n\n";
109
110
111 std::cout << "1. Loading configuration...\n";
112 auto config_result = common::config::read_yaml("app.yaml");
113 if (config_result.is_err()) {
114 std::cerr << "Config error: " << config_result.error().message << "\n";
115 std::cerr << "Using default configuration\n";
116 }
117 auto cfg = config_result.is_ok() ? config_result.value()
118 : common::config::Config::defaults();
119
120
121 std::cout << "2. Initializing systems...\n";
126
128 if (init_result.is_err()) {
129 std::cerr << "Initialization failed: "
130 << init_result.error().message << "\n";
131 return 1;
132 }
133
134 std::cout << " ✓ Systems initialized successfully\n\n";
135
136
140
141
142 std::cout << "3. Setting up database...\n";
143 database::connection_config db_config;
144 db_config.type = database::db_type::sqlite;
145 db_config.path = "users.db";
146
147 auto db_result = database::database::connect(db_config);
148 if (db_result.is_err()) {
149 std::cerr << "Database connection failed: "
150 << db_result.error().message << "\n";
152 return 1;
153 }
154 auto db = db_result.value();
155
156
157 auto create_table_result = db->execute(
158 "CREATE TABLE IF NOT EXISTS users ("
159 " id INTEGER PRIMARY KEY AUTOINCREMENT,"
160 " name TEXT NOT NULL,"
161 " email TEXT UNIQUE NOT NULL"
162 ")"
163 );
164
165 if (create_table_result.is_err()) {
166 std::cerr << "Table creation failed\n";
168 return 1;
169 }
170
171 std::cout << " ✓ Database ready\n\n";
172
173
174 std::cout << "4. Running application...\n";
175 logger->log(common::log_level::info, "Application started");
176
177
178 std::vector<std::pair<std::string, std::string>> sample_users = {
179 {"Alice Smith", "alice@example.com"},
180 {"Bob Johnson", "bob@example.com"},
181 {"Carol Williams", "carol@example.com"}
182 };
183
184 for (const auto& [name, email] : sample_users) {
186
187 if (result.is_ok()) {
188 const auto& user = result.value();
189 std::cout << " ✓ Registered: " << user.name
190 << " (ID: " << user.id << ")\n";
191 } else {
192 std::cout << " ✗ Failed: " << name
193 << " - " << result.error().message << "\n";
194 }
195
196
197 std::this_thread::sleep_for(std::chrono::milliseconds(100));
198
200 break;
201 }
202 }
203
204
205 std::cout << "\n5. Querying all users...\n";
206 auto users_result = db->query("SELECT id, name, email FROM users");
207
208 if (users_result.is_ok()) {
209 const auto& rows = users_result.value().rows;
210 std::cout << " Total users: " << rows.size() << "\n";
211
212 for (const auto& row : rows) {
213 std::cout << " - " << row.get<std::string>(1)
214 << " <" << row.get<std::string>(2) << ">\n";
215 }
216 }
217
218 logger->log(common::log_level::info, "Application completed");
219
220
221 std::cout << "\n6. Shutting down...\n";
223 std::chrono::seconds(5)
224 );
225
226 if (shutdown_result.is_err()) {
227 std::cerr << "Shutdown error: "
228 << shutdown_result.error().message << "\n";
229 return 1;
230 }
231
232 std::cout << " ✓ Shutdown complete\n";
233 std::cout << "\n=== Application Finished ===\n";
234
235 return 0;
236}
static service_container & services()
Get the service container.
static VoidResult shutdown(std::chrono::milliseconds timeout=std::chrono::seconds(30))
Shutdown the unified system gracefully.
static VoidResult initialize(const bootstrapper_options &opts={})
Initialize the unified system.
Abstract interface for task execution systems.
Standard interface for logging implementations.
void signal_handler(int signal)
std::atomic< bool > g_running
auto register_user(std::shared_ptr< database::database > db, std::shared_ptr< common::interfaces::ILogger > logger, const std::string &name, const std::string &email) -> common::Result< User >
Configuration options for the unified bootstrapper.
bool enable_logging
Enable logging system services.
bool enable_database
Enable database system services.
std::string config_path
Path to configuration file (optional)