diff --git a/src/common/lookups/IdenTableLookup.cpp b/src/common/lookups/IdenTableLookup.cpp
index 9ef6a22d..4448c6be 100644
--- a/src/common/lookups/IdenTableLookup.cpp
+++ b/src/common/lookups/IdenTableLookup.cpp
@@ -166,3 +166,13 @@ bool IdenTableLookup::load()
return true;
}
+
+///
+/// Saves the table to the passed lookup table file.
+///
+/// True, if lookup table was saved, otherwise false.
+bool IdenTableLookup::save()
+{
+ /// TODO TODO TODO actually save stuff
+ return false;
+}
\ No newline at end of file
diff --git a/src/common/lookups/IdenTableLookup.h b/src/common/lookups/IdenTableLookup.h
index 271e0b43..1edf0b04 100644
--- a/src/common/lookups/IdenTableLookup.h
+++ b/src/common/lookups/IdenTableLookup.h
@@ -104,6 +104,10 @@ namespace lookups
/// Loads the table from the passed lookup table file.
/// True, if lookup table was loaded, otherwise false.
bool load() override;
+
+ /// Saves the table to the passed lookup table file.
+ /// True, if lookup table was saved, otherwise false.
+ bool save() override;
};
} // namespace lookups
diff --git a/src/common/lookups/LookupTable.h b/src/common/lookups/LookupTable.h
index 5515dede..96b65265 100644
--- a/src/common/lookups/LookupTable.h
+++ b/src/common/lookups/LookupTable.h
@@ -143,6 +143,8 @@ namespace lookups
/// Loads the table from the passed lookup table file.
/// True, if lookup table was loaded, otherwise false.
virtual bool load() = 0;
+
+ virtual bool save() = 0;
};
} // namespace lookups
diff --git a/src/common/lookups/RadioIdLookup.cpp b/src/common/lookups/RadioIdLookup.cpp
index 64af410d..672373b7 100644
--- a/src/common/lookups/RadioIdLookup.cpp
+++ b/src/common/lookups/RadioIdLookup.cpp
@@ -132,6 +132,7 @@ RadioId RadioIdLookup::find(uint32_t id)
void RadioIdLookup::commit()
{
// bryanb: TODO TODO TODO
+ save();
}
///
@@ -222,3 +223,61 @@ bool RadioIdLookup::load()
return true;
}
+
+///
+/// Saves the table to the passed lookup table file.
+///
+/// True, if lookup table was saved, otherwise false.
+bool RadioIdLookup::save()
+{
+ LogDebug(LOG_HOST, "Saving RID lookup file to %s", m_filename.c_str());
+
+ if (m_filename.empty()) {
+ return false;
+ }
+
+ std::ofstream file (m_filename, std::ofstream::out);
+ if (file.fail()) {
+ LogError(LOG_HOST, "Cannot open the radio ID lookup file - %s", m_filename.c_str());
+ return false;
+ }
+
+ // Counter for lines written
+ unsigned int lines = 0;
+
+ m_mutex.lock();
+ {
+ // String for writing
+ std::string line;
+ // iterate over each entry in the RID lookup and write it to the open file
+ for (auto& entry: m_table) {
+ // Get the parameters
+ uint32_t rid = entry.first;
+ bool enabled = entry.second.radioEnabled();
+ std::string alias = entry.second.radioAlias();
+ // Format into a string
+ line = std::to_string(rid) + "," + std::to_string(enabled) + ",";
+ // Add the alias if we have one
+ if (alias.length() > 0) {
+ line += alias;
+ line += ",";
+ }
+ // Add the newline
+ line += "\n";
+ // Write to file
+ file << line;
+ // Increment
+ lines++;
+ }
+ }
+ m_mutex.unlock();
+
+ file.close();
+
+ if (lines != m_table.size())
+ return false;
+
+ LogInfoEx(LOG_HOST, "Saved %u entries to lookup table file %s", lines, m_filename.c_str());
+
+ return true;
+}
\ No newline at end of file
diff --git a/src/common/lookups/RadioIdLookup.h b/src/common/lookups/RadioIdLookup.h
index 97787fee..a357cbe1 100644
--- a/src/common/lookups/RadioIdLookup.h
+++ b/src/common/lookups/RadioIdLookup.h
@@ -137,6 +137,10 @@ namespace lookups
/// Loads the table from the passed lookup table file.
/// True, if lookup table was loaded, otherwise false.
bool load() override;
+
+ /// Saves the table to the passed lookup table file.
+ /// True, if lookup table was saved, otherwise false.
+ bool save() override;
};
} // namespace lookups