ColorModeHandler.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "tools/skiaserve/urlhandlers/UrlHandler.h"
  8. #include "microhttpd.h"
  9. #include "tools/skiaserve/Request.h"
  10. #include "tools/skiaserve/Response.h"
  11. using namespace Response;
  12. bool ColorModeHandler::canHandle(const char* method, const char* url) {
  13. static const char* kBasePath = "/colorMode/";
  14. return 0 == strcmp(method, MHD_HTTP_METHOD_POST) &&
  15. 0 == strncmp(url, kBasePath, strlen(kBasePath));
  16. }
  17. int ColorModeHandler::handle(Request* request, MHD_Connection* connection,
  18. const char* url, const char* method,
  19. const char* upload_data, size_t* upload_data_size) {
  20. SkTArray<SkString> commands;
  21. SkStrSplit(url, "/", &commands);
  22. if (commands.count() != 2) {
  23. return MHD_NO;
  24. }
  25. int mode;
  26. if (1 != sscanf(commands[1].c_str(), "%d", &mode)) {
  27. return MHD_NO;
  28. }
  29. bool success = request->setColorMode(mode);
  30. if (!success) {
  31. return SendError(connection, "Unable to create requested surface");
  32. }
  33. return SendOK(connection);
  34. }