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