68 lines
2.3 KiB
Zig
68 lines
2.3 KiB
Zig
const std = @import("std");
|
|
const heap = std.heap;
|
|
const mem = std.mem;
|
|
const Allocator = std.mem.Allocator;
|
|
const FixedBufferAllocator = heap.FixedBufferAllocator;
|
|
|
|
const Config = @import("config.zig").Config;
|
|
const data = @import("data");
|
|
const exchange = @import("exchange");
|
|
|
|
pub const ServerSettings = struct {
|
|
failure: bool = false,
|
|
delay: u64 = 0,
|
|
};
|
|
|
|
const payments = data.payments;
|
|
|
|
var config_allocated: [1024 * 100]u8 = undefined;
|
|
|
|
var heap_alocated: []u8 = undefined;
|
|
|
|
pub var config: Config = undefined;
|
|
pub var payments_repository: payments.PaymentsRepository = undefined;
|
|
|
|
var summary_exchange_connection: exchange.ExchangeConnection = undefined;
|
|
pub var summary_exchange: exchange.PaymentSummaryExchange = undefined;
|
|
|
|
pub var server_settings: ServerSettings = .{};
|
|
|
|
pub fn initConfig() !void {
|
|
var pba = FixedBufferAllocator.init(&config_allocated);
|
|
const allocator = pba.allocator();
|
|
|
|
config = try Config.init(allocator);
|
|
}
|
|
|
|
pub fn intiRepository(total_elements_expected: usize) !void {
|
|
const alloc_payments_repository = payments.calculateNecessaryMemory(total_elements_expected);
|
|
|
|
heap_alocated = try std.heap.page_allocator.alloc(u8, alloc_payments_repository);
|
|
var pba = FixedBufferAllocator.init(heap_alocated);
|
|
const allocator = pba.allocator();
|
|
|
|
const data_payments = try allocator.alloc(u8, alloc_payments_repository);
|
|
var pba_data_payments = FixedBufferAllocator.init(data_payments);
|
|
|
|
payments_repository = try payments.PaymentsRepository.init(pba_data_payments.allocator(), total_elements_expected);
|
|
|
|
if (config.payment_summary_exchange_host != null) {
|
|
summary_exchange_connection = try exchange.ExchangeConnection.init(
|
|
config.payment_summary_exchange_host.?,
|
|
config.payment_summary_exchange_port,
|
|
);
|
|
|
|
summary_exchange = exchange.PaymentSummaryExchange.init(&payments_repository, &summary_exchange_connection);
|
|
summary_exchange.start();
|
|
} else {
|
|
summary_exchange_connection = exchange.ExchangeConnection{
|
|
.in_address = undefined,
|
|
.out_address = undefined,
|
|
.out_status = .dead,
|
|
};
|
|
|
|
summary_exchange = exchange.PaymentSummaryExchange.init(&payments_repository, &summary_exchange_connection);
|
|
}
|
|
}
|
|
|
|
pub fn deinit() void {}
|