Skip to content

Commit 3ffcbc1

Browse files
committed
Simplify mDNS config component
1 parent 5455b67 commit 3ffcbc1

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

components/ocs_pipeline/config/mdns_config.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@ const char* log_tag = "mdns_config";
2424

2525
} // namespace
2626

27-
MdnsConfig::MdnsConfig(const system::DeviceInfo& device_info,
28-
storage::StorageBuilder& storage_builder) {
29-
storage_ = storage_builder.make("mdns_config");
30-
configASSERT(storage_);
31-
27+
MdnsConfig::MdnsConfig(storage::IStorage& storage, const system::DeviceInfo& device_info)
28+
: storage_(storage) {
3229
memset(hostname_, 0, sizeof(hostname_));
33-
auto code = algo::StorageOps::prob_read(*storage_, hostname_key_, hostname_,
30+
auto code = algo::StorageOps::prob_read(storage_, hostname_key_, hostname_,
3431
max_hostname_size_);
3532
if (code != status::StatusCode::OK) {
3633
memcpy(hostname_, device_info.get_fw_name(),
@@ -50,7 +47,7 @@ status::StatusCode MdnsConfig::configure(const char* hostname) {
5047
bool modified = false;
5148

5249
if (strncmp(hostname_, hostname, std::min(strlen(hostname_), strlen(hostname)))) {
53-
const auto code = storage_->write(hostname_key_, hostname, strlen(hostname));
50+
const auto code = storage_.write(hostname_key_, hostname, strlen(hostname));
5451
if (code != status::StatusCode::OK) {
5552
return code;
5653
}
@@ -68,7 +65,7 @@ status::StatusCode MdnsConfig::configure(const char* hostname) {
6865
}
6966

7067
status::StatusCode MdnsConfig::reset() {
71-
auto code = storage_->erase(hostname_key_);
68+
auto code = storage_.erase(hostname_key_);
7269
if (code == status::StatusCode::NoData) {
7370
code = status::StatusCode::NotModified;
7471
}

components/ocs_pipeline/config/mdns_config.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#pragma once
1010

1111
#include "ocs_core/noncopyable.h"
12-
#include "ocs_storage/storage_builder.h"
12+
#include "ocs_storage/istorage.h"
1313
#include "ocs_system/device_info.h"
1414

1515
namespace ocs {
@@ -21,10 +21,9 @@ class MdnsConfig : public core::NonCopyable<> {
2121
//! Initialize.
2222
//!
2323
//! @params
24+
//! - @p storage to persist mDNS configuration.
2425
//! - @p device_info to use as a fallback for mDNS configuration.
25-
//! - @p storage_builder to persist mDNS configuration.
26-
MdnsConfig(const system::DeviceInfo& device_info,
27-
storage::StorageBuilder& storage_builder);
26+
MdnsConfig(storage::IStorage& storage, const system::DeviceInfo& device_info);
2827

2928
//! Return the configured mDNS hostname.
3029
const char* get_hostname() const;
@@ -37,10 +36,9 @@ class MdnsConfig : public core::NonCopyable<> {
3736

3837
private:
3938
static constexpr const char* hostname_key_ = "host";
40-
4139
static constexpr unsigned max_hostname_size_ = 31;
4240

43-
storage::StorageBuilder::IStoragePtr storage_;
41+
storage::IStorage& storage_;
4442

4543
char hostname_[max_hostname_size_ + 1];
4644
};

0 commit comments

Comments
 (0)