1 /* 2 * Copyright 2008-2009, Oliver Ruiz Dorantes, <oliver.ruiz.dorantes@gmail.com> 3 * Copyright 2012-2013, Tri-Edge AI <triedgeai@gmail.com> 4 * Copyright 2021, Haiku, Inc. 5 * Distributed under the terms of the MIT License. 6 * 7 * Authors: 8 * Fredrik Modéen <fredrik_at_modeen.se> 9 */ 10 11 12 #include "BluetoothSettings.h" 13 14 #include <SettingsMessage.h> 15 16 17 BluetoothSettings::BluetoothSettings() 18 : 19 fSettingsMessage(B_USER_SETTINGS_DIRECTORY, "Bluetooth_settings") 20 { 21 fCurrentSettings.pickeddevice = bdaddrUtils::NullAddress(); 22 fCurrentSettings.localdeviceclass = DeviceClass(); 23 fCurrentSettings.policy = 0; 24 fCurrentSettings.inquirytime = 15; 25 } 26 27 28 void 29 BluetoothSettings::SetPickedDevice(bdaddr_t pickeddevice) 30 { 31 fCurrentSettings.pickeddevice = pickeddevice; 32 } 33 34 35 void 36 BluetoothSettings::SetLocalDeviceClass(DeviceClass localdeviceclass) 37 { 38 fCurrentSettings.localdeviceclass = localdeviceclass; 39 } 40 41 42 void 43 BluetoothSettings::SetPolicy(int32 policy) 44 { 45 fCurrentSettings.policy = policy; 46 } 47 48 49 void 50 BluetoothSettings::SetInquiryTime(int32 inquirytime) 51 { 52 fCurrentSettings.inquirytime = inquirytime; 53 } 54 55 56 void 57 BluetoothSettings::LoadSettings() 58 { 59 bdaddr_t* addr; 60 ssize_t size; 61 status_t status = fSettingsMessage.FindData("BDAddress", B_RAW_TYPE, 62 (const void**)&addr, &size); 63 if (status == B_OK) 64 SetPickedDevice(*addr); 65 else 66 SetPickedDevice(bdaddrUtils::NullAddress()); 67 68 DeviceClass* devclass; 69 status = fSettingsMessage.FindData("DeviceClass", B_RAW_TYPE, 70 (const void**)&devclass, &size); 71 if (status == B_OK) 72 SetLocalDeviceClass(*devclass); 73 else 74 SetLocalDeviceClass(DeviceClass()); 75 76 SetPolicy(fSettingsMessage.GetValue("Policy", (int32)0)); 77 SetInquiryTime(fSettingsMessage.GetValue("InquiryTime", (int32)15)); 78 } 79 80 81 void 82 BluetoothSettings::SaveSettings() 83 { 84 fSettingsMessage.SetValue("DeviceClass", B_RAW_TYPE, 85 &fCurrentSettings.localdeviceclass, sizeof(DeviceClass)); 86 fSettingsMessage.SetValue("BDAddress", B_RAW_TYPE, &fCurrentSettings.pickeddevice, 87 sizeof(bdaddr_t)); 88 fSettingsMessage.SetValue("Policy", fCurrentSettings.policy); 89 fSettingsMessage.SetValue("InquiryTime", fCurrentSettings.inquirytime); 90 91 fSettingsMessage.Save(); 92 } 93