Adding files to initialize, update, and read key-value (to be used together with...
[iotcloud.git] / version2 / src / C / Init.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 260
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->initTable();
20         //t1->rebuild();
21         printf("T1 Ready\n");
22
23         baseurl->releaseRef();
24         password->releaseRef();
25
26         // Make the Keys
27         printf("Setting up keys\n");
28         for (int i = 0; i < NUMBER_OF_SENSORS; i++) {
29                 printf("%d\n",i);
30                 char buffer[80];
31                 sprintf(buffer, "sensor%d", i);
32                 IoTString *ia = new IoTString(buffer);
33                 t1->createNewKey(ia, MACHINE_ID);
34                 ia->releaseRef();
35         }
36
37         t1->update();
38         printf("Updating table\n");
39
40         for (uint i = 0; i < transStatusList->size(); i++) {
41                 TransactionStatus * status = transStatusList->get(i);
42                 if (status->getStatus() != TransactionStatus_StatusCommitted) {
43                         foundError = true;
44                         printf("Status error\n");
45                 }
46                 delete status;
47         }
48         
49         if (foundError) {
50                 printf("Found Errors...\n");
51         } else {
52                 printf("No Errors Found...\n");
53         }
54
55         delete transStatusList;
56         delete t1;
57 }
58