Hi,
On Fri, Apr 16, 2021 at 10:10 AM <fredrik@xxxxxxxxx> wrote:
HI
I have a problem (making new methods to SettingsMessage). I was thinking of
change how Bluetooth pref store it's settings, but in small steps.
First step are to convert the stored settingsfile to BMessage.
struct {
bdaddr_t PickedDevice;
DeviceClass LocalDeviceClass;
int32 Policy;
int32 InquiryTime;
} Data;
int are not hard. when It comes to DeviceClass I was considering to store the
3 ints that it contains of and just make a DeviceClass when I read the
settings from file.
My biggest problem are how to store this bdaddr_t. Here I was consider
FindData/AddData, If that the case, then I need to extend SettingsMessage
with GetValue/SetValue for Data and there are my problem. Or should BMessage
should be extended to hadle a bdaddr_t?
This are what I came up with.. it's now how it should be. I don't even know
how this would be in C# (if it is/was possible). And that are what I use
ewery day..
status_t
SettingsMessage::SetValue(const char* name, type_code type, const void* data,
ssize_t numBytes)
const void*
SettingsMessage::GetValue(const char* name, type_code type, ssize_t numBytes,
const void& defaultValue)
This are how it suppose to be used.settings.PickedDevice = fSettingsMessage.GetValue(kPickedDevice,
void
BluetoothSettings::LoadSettings(Data& settings) const
{
// This are how the default was set before.
// Data.PickedDevice = bdaddrUtils::NullAddress();
// Data.LocalDeviceClass = DeviceClass();
// Data.Policy = 0;
// Data.InquiryTime = 15;
//Last parameter are the default value.
settings.PickedDevice = fSettingsMessage.GetValue(kPickedDevice,
B_ANY_TYPE, bdaddrUtils::NullAddress());
settings.Policy = fSettingsMessage.GetValue(kPolicy, 0);fSettingsMessage.SetValue("bdaddr", kBluetoothDeviceAddress,
settings.InquiryTime = fSettingsMessage.GetValue(kInquiryTime, 15);
}
void
BluetoothSettings::SaveSettings(const Data& settings)
{
fSettingsMessage.SetValue("bdaddr", B_ANY_TYPE, settings.bdaddr,
sizeof(bdaddr_t));
fSettingsMessage.SetValue(kPolicy, settings.Policy);
fSettingsMessage.SetValue(kInquiryTime, settings.InquiryTime);
fSettingsMessage.Save();
}