3 * @purpose Temporary file to run a test thread that will query a sensors thread
4 * Code will probably be combined with Jeremy's FastCGI API
14 static DataPoint buffer[QUERY_BUFSIZ];
17 * Query sensor with id
18 * @param id - The index of the sensor in g_sensors
20 void QuerySensor(int id) //TODO: This code will form the SensorHandler FastCGI function (I think?)
22 Sensor * s = g_sensors+id;
25 //CRITICAL SECTION (Don't access file while sensor thread is writing to it!)
26 pthread_mutex_lock(&(s->mutex));
28 fseek(s->file, -QUERY_BUFSIZ*sizeof(DataPoint), SEEK_END);
29 amount_read = fread(&buffer, sizeof(DataPoint), QUERY_BUFSIZ, s->file);
30 Log(LOGDEBUG, "Read %d data points", amount_read);
32 pthread_mutex_unlock(&(s->mutex));
33 //End critical section
35 // So... we have a buffer
36 // I guess we'll want to JSON it or something?
37 // Just print it out for now
38 for (int i = 0; i < amount_read; ++i)
40 printf("%f\t%f\n", buffer[i].time, buffer[i].value);
43 // Will want to handle case where there actually wasn't anything new to respond with
44 // (In case we have a sensor that is slower than the rate of jQuery requests)
47 Log(LOGWARN, "No data points read from sensor%s file");
48 printf("# No data\n");
53 * Test function to simulate responding to HTTP requests
54 * @param args - IGNORED (void* required to pass function to pthread_create)
55 * @returns NULL (void* required to pass function to pthread_create)
57 void * Query_Main(void * args)
59 while (true) //TODO: Exit condition
62 for (int i = 0; i < NUMSENSORS; ++i)
64 printf("# Sensor %d\n", i);