Skip to content

Commit d6266e5

Browse files
code refactor
1 parent 46a42af commit d6266e5

9 files changed

Lines changed: 204 additions & 43 deletions

File tree

include/bitchat/runners/cleanup_runner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class CleanupRunner
1818
CleanupRunner();
1919
~CleanupRunner();
2020

21-
// Set the network service
22-
void setNetworkService(std::shared_ptr<NetworkService> networkService);
21+
// Initialize the cleanup runner
22+
bool initialize(std::shared_ptr<NetworkService> networkService);
2323

2424
// Start the cleanup loop
2525
bool start();

include/bitchat/services/network_service.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class NetworkService
2727
~NetworkService();
2828

2929
// Initialize the network service
30-
bool initialize(std::shared_ptr<BluetoothInterface> bluetooth);
30+
bool initialize(std::shared_ptr<BluetoothInterface> bluetoothInterface, std::shared_ptr<BluetoothAnnounceRunner> announceRunner, std::shared_ptr<CleanupRunner> cleanupRunner);
3131

3232
// Start network operations
3333
bool start();
@@ -53,10 +53,6 @@ class NetworkService
5353
// Check if network is ready
5454
bool isReady() const;
5555

56-
// Set runner instances
57-
void setAnnounceRunner(std::shared_ptr<BluetoothAnnounceRunner> runner);
58-
void setCleanupRunner(std::shared_ptr<CleanupRunner> runner);
59-
6056
private:
6157
// Bluetooth interface
6258
std::shared_ptr<BluetoothInterface> bluetoothInterface;

src/bitchat/core/bitchat_manager.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,8 @@ bool BitchatManager::initialize(
7777
return false;
7878
}
7979

80-
// Set runners in NetworkService before initialization
81-
if (announceRunner)
82-
{
83-
networkService->setAnnounceRunner(announceRunner);
84-
}
85-
86-
if (cleanupRunner)
87-
{
88-
networkService->setCleanupRunner(cleanupRunner);
89-
}
90-
9180
// Initialize services
92-
if (!networkService->initialize(bluetoothInterface))
81+
if (!networkService->initialize(bluetoothInterface, announceRunner, cleanupRunner))
9382
{
9483
spdlog::error("Failed to initialize NetworkService");
9584
return false;
@@ -123,6 +112,7 @@ bool BitchatManager::initialize(
123112
// Set initialization state
124113
BitchatData::shared()->setInitialized(true);
125114
spdlog::info("BitchatManager initialized successfully");
115+
126116
return true;
127117
}
128118
catch (const std::exception &e)

src/bitchat/runners/bluetooth_announce_runner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ BluetoothAnnounceRunner::BluetoothAnnounceRunner()
1313
: shouldExit(false)
1414
, running(false)
1515
{
16+
// Pass
1617
}
1718

1819
BluetoothAnnounceRunner::~BluetoothAnnounceRunner()

src/bitchat/runners/cleanup_runner.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,21 @@ CleanupRunner::CleanupRunner()
1111
: shouldExit(false)
1212
, running(false)
1313
{
14+
// Pass
1415
}
1516

1617
CleanupRunner::~CleanupRunner()
1718
{
1819
stop();
1920
}
2021

21-
void CleanupRunner::setNetworkService(std::shared_ptr<NetworkService> networkService)
22+
bool CleanupRunner::initialize(std::shared_ptr<NetworkService> networkService)
2223
{
2324
this->networkService = networkService;
25+
26+
spdlog::info("CleanupRunner initialized");
27+
28+
return true;
2429
}
2530

2631
bool CleanupRunner::start()

src/bitchat/services/crypto_service.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace bitchat
1313
CryptoService::CryptoService()
1414
: signingPrivateKey(nullptr)
1515
{
16+
// Pass
1617
}
1718

1819
CryptoService::~CryptoService()
@@ -24,6 +25,7 @@ bool CryptoService::initialize()
2425
{
2526
OpenSSL_add_all_algorithms();
2627
ERR_load_crypto_strings();
28+
2729
return true;
2830
}
2931

src/bitchat/services/message_service.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ MessageService::MessageService()
2121

2222
bool MessageService::initialize(std::shared_ptr<NetworkService> networkService, std::shared_ptr<CryptoService> cryptoService, std::shared_ptr<NoiseService> noiseService)
2323
{
24+
// Set services
2425
this->networkService = networkService;
2526
this->cryptoService = cryptoService;
2627
this->noiseService = noiseService;

src/bitchat/services/network_service.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,21 @@ NetworkService::~NetworkService()
2626
stop();
2727
}
2828

29-
bool NetworkService::initialize(std::shared_ptr<BluetoothInterface> bluetooth)
29+
bool NetworkService::initialize(std::shared_ptr<BluetoothInterface> bluetoothInterface, std::shared_ptr<BluetoothAnnounceRunner> announceRunner, std::shared_ptr<CleanupRunner> cleanupRunner)
3030
{
31-
bluetoothInterface = bluetooth;
31+
// Set Bluetooth interface
32+
this->bluetoothInterface = bluetoothInterface;
3233

3334
if (!bluetoothInterface)
3435
{
3536
spdlog::error("NetworkService: Bluetooth interface is null");
3637
return false;
3738
}
3839

40+
// Set runners
41+
this->announceRunner = announceRunner;
42+
this->cleanupRunner = cleanupRunner;
43+
3944
// Set up Bluetooth callbacks
4045
// clang-format off
4146
bluetoothInterface->setPacketReceivedCallback([this](const BitchatPacket &packet, const std::string &peripheralID) {
@@ -167,16 +172,6 @@ bool NetworkService::isReady() const
167172
return bluetoothInterface && bluetoothInterface->isReady();
168173
}
169174

170-
void NetworkService::setAnnounceRunner(std::shared_ptr<BluetoothAnnounceRunner> runner)
171-
{
172-
announceRunner = runner;
173-
}
174-
175-
void NetworkService::setCleanupRunner(std::shared_ptr<CleanupRunner> runner)
176-
{
177-
cleanupRunner = runner;
178-
}
179-
180175
void NetworkService::onPeerConnected(const std::string &peripheralID)
181176
{
182177
spdlog::info("Peer connected with UUID: {}", peripheralID);

0 commit comments

Comments
 (0)