-
-
Save oneman/37a9a702b99626bb965d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/daemon/krad_ops.c b/daemon/krad_ops.c | |
index 2d1068c..74815fd 100644 | |
--- a/daemon/krad_ops.c | |
+++ b/daemon/krad_ops.c | |
@@ -37,7 +37,7 @@ typedef struct kr_media_ops_server kr_media_ops_server; | |
#define KR_COMMAND_SIZE 512 | |
#define KR_OPS_NTASKS 64 | |
-#define KR_TIMEOUT_SEC 1 | |
+#define KR_TIMEOUT_SEC 100 | |
#define KR_OPS_BASE "/tasks" | |
struct kr_media_ops_server { | |
@@ -328,43 +328,74 @@ static int add_route(kr_front_router *router, const char *str) { | |
return 0; | |
} | |
-static ssize_t say_hello(kr_web_path *path) { | |
+static ssize_t say_something(kr_web_path *path, const char *something) { | |
kr_http_header hdr; | |
kr_http_response res; | |
uint8_t hdrbuf[512]; | |
- char *hello; | |
size_t sz; | |
size_t hdrsz; | |
+ printk("trying to send '%s'", something); | |
hdrsz = sizeof(hdrbuf); | |
- hello = "Hello, world!"; | |
- sz = strlen(hello); | |
+ sz = strlen(something); | |
kr_http_response_init(&res, 200); | |
kr_http_length_header_init(&hdr, sz, hdrbuf, hdrsz); | |
kr_http_response_add_header(&res, &hdr); | |
kr_web_path_pack_http_response(path, &res); | |
- return kr_web_path_pack(path, (uint8_t *)hello, sz); | |
+ return kr_web_path_pack(path, (uint8_t *)something, sz); | |
} | |
static int say_no_no(kr_web_path *path) { | |
- kr_http_response res; | |
- kr_http_response_init(&res, 404); | |
- kr_web_path_pack_http_response(path, &res); | |
+ say_something(path, "no no"); | |
return 0; | |
} | |
-static void got_headers(kr_web_path *path, kr_front_router *router) { | |
+static void do_post(kr_web_path *path, kr_front_router *router) { | |
kr_front_route *route; | |
printk("?"); | |
route = kr_front_resolve(router, KR_OPS_BASE, strlen(KR_OPS_BASE)); | |
if (route) { | |
printk("good"); | |
- say_hello(path); | |
+ say_something(path, "hello, world!"); | |
} else { | |
printk("bad"); | |
say_no_no(path); | |
} | |
} | |
+static void do_get(kr_web_path *path) { | |
+ int i; | |
+ int ret; | |
+ kr_mt *task; | |
+ char json[8192]; | |
+ kr_media_ops_server *server; | |
+ i = 0; | |
+ server = path->web->user; | |
+ if ((task = kr_pool_iterate_active(server->task_pool, &i))) { | |
+ ret = kr_mt_info_pack_json(json, task, sizeof(json)); | |
+ if (ret > 0) { | |
+ say_something(path, json); | |
+ } else { | |
+ say_something(path, "found a task, but couldn't pack it as json."); | |
+ } | |
+ } else { | |
+ say_something(path, "no running tasks."); | |
+ } | |
+} | |
+ | |
+static void got_headers(kr_web_path *path, kr_front_router *router) { | |
+ switch(path->client.http.request.req_line.method) { | |
+ case KR_HTTP_GET: | |
+ do_get(path); | |
+ break; | |
+ case KR_HTTP_POST: | |
+ do_post(path, router); | |
+ break; | |
+ default: | |
+ say_something(path, "huh?"); | |
+ break; | |
+ } | |
+} | |
+ | |
static int web_event(kr_web_event *event) { | |
int ret; | |
kr_media_ops_server *server; | |
@@ -546,6 +577,7 @@ static int handle_startup(kr_app_server *app_server, void *user) { | |
web_setup.event_cb = web_event; | |
web_setup.user = server; | |
web_setup.npaths = KR_OPS_NTASKS; | |
+ web_setup.master_loop = kr_app_server_mainloop_get(app_server); | |
server->web = kr_web_create(&web_setup); | |
/* KLUDGE */ | |
if (getenv("KRAD_WEB_PORT")) { | |
@@ -554,7 +586,7 @@ static int handle_startup(kr_app_server *app_server, void *user) { | |
new.type = KR_WEB_SERVER; | |
new.server.type = KR_WEB_SERVER_HTTP; | |
new.server.port = atoi(getenv("KRAD_WEB_PORT")); | |
- kr_web_path_create(server->web, &new, "coconutptr"); | |
+ kr_web_path_create(server->web, &new, server); | |
} | |
/* END KLUDGE */ | |
memset(&router_setup, 0, sizeof(router_setup)); | |
diff --git a/lib/gen/info_functions.h b/lib/gen/info_functions.h | |
index b45d10e..a0f9f22 100644 | |
--- a/lib/gen/info_functions.h | |
+++ b/lib/gen/info_functions.h | |
@@ -583,6 +583,8 @@ static const kr_info_functions_spec info_functions[] = { | |
[KR_AVCONV_INFO] = { | |
.size = sizeof(struct kr_avconv_info), | |
.to_text = kr_avconv_info_to_text, | |
+ .pack_json = kr_avconv_info_pack_json, | |
+ .unpack_json = kr_avconv_info_unpack_json, | |
.init = kr_avconv_info_init, | |
.valid = kr_avconv_info_valid, | |
.random = kr_avconv_info_random, | |
@@ -592,6 +594,8 @@ static const kr_info_functions_spec info_functions[] = { | |
[KR_CURL_INFO] = { | |
.size = sizeof(struct kr_curl_info), | |
.to_text = kr_curl_info_to_text, | |
+ .pack_json = kr_curl_info_pack_json, | |
+ .unpack_json = kr_curl_info_unpack_json, | |
.init = kr_curl_info_init, | |
.valid = kr_curl_info_valid, | |
.random = kr_curl_info_random, | |
@@ -601,6 +605,8 @@ static const kr_info_functions_spec info_functions[] = { | |
[KR_LIVESTREAMER_INFO] = { | |
.size = sizeof(struct kr_livestreamer_info), | |
.to_text = kr_livestreamer_info_to_text, | |
+ .pack_json = kr_livestreamer_info_pack_json, | |
+ .unpack_json = kr_livestreamer_info_unpack_json, | |
.init = kr_livestreamer_info_init, | |
.valid = kr_livestreamer_info_valid, | |
.random = kr_livestreamer_info_random, | |
@@ -610,6 +616,8 @@ static const kr_info_functions_spec info_functions[] = { | |
[KR_QUVI_INFO] = { | |
.size = sizeof(struct kr_quvi_info), | |
.to_text = kr_quvi_info_to_text, | |
+ .pack_json = kr_quvi_info_pack_json, | |
+ .unpack_json = kr_quvi_info_unpack_json, | |
.init = kr_quvi_info_init, | |
.valid = kr_quvi_info_valid, | |
.random = kr_quvi_info_random, | |
@@ -619,6 +627,8 @@ static const kr_info_functions_spec info_functions[] = { | |
[KR_TEST_TASK_INFO] = { | |
.size = sizeof(struct kr_test_task_info), | |
.to_text = kr_test_task_info_to_text, | |
+ .pack_json = kr_test_task_info_pack_json, | |
+ .unpack_json = kr_test_task_info_unpack_json, | |
.init = kr_test_task_info_init, | |
.valid = kr_test_task_info_valid, | |
.random = kr_test_task_info_random, | |
@@ -628,6 +638,8 @@ static const kr_info_functions_spec info_functions[] = { | |
[KR_TRANSMISSION_CLI_INFO] = { | |
.size = sizeof(struct kr_transmission_cli_info), | |
.to_text = kr_transmission_cli_info_to_text, | |
+ .pack_json = kr_transmission_cli_info_pack_json, | |
+ .unpack_json = kr_transmission_cli_info_unpack_json, | |
.init = kr_transmission_cli_info_init, | |
.valid = kr_transmission_cli_info_valid, | |
.random = kr_transmission_cli_info_random, | |
@@ -638,6 +650,7 @@ static const kr_info_functions_spec info_functions[] = { | |
.size = sizeof(kr_mt_status), | |
.to_text = kr_mt_status_to_text, | |
.pack_json = kr_mt_status_pack_json, | |
+ .unpack_json = kr_mt_status_unpack_json, | |
.init = kr_mt_status_init, | |
.valid = kr_mt_status_valid, | |
.random = kr_mt_status_random, | |
@@ -648,6 +661,7 @@ static const kr_info_functions_spec info_functions[] = { | |
.size = sizeof(kr_ops_info), | |
.to_text = kr_ops_info_to_text, | |
.pack_json = kr_ops_info_pack_json, | |
+ .unpack_json = kr_ops_info_unpack_json, | |
.init = kr_ops_info_init, | |
.valid = kr_ops_info_valid, | |
.random = kr_ops_info_random, | |
@@ -658,6 +672,7 @@ static const kr_info_functions_spec info_functions[] = { | |
.size = sizeof(kr_mt_info), | |
.to_text = kr_mt_info_to_text, | |
.pack_json = kr_mt_info_pack_json, | |
+ .unpack_json = kr_mt_info_unpack_json, | |
.init = kr_mt_info_init, | |
.valid = kr_mt_info_valid, | |
.random = kr_mt_info_random, | |
@@ -667,6 +682,8 @@ static const kr_info_functions_spec info_functions[] = { | |
[KR_VALGRIND_STRESSOR_INFO] = { | |
.size = sizeof(struct kr_valgrind_stressor_info), | |
.to_text = kr_valgrind_stressor_info_to_text, | |
+ .pack_json = kr_valgrind_stressor_info_pack_json, | |
+ .unpack_json = kr_valgrind_stressor_info_unpack_json, | |
.init = kr_valgrind_stressor_info_init, | |
.valid = kr_valgrind_stressor_info_valid, | |
.random = kr_valgrind_stressor_info_random, | |
diff --git a/lib/gen/wrappers.c b/lib/gen/wrappers.c | |
index 5345e80..01fb1a8 100644 | |
--- a/lib/gen/wrappers.c | |
+++ b/lib/gen/wrappers.c | |
@@ -104,21 +104,36 @@ | |
#include "../system/gen/types_helpers.c" | |
#include "../tasks/avconv/gen/types_to_text.c" | |
#include "../tasks/avconv/gen/types_helpers.c" | |
+#include "../tasks/avconv/gen/types_to_json.c" | |
+#include "../tasks/avconv/gen/types_from_json.c" | |
#include "../tasks/curl/gen/types_to_text.c" | |
#include "../tasks/curl/gen/types_helpers.c" | |
+#include "../tasks/curl/gen/types_to_json.c" | |
+#include "../tasks/curl/gen/types_from_json.c" | |
#include "../tasks/livestreamer/gen/types_to_text.c" | |
#include "../tasks/livestreamer/gen/types_helpers.c" | |
+#include "../tasks/livestreamer/gen/types_to_json.c" | |
+#include "../tasks/livestreamer/gen/types_from_json.c" | |
#include "../tasks/quvi/gen/types_to_text.c" | |
#include "../tasks/quvi/gen/types_helpers.c" | |
+#include "../tasks/quvi/gen/types_to_json.c" | |
+#include "../tasks/quvi/gen/types_from_json.c" | |
#include "../tasks/test/gen/types_to_text.c" | |
#include "../tasks/test/gen/types_helpers.c" | |
+#include "../tasks/test/gen/types_to_json.c" | |
+#include "../tasks/test/gen/types_from_json.c" | |
#include "../tasks/transmission_cli/gen/types_to_text.c" | |
#include "../tasks/transmission_cli/gen/types_helpers.c" | |
+#include "../tasks/transmission_cli/gen/types_to_json.c" | |
+#include "../tasks/transmission_cli/gen/types_from_json.c" | |
#include "../tasks/gen/types_to_text.c" | |
#include "../tasks/gen/types_helpers.c" | |
#include "../tasks/gen/types_to_json.c" | |
+#include "../tasks/gen/types_from_json.c" | |
#include "../tasks/valgrind_stressor/gen/types_to_text.c" | |
#include "../tasks/valgrind_stressor/gen/types_helpers.c" | |
+#include "../tasks/valgrind_stressor/gen/types_to_json.c" | |
+#include "../tasks/valgrind_stressor/gen/types_from_json.c" | |
#include "../time/gen/types_to_json.c" | |
#include "../time/gen/types_from_json.c" | |
#include "../time/gen/types_to_ebml.c" | |
diff --git a/lib/tasks/avconv/types.h b/lib/tasks/avconv/types.h | |
index b9dad9f..b16626f 100644 | |
--- a/lib/tasks/avconv/types.h | |
+++ b/lib/tasks/avconv/types.h | |
@@ -10,5 +10,7 @@ typedef struct kr_avconv_info { | |
#include "gen/types_to_text.h" | |
#include "gen/types_helpers.h" | |
+#include "gen/types_to_json.h" | |
+#include "gen/types_from_json.h" | |
#endif | |
diff --git a/lib/tasks/curl/types.h b/lib/tasks/curl/types.h | |
index d42033f..afa423c 100644 | |
--- a/lib/tasks/curl/types.h | |
+++ b/lib/tasks/curl/types.h | |
@@ -11,5 +11,7 @@ typedef struct kr_curl_info { | |
#include "gen/types_to_text.h" | |
#include "gen/types_helpers.h" | |
+#include "gen/types_to_json.h" | |
+#include "gen/types_from_json.h" | |
#endif | |
diff --git a/lib/tasks/livestreamer/types.h b/lib/tasks/livestreamer/types.h | |
index c56b045..493a3a2 100644 | |
--- a/lib/tasks/livestreamer/types.h | |
+++ b/lib/tasks/livestreamer/types.h | |
@@ -10,5 +10,7 @@ typedef struct kr_livestreamer_info { | |
#include "gen/types_to_text.h" | |
#include "gen/types_helpers.h" | |
+#include "gen/types_to_json.h" | |
+#include "gen/types_from_json.h" | |
#endif | |
diff --git a/lib/tasks/quvi/types.h b/lib/tasks/quvi/types.h | |
index 0079ed0..f883b69 100644 | |
--- a/lib/tasks/quvi/types.h | |
+++ b/lib/tasks/quvi/types.h | |
@@ -9,5 +9,7 @@ typedef struct kr_quvi_info { | |
#include "gen/types_to_text.h" | |
#include "gen/types_helpers.h" | |
+#include "gen/types_to_json.h" | |
+#include "gen/types_from_json.h" | |
#endif | |
diff --git a/lib/tasks/test/types.h b/lib/tasks/test/types.h | |
index 4258b22..1119c9c 100644 | |
--- a/lib/tasks/test/types.h | |
+++ b/lib/tasks/test/types.h | |
@@ -7,5 +7,7 @@ typedef struct kr_test_task_info { | |
#include "gen/types_to_text.h" | |
#include "gen/types_helpers.h" | |
+#include "gen/types_to_json.h" | |
+#include "gen/types_from_json.h" | |
#endif | |
diff --git a/lib/tasks/transmission_cli/types.h b/lib/tasks/transmission_cli/types.h | |
index 2864fc7..2f3cbde 100644 | |
--- a/lib/tasks/transmission_cli/types.h | |
+++ b/lib/tasks/transmission_cli/types.h | |
@@ -9,5 +9,7 @@ typedef struct kr_transmission_cli_info { | |
#include "gen/types_to_text.h" | |
#include "gen/types_helpers.h" | |
+#include "gen/types_to_json.h" | |
+#include "gen/types_from_json.h" | |
#endif | |
diff --git a/lib/tasks/types.h b/lib/tasks/types.h | |
index c95b46d..fedc5c9 100644 | |
--- a/lib/tasks/types.h | |
+++ b/lib/tasks/types.h | |
@@ -119,5 +119,6 @@ typedef struct { | |
#include "gen/types_to_text.h" | |
#include "gen/types_helpers.h" | |
#include "gen/types_to_json.h" | |
+#include "gen/types_from_json.h" | |
#endif | |
diff --git a/lib/tasks/valgrind_stressor/types.h b/lib/tasks/valgrind_stressor/types.h | |
index a6a2557..6cb6226 100644 | |
--- a/lib/tasks/valgrind_stressor/types.h | |
+++ b/lib/tasks/valgrind_stressor/types.h | |
@@ -5,5 +5,7 @@ typedef struct kr_valgrind_stressor_info { | |
#include "gen/types_to_text.h" | |
#include "gen/types_helpers.h" | |
+#include "gen/types_to_json.h" | |
+#include "gen/types_from_json.h" | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment