Bluetooth: rename FFBluetoothDevice to FFBluetoothResult

This commit is contained in:
李通洲
2023-08-30 13:13:11 +08:00
parent 757e5f8174
commit fb3fb1bf99
6 changed files with 22 additions and 22 deletions
+3 -3
View File
@@ -5,15 +5,15 @@
#include "fastfetch.h"
typedef struct FFBluetoothDevice
typedef struct FFBluetoothResult
{
FFstrbuf name;
FFstrbuf address;
FFstrbuf type;
uint8_t battery; // 0-100%
bool connected;
} FFBluetoothDevice;
} FFBluetoothResult;
const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothDevice */);
const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothResult */);
#endif
+2 -2
View File
@@ -2,7 +2,7 @@
#import <IOBluetooth/IOBluetooth.h>
const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothDevice */)
const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothResult */)
{
NSArray<IOBluetoothDevice*>* ioDevices = IOBluetoothDevice.pairedDevices;
if(!ioDevices)
@@ -10,7 +10,7 @@ const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothDevice */)
for(IOBluetoothDevice* ioDevice in ioDevices)
{
FFBluetoothDevice* device = ffListAdd(devices);
FFBluetoothResult* device = ffListAdd(devices);
ffStrbufInitS(&device->name, ioDevice.name.UTF8String);
ffStrbufInitS(&device->address, ioDevice.addressString.UTF8String);
ffStrbufInit(&device->type);
+4 -4
View File
@@ -44,7 +44,7 @@ array [ //root
]
*/
static void detectBluetoothValue(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothDevice* device)
static void detectBluetoothValue(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothResult* device)
{
if(dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
return;
@@ -72,7 +72,7 @@ static void detectBluetoothValue(FFDBusData* dbus, DBusMessageIter* iter, FFBlue
ffDBusGetBool(dbus, &dictIter, &device->connected);
}
static void detectBluetoothProperty(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothDevice* device)
static void detectBluetoothProperty(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothResult* device)
{
if(dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
return;
@@ -130,7 +130,7 @@ static void detectBluetoothObject(FFlist* devices, FFDBusData* dbus, DBusMessage
DBusMessageIter arrayIter;
dbus->lib->ffdbus_message_iter_recurse(&dictIter, &arrayIter);
FFBluetoothDevice* device = ffListAdd(devices);
FFBluetoothResult* device = ffListAdd(devices);
ffStrbufInit(&device->name);
ffStrbufInit(&device->address);
ffStrbufInit(&device->type);
@@ -193,7 +193,7 @@ static const char* detectBluetooth(FFlist* devices)
#endif
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothDevice */)
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */)
{
#ifdef FF_HAVE_DBUS
return detectBluetooth(devices);
@@ -1,6 +1,6 @@
#include "bluetooth.h"
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothDevice */)
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */)
{
return "Not supported on this platform";
}
+2 -2
View File
@@ -7,7 +7,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpointer-sign"
const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothDevice */)
const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothResult */)
{
BLUETOOTH_DEVICE_SEARCH_PARAMS btsp = {
.fReturnConnected = TRUE,
@@ -25,7 +25,7 @@ const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothDevice */)
return "BluetoothFindFirstDevice() failed or no devices found";
do {
FFBluetoothDevice* device = ffListAdd(devices);
FFBluetoothResult* device = ffListAdd(devices);
ffStrbufInit(&device->name);
ffStrbufInit(&device->address);
ffStrbufInit(&device->type);
+10 -10
View File
@@ -6,7 +6,7 @@
#define FF_BLUETOOTH_NUM_FORMAT_ARGS 4
static void printDevice(FFBluetoothOptions* options, const FFBluetoothDevice* device, uint8_t index)
static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* device, uint8_t index)
{
if(options->moduleArgs.outputFormat.length == 0)
{
@@ -34,7 +34,7 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothDevice* de
void ffPrintBluetooth(FFBluetoothOptions* options)
{
FF_LIST_AUTO_DESTROY devices = ffListCreate(sizeof (FFBluetoothDevice));
FF_LIST_AUTO_DESTROY devices = ffListCreate(sizeof (FFBluetoothResult));
const char* error = ffDetectBluetooth(&devices);
if(error)
@@ -43,14 +43,14 @@ void ffPrintBluetooth(FFBluetoothOptions* options)
}
else
{
FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFBluetoothDevice*));
FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFBluetoothResult*));
FF_LIST_FOR_EACH(FFBluetoothDevice, device, devices)
FF_LIST_FOR_EACH(FFBluetoothResult, device, devices)
{
if(!device->connected && !options->showDisconnected)
continue;
*(FFBluetoothDevice**)ffListAdd(&filtered) = device;
*(FFBluetoothResult**)ffListAdd(&filtered) = device;
}
if(filtered.length == 0)
@@ -61,11 +61,11 @@ void ffPrintBluetooth(FFBluetoothOptions* options)
for(uint32_t i = 0; i < filtered.length; i++)
{
uint8_t index = (uint8_t) (filtered.length == 1 ? 0 : i + 1);
printDevice(options, *(FFBluetoothDevice**)ffListGet(&filtered, i), index);
printDevice(options, *(FFBluetoothResult**)ffListGet(&filtered, i), index);
}
}
FF_LIST_FOR_EACH(FFBluetoothDevice, device, devices)
FF_LIST_FOR_EACH(FFBluetoothResult, device, devices)
{
ffStrbufDestroy(&device->name);
ffStrbufDestroy(&device->type);
@@ -126,7 +126,7 @@ void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module)
void ffGenerateBluetoothJson(FF_MAYBE_UNUSED FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBluetoothDevice));
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBluetoothResult));
const char* error = ffDetectBluetooth(&results);
if (error)
@@ -139,7 +139,7 @@ void ffGenerateBluetoothJson(FF_MAYBE_UNUSED FFBluetoothOptions* options, yyjson
yyjson_mut_val* arr = yyjson_mut_arr(doc);
yyjson_mut_obj_add_val(doc, module, "result", arr);
FF_LIST_FOR_EACH(FFBluetoothDevice, item, results)
FF_LIST_FOR_EACH(FFBluetoothResult, item, results)
{
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
yyjson_mut_obj_add_strbuf(doc, obj, "address", &item->address);
@@ -150,7 +150,7 @@ void ffGenerateBluetoothJson(FF_MAYBE_UNUSED FFBluetoothOptions* options, yyjson
}
}
FF_LIST_FOR_EACH(FFBluetoothDevice, device, results)
FF_LIST_FOR_EACH(FFBluetoothResult, device, results)
{
ffStrbufDestroy(&device->name);
ffStrbufDestroy(&device->type);