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)
{
status_t ret = ReplaceData(name, type, &data, numBytes);
if (ret != B_OK)
ret = AddData(name, type, data, numBytes);
if (ret == B_OK)
_NotifyValueChanged(name);
return ret;
}
const void*
SettingsMessage::GetValue(const char* name, type_code type, ssize_t
numBytes, const void& defaultValue)
{
void* value;
if (FindData(name, type, (const void**)&value, &bytes) != B_OK)
return defaultValue;
return value;
}
This are how it suppose to be used.
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, sizeof(bdaddr_t), bdaddrUtils::NullAddress());
settings.Policy = fSettingsMessage.GetValue(kPolicy, 0);
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();
}
//Fredrik