-
Notifications
You must be signed in to change notification settings - Fork 3
/
datastore.pde
79 lines (71 loc) · 2.06 KB
/
datastore.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
DataStore::DataStore(char *_name)
{
name = _name;
}
bool DataStore::load()
{
bool result = false;
FlowMemoryManager memoryManager = FlowMemoryManager_New();
if (memoryManager)
{
FlowDevice thisDevice = FlowClient_GetLoggedInDevice(memoryManager);
if (thisDevice)
{
_datastore = FlowDevice_RetrieveDataStore(thisDevice, name);
if (_datastore)
{
if (FlowMemoryManager_DetachObject(memoryManager, &_datastore))
{
result = true;
}
}
}
FlowMemoryManager_Free(&memoryManager);
}
return result;
}
bool DataStore::clear(char *str)
{
bool result = false;
FlowMemoryManager memoryManager = FlowMemoryManager_New();
if (memoryManager && FlowMemoryManager_AttachObject(memoryManager, _datastore))
{
FlowDataStoreItems datastoreItems = FlowDataStore_RetrieveItems(_datastore, 0);
unsigned int measurementCount = FlowDataStoreItems_GetTotalCount(datastoreItems);
if (datastoreItems && FlowDataStoreItems_Remove(datastoreItems, str))
{
Serial.print("\n\rSuccessfully deleted measurement(s).\n\r");
result = true;
}
else
{
Serial.print("Error, failed to delete saved measurements.");
}
FlowMemoryManager_DetachObject(memoryManager, &_datastore);
FlowMemoryManager_Free(&memoryManager);
}
return result;
}
bool DataStore::save(XMLNode &node){
bool result = false;
StringBuilder datastoreItem = StringBuilder_New(1024);
datastoreItem = node.appendTo(datastoreItem);
FlowMemoryManager memoryManager = FlowMemoryManager_New();
if (memoryManager && FlowMemoryManager_AttachObject(memoryManager, _datastore))
{
FlowDataStoreItems datastoreItems = FlowDataStore_RetrieveItems(_datastore, 0);
if (datastoreItems)
{
FlowDataStoreItem newItem = FlowDataStoreItem_New(memoryManager);
FlowDataStoreItem_SetContent(newItem, (char *) StringBuilder_GetCString(datastoreItem));
if (FlowDataStoreItems_AddItem(datastoreItems, newItem))
{
result = true;
}
}
FlowMemoryManager_DetachObject(memoryManager, &_datastore);
}
FlowMemoryManager_Free(&memoryManager);
StringBuilder_Free(&datastoreItem);
return result;
}