basic of display management. Backend to register and give image for the device. front end to manage displays etc.
This commit is contained in:
57
Provider/main/api/devices/store.cpp
Normal file
57
Provider/main/api/devices/store.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// Device data store: CRUD helpers
|
||||
|
||||
#include "device.hpp"
|
||||
|
||||
// Find a device by MAC address, returns nullptr if not found
|
||||
internal device_t *find_device(const char *mac)
|
||||
{
|
||||
for (int i = 0; i < MAX_DEVICES; i++)
|
||||
{
|
||||
if (g_Devices[i].active && strcmp(g_Devices[i].mac, mac) == 0)
|
||||
{
|
||||
return &g_Devices[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Register a device by MAC. Returns pointer to device (existing or new).
|
||||
// Sets *was_new to true if it was freshly registered.
|
||||
internal device_t *register_device(const char *mac, bool *was_new)
|
||||
{
|
||||
*was_new = false;
|
||||
|
||||
// Check for existing
|
||||
device_t *existing = find_device(mac);
|
||||
if (existing)
|
||||
{
|
||||
return existing;
|
||||
}
|
||||
|
||||
// Find a free slot
|
||||
for (int i = 0; i < MAX_DEVICES; i++)
|
||||
{
|
||||
if (!g_Devices[i].active)
|
||||
{
|
||||
strlcpy(g_Devices[i].mac, mac, sizeof(g_Devices[i].mac));
|
||||
g_Devices[i].active = true;
|
||||
g_Devices[i].xml_layout[0] = '\0';
|
||||
*was_new = true;
|
||||
return &g_Devices[i];
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr; // All slots full
|
||||
}
|
||||
|
||||
// Update the XML layout for a device. Returns true on success.
|
||||
internal bool update_device_layout(const char *mac, const char *xml)
|
||||
{
|
||||
device_t *dev = find_device(mac);
|
||||
if (!dev)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
strlcpy(dev->xml_layout, xml, sizeof(dev->xml_layout));
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user