+
+ // Check if format type was specified
+ if (FCGI_RECEIVED(values[FORMAT].flags))
+ {
+ if (strcmp(fmt_str, "json") == 0)
+ format = JSON;
+ else if (strcmp(fmt_str, "tsv") == 0)
+ format = TSV;
+ else
+ Log(LOGERR, "Unknown format type \"%s\"", fmt_str);
+ }
+
+ // Get Sensor
+ Sensor * s = g_sensors[id];
+
+ // Begin response
+ Sensor_BeginResponse(context, id, format);
+
+ // If a time was specified
+ if (FCGI_RECEIVED(values[START_TIME].flags) || FCGI_RECEIVED(values[END_TIME].flags))
+ {
+ // Wrap times relative to the current time
+ if (start_time < 0)
+ start_time += current_time;
+ if (end_time < 0)
+ end_time += current_time;
+
+ // Print points by time range
+ Data_PrintByTimes(&(s->data_file), start_time, end_time, format);
+
+ }
+ else // No time was specified; just return a recent set of points
+ {
+ pthread_mutex_lock(&(s->data_file.mutex));
+ int start_index = s->data_file.num_points-DATA_BUFSIZ;
+ int end_index = s->data_file.num_points-1;
+ pthread_mutex_unlock(&(s->data_file.mutex));
+
+ // Print points by indexes
+ Data_PrintByIndexes(&(s->data_file), start_index, end_index, format);
+ }
+
+ // Finish response
+ Sensor_EndResponse(context, id, format);
+