Common/Network: Get rid of out parameters for MAC address utilities

Given we have std::array and std::optional, we can use these in
conjunction with one another to avoid the need for out parameters.
This commit is contained in:
Lioncash 2018-06-10 14:32:33 -04:00
commit ce69201f33
9 changed files with 77 additions and 58 deletions

View file

@ -5,6 +5,7 @@
#include "Core/HW/EXI/EXI_DeviceEthernet.h"
#include <memory>
#include <optional>
#include <string>
#include "Common/ChunkFile.h"
@ -33,16 +34,17 @@ CEXIETHERNET::CEXIETHERNET()
// Parse MAC address from config, and generate a new one if it doesn't
// exist or can't be parsed.
std::string& mac_addr_setting = SConfig::GetInstance().m_bba_mac;
u8 mac_addr[Common::MAC_ADDRESS_SIZE] = {0};
std::optional<Common::MACAddress> mac_addr = Common::StringToMacAddress(mac_addr_setting);
if (!Common::StringToMacAddress(mac_addr_setting, mac_addr))
if (!mac_addr)
{
Common::GenerateMacAddress(Common::MACConsumer::BBA, mac_addr);
mac_addr_setting = Common::MacAddressToString(mac_addr);
mac_addr = Common::GenerateMacAddress(Common::MACConsumer::BBA);
mac_addr_setting = Common::MacAddressToString(mac_addr.value());
SConfig::GetInstance().SaveSettings();
}
memcpy(&mBbaMem[BBA_NAFR_PAR0], mac_addr, Common::MAC_ADDRESS_SIZE);
const auto& mac = mac_addr.value();
memcpy(&mBbaMem[BBA_NAFR_PAR0], mac.data(), mac.size());
// HACK: .. fully established 100BASE-T link
mBbaMem[BBA_NWAYS] = NWAYS_LS100 | NWAYS_LPNWAY | NWAYS_100TXF | NWAYS_ANCLPT;