Adding Fidelius manual.
[iotcloud.git] / version2 / src / C / Update.C
1 #include "Table.h"
2 #include "IoTString.h"
3 #include "TimingSingleton.h"
4 #include "TransactionStatus.h"
5
6 #define NUMBER_OF_SENSORS 1
7 #define MACHINE_ID 15512
8
9 int main(int numargs, char ** args) {
10         TimingSingleton * timer = TimingSingleton_getInstance();
11
12         bool foundError = false;
13         Vector<TransactionStatus *> * transStatusList = new Vector<TransactionStatus *>();
14
15         // Setup the 2 clients
16         IoTString * baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
17         IoTString * password = new IoTString("reallysecret");
18         Table * t1 = new Table(baseurl, password, MACHINE_ID, -1);
19         t1->rebuild();
20         printf("T1 Ready\n");
21
22         baseurl->releaseRef();
23         password->releaseRef();
24
25         char keyBuffer[80];
26         char dataBuffer[80];
27
28         sprintf(keyBuffer, "tempF0");
29         IoTString * iKeyA = new IoTString(keyBuffer);
30         sprintf(dataBuffer, "data4");
31         IoTString * iValueA = new IoTString(dataBuffer);
32         t1->createNewKey(iKeyA, MACHINE_ID);
33         t1->startTransaction();
34         t1->put(iKeyA, iValueA);
35         transStatusList->add(t1->commitTransaction());
36         
37         sprintf(keyBuffer, "humid0");
38         IoTString * iKeyB = new IoTString(keyBuffer);
39         sprintf(dataBuffer, "data6");
40         IoTString * iValueB = new IoTString(dataBuffer);
41         t1->createNewKey(iKeyB, MACHINE_ID);
42         t1->startTransaction();
43         t1->put(iKeyB, iValueB);
44         transStatusList->add(t1->commitTransaction());
45         t1->update();
46         
47         iKeyB->releaseRef();
48         iValueB->releaseRef();
49         iKeyA->releaseRef();
50         iValueA->releaseRef();
51
52         for (uint i = 0; i < transStatusList->size(); i++) {
53                 TransactionStatus * status = transStatusList->get(i);
54                 if (status->getStatus() != TransactionStatus_StatusCommitted) {
55                         foundError = true;
56                         printf("Status error\n");
57                 }
58                 delete status;
59         }
60         
61         if (foundError) {
62                 printf("Found Errors...\n");
63         } else {
64                 printf("No Errors Found...\n");
65         }
66
67         delete transStatusList;
68         delete t1;
69 }
70