aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/skiaserve/urlhandlers
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2016-02-26 08:22:49 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-26 08:22:49 -0800
commit1e5884b066da57a0c5dd9a0f9489b0bb1c3b3c34 (patch)
treeae9dbfd543884e5584217f252770506ca5f39a00 /tools/skiaserve/urlhandlers
parent4ee1cdad526fd8b6bb50d6f9d339b2c782257a8b (diff)
Wire up /batches in skiaserve
Diffstat (limited to 'tools/skiaserve/urlhandlers')
-rw-r--r--tools/skiaserve/urlhandlers/BatchesHandler.cpp41
-rw-r--r--tools/skiaserve/urlhandlers/CmdHandler.cpp8
-rw-r--r--tools/skiaserve/urlhandlers/UrlHandler.h11
3 files changed, 57 insertions, 3 deletions
diff --git a/tools/skiaserve/urlhandlers/BatchesHandler.cpp b/tools/skiaserve/urlhandlers/BatchesHandler.cpp
new file mode 100644
index 0000000000..221c5393c7
--- /dev/null
+++ b/tools/skiaserve/urlhandlers/BatchesHandler.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "UrlHandler.h"
+
+#include "microhttpd.h"
+#include "../Request.h"
+#include "../Response.h"
+
+using namespace Response;
+
+bool BatchesHandler::canHandle(const char* method, const char* url) {
+ const char* kBasePath = "/batches";
+ return 0 == strncmp(url, kBasePath, strlen(kBasePath));
+}
+
+int BatchesHandler::handle(Request* request, MHD_Connection* connection,
+ const char* url, const char* method,
+ const char* upload_data, size_t* upload_data_size) {
+ SkTArray<SkString> commands;
+ SkStrSplit(url, "/", &commands);
+
+ if (!request->hasPicture() || commands.count() > 1) {
+ return MHD_NO;
+ }
+
+ // /batches
+ if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) {
+ int n = request->getLastOp();
+
+ SkAutoTUnref<SkData> data(request->getJsonBatchList(n));
+ return SendData(connection, data, "application/json");
+ }
+
+ return MHD_NO;
+}
+
diff --git a/tools/skiaserve/urlhandlers/CmdHandler.cpp b/tools/skiaserve/urlhandlers/CmdHandler.cpp
index c741eb9a43..1699bcbcfc 100644
--- a/tools/skiaserve/urlhandlers/CmdHandler.cpp
+++ b/tools/skiaserve/urlhandlers/CmdHandler.cpp
@@ -24,7 +24,7 @@ int CmdHandler::handle(Request* request, MHD_Connection* connection,
SkTArray<SkString> commands;
SkStrSplit(url, "/", &commands);
- if (!request->fPicture.get() || commands.count() > 3) {
+ if (!request->hasPicture() || commands.count() > 3) {
return MHD_NO;
}
@@ -32,11 +32,13 @@ int CmdHandler::handle(Request* request, MHD_Connection* connection,
if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) {
int n;
if (commands.count() == 1) {
- n = request->fDebugCanvas->getSize() - 1;
+ n = request->getLastOp();
} else {
sscanf(commands[1].c_str(), "%d", &n);
}
- return SendJSON(connection, request, n);
+
+ SkAutoTUnref<SkData> data(request->getJsonOps(n));
+ return SendData(connection, data, "application/json");
}
// /cmd/N, for now only delete supported
diff --git a/tools/skiaserve/urlhandlers/UrlHandler.h b/tools/skiaserve/urlhandlers/UrlHandler.h
index 9eee35f489..28d378aaf9 100644
--- a/tools/skiaserve/urlhandlers/UrlHandler.h
+++ b/tools/skiaserve/urlhandlers/UrlHandler.h
@@ -101,6 +101,17 @@ public:
const char* upload_data, size_t* upload_data_size) override;
};
+/*
+ * Returns a json descripton of all the batches in the image
+ */
+class BatchesHandler : public UrlHandler {
+public:
+ bool canHandle(const char* method, const char* url) override;
+ int handle(Request* request, MHD_Connection* connection,
+ const char* url, const char* method,
+ const char* upload_data, size_t* upload_data_size) override;
+};
+
class RootHandler : public UrlHandler {
public:
bool canHandle(const char* method, const char* url) override;