Shim.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * This software is released under the MIT License.
  3. * https://opensource.org/licenses/MIT
  4. *
  5. */
  6. #pragma once
  7. #include <vector>
  8. #include <iostream>
  9. #include <map>
  10. #include "AudioSink.h"
  11. #include "FileHelper.h"
  12. #include "BaseHTTPServer.h"
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <sys/unistd.h>
  16. #include <sys/stat.h>
  17. #include "esp_err.h"
  18. #include "esp_http_server.h"
  19. #include "esp_log.h"
  20. class ShimAudioSink : public AudioSink {
  21. public:
  22. ShimAudioSink(void) { softwareVolumeControl = false; }
  23. void feedPCMFrames(const uint8_t *data, size_t bytes);
  24. virtual void volumeChanged(uint16_t volume);
  25. };
  26. class NVSFile : public FileHelper {
  27. private:
  28. std::map<std::string, std::string> files;
  29. public:
  30. bool readFile(std::string filename, std::string &fileContent);
  31. bool writeFile(std::string filename, std::string fileContent);
  32. bool flush();
  33. };
  34. class ShimHTTPServer : public bell::BaseHTTPServer {
  35. private:
  36. httpd_handle_t serverHandle;
  37. bell::httpHandler uriHandlers[4];
  38. public:
  39. ShimHTTPServer(httpd_handle_t server, int port) { serverHandle = server; serverPort = port; }
  40. void registerHandler(bell::RequestType requestType, const std::string &, bell::httpHandler, bool readDataToStr = false);
  41. void respond(const bell::HTTPResponse &);
  42. };