git.ucc.asn.au
/
matches
/
MCTX3420.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Notes from meeting
[matches/MCTX3420.git]
/
server
/
fastcgi.c
diff --git
a/server/fastcgi.c
b/server/fastcgi.c
index
8f4ab32
..
62978ea
100644
(file)
--- a/
server/fastcgi.c
+++ b/
server/fastcgi.c
@@
-12,8
+12,10
@@
#include "common.h"
#include "sensor.h"
#include "common.h"
#include "sensor.h"
+#include "actuator.h"
#include "control.h"
#include "options.h"
#include "control.h"
#include "options.h"
+#include "image.h"
/**The time period (in seconds) before the control key expires @ */
#define CONTROL_TIMEOUT 180
/**The time period (in seconds) before the control key expires @ */
#define CONTROL_TIMEOUT 180
@@
-40,7
+42,7
@@
struct FCGIContext {
static void IdentifyHandler(FCGIContext *context, char *params) {
bool ident_sensors = false, ident_actuators = false;
//const char *key, *value;
static void IdentifyHandler(FCGIContext *context, char *params) {
bool ident_sensors = false, ident_actuators = false;
//const char *key, *value;
- struct timeval now;
+
int i;
FCGIValue values[2] = {{"sensors", &ident_sensors, FCGI_BOOL_T},
int i;
FCGIValue values[2] = {{"sensors", &ident_sensors, FCGI_BOOL_T},
@@
-237,14
+239,19
@@
bool FCGI_ParseRequest(FCGIContext *context, char *params, FCGIValue values[], s
case FCGI_BOOL_T:
*((bool*) val->value) = true;
break;
case FCGI_BOOL_T:
*((bool*) val->value) = true;
break;
- case FCGI_
LONG_T:
-
*((long*) val->value)
= strtol(value, &ptr, 10);
+ case FCGI_
INT_T: case FCGI_LONG_T: {
+
long parsed
= strtol(value, &ptr, 10);
if (!*value || *ptr) {
snprintf(buf, BUFSIZ, "Expected int for '%s' but got '%s'", key, value);
FCGI_RejectJSON(context, FCGI_EscapeJSON(buf));
return false;
}
if (!*value || *ptr) {
snprintf(buf, BUFSIZ, "Expected int for '%s' but got '%s'", key, value);
FCGI_RejectJSON(context, FCGI_EscapeJSON(buf));
return false;
}
- break;
+
+ if (FCGI_TYPE(val->flags) == FCGI_INT_T)
+ *((int*) val->value) = parsed;
+ else
+ *((long*) val->value) = parsed;
+ } break;
case FCGI_DOUBLE_T:
*((double*) val->value) = strtod(value, &ptr);
if (!*value || *ptr) {
case FCGI_DOUBLE_T:
*((double*) val->value) = strtod(value, &ptr);
if (!*value || *ptr) {
@@
-292,6
+299,7
@@
void FCGI_BeginJSON(FCGIContext *context, StatusCodes status_code)
printf("\t\"module\" : \"%s\"", context->current_module);
FCGI_JSONLong("status", status_code);
//Time and running statistics
printf("\t\"module\" : \"%s\"", context->current_module);
FCGI_JSONLong("status", status_code);
//Time and running statistics
+ struct timeval now;
gettimeofday(&now, NULL);
FCGI_JSONDouble("start_time", TIMEVAL_TO_DOUBLE(g_options.start_time));
FCGI_JSONDouble("current_time", TIMEVAL_TO_DOUBLE(now));
gettimeofday(&now, NULL);
FCGI_JSONDouble("start_time", TIMEVAL_TO_DOUBLE(g_options.start_time));
FCGI_JSONDouble("current_time", TIMEVAL_TO_DOUBLE(now));
@@
-426,6
+434,17
@@
void FCGI_PrintRaw(const char *format, ...)
va_end(list);
}
va_end(list);
}
+
+/**
+ * Write binary data
+ * See fwrite
+ */
+void FCGI_WriteBinary(void * data, size_t size, size_t num_elem)
+{
+ Log(LOGDEBUG,"Writing!");
+ fwrite(data, size, num_elem, stdout);
+}
+
/**
* Main FCGI request loop that receives/responds to client requests.
* @param data Reserved.
/**
* Main FCGI request loop that receives/responds to client requests.
* @param data Reserved.
@@
-437,19
+456,7
@@
void * FCGI_RequestLoop (void *data)
FCGIContext context = {0};
Log(LOGDEBUG, "First request...");
FCGIContext context = {0};
Log(LOGDEBUG, "First request...");
- //TODO: The FCGI_Accept here is blocking.
- // That means that if another thread terminates the program, this thread
- // will not terminate until the next request is made.
while (FCGI_Accept() >= 0) {
while (FCGI_Accept() >= 0) {
-
- if (Thread_Runstate() != RUNNING)
- {
- //TODO: Yeah... deal with this better :P
- Log(LOGERR, "FIXME; FCGI gets request after other threads have finished.");
- printf("Content-type: text/plain\r\n\r\n+++OUT OF CHEESE ERROR+++\n");
- break;
- }
-
Log(LOGDEBUG, "Got request #%d", context.response_number);
ModuleHandler module_handler = NULL;
char module[BUFSIZ], params[BUFSIZ];
Log(LOGDEBUG, "Got request #%d", context.response_number);
ModuleHandler module_handler = NULL;
char module[BUFSIZ], params[BUFSIZ];
@@
-473,6
+480,10
@@
void * FCGI_RequestLoop (void *data)
module_handler = Control_Handler;
} else if (!strcmp("sensors", module)) {
module_handler = Sensor_Handler;
module_handler = Control_Handler;
} else if (!strcmp("sensors", module)) {
module_handler = Sensor_Handler;
+ } else if (!strcmp("actuators", module)) {
+ module_handler = Actuator_Handler;
+ } else if (!strcmp("image", module)) {
+ module_handler = Image_Handler;
}
context.current_module = module;
}
context.current_module = module;
@@
-487,7
+498,6
@@
void * FCGI_RequestLoop (void *data)
}
Log(LOGDEBUG, "Thread exiting.");
}
Log(LOGDEBUG, "Thread exiting.");
- Thread_QuitProgram(false);
// NOTE: Don't call pthread_exit, because this runs in the main thread. Just return.
return NULL;
}
// NOTE: Don't call pthread_exit, because this runs in the main thread. Just return.
return NULL;
}
UCC
git Repository :: git.ucc.asn.au