implemented RID ACL file save

pull/49/head
W3AXL 2 years ago
parent b9c89aebf1
commit 18f5d69a36

@ -166,3 +166,13 @@ bool IdenTableLookup::load()
return true;
}
/// <summary>
/// Saves the table to the passed lookup table file.
/// </summary>
/// <returns>True, if lookup table was saved, otherwise false.</returns>
bool IdenTableLookup::save()
{
/// TODO TODO TODO actually save stuff
return false;
}

@ -104,6 +104,10 @@ namespace lookups
/// <summary>Loads the table from the passed lookup table file.</summary>
/// <returns>True, if lookup table was loaded, otherwise false.</returns>
bool load() override;
/// <summary>Saves the table to the passed lookup table file.</summary>
/// <returns>True, if lookup table was saved, otherwise false.</returns>
bool save() override;
};
} // namespace lookups

@ -143,6 +143,8 @@ namespace lookups
/// <summary>Loads the table from the passed lookup table file.</summary>
/// <returns>True, if lookup table was loaded, otherwise false.</returns>
virtual bool load() = 0;
virtual bool save() = 0;
};
} // namespace lookups

@ -132,6 +132,7 @@ RadioId RadioIdLookup::find(uint32_t id)
void RadioIdLookup::commit()
{
// bryanb: TODO TODO TODO
save();
}
/// <summary>
@ -222,3 +223,61 @@ bool RadioIdLookup::load()
return true;
}
/// <summary>
/// Saves the table to the passed lookup table file.
/// </summary>
/// <returns>True, if lookup table was saved, otherwise false.</returns>
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;
}

@ -137,6 +137,10 @@ namespace lookups
/// <summary>Loads the table from the passed lookup table file.</summary>
/// <returns>True, if lookup table was loaded, otherwise false.</returns>
bool load() override;
/// <summary>Saves the table to the passed lookup table file.</summary>
/// <returns>True, if lookup table was saved, otherwise false.</returns>
bool save() override;
};
} // namespace lookups

Loading…
Cancel
Save

Powered by TurnKey Linux.