PlayerControl.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef __PLAYERCONTROL_H_
  2. #define __PLAYERCONTROL_H_
  3. #include <iostream>
  4. #include <rapidjson/document.h>
  5. #include <rapidjson/rapidjson.h>
  6. #include <rapidjson/stringbuffer.h>
  7. #include <rapidjson/writer.h>
  8. #include <vector>
  9. class PlayerCommand
  10. {
  11. public:
  12. std::string device;
  13. std::string ctype;
  14. std::string param;
  15. public:
  16. PlayerCommand() {}
  17. ~PlayerCommand() {}
  18. void objectToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer){
  19. writer.StartObject();
  20. writer.Key("device");
  21. writer.String(device.c_str());
  22. writer.Key("ctype");
  23. writer.String(ctype.c_str());
  24. writer.Key("param");
  25. writer.String(param.c_str());
  26. writer.EndObject();
  27. }
  28. };
  29. class PlayerControl
  30. {
  31. public:
  32. std::string URL = "/qxsbr360xs.do";
  33. public:
  34. std::string cid;
  35. std::string cname;
  36. std::string dtype;
  37. std::string did;
  38. vector<PlayerCommand> command;
  39. public:
  40. PlayerControl() {}
  41. ~PlayerControl() {}
  42. void setURL(std::string url){
  43. this->URL = url;
  44. }
  45. std::string getUrl(){
  46. return this->URL;
  47. }
  48. void objectToJson(std::string& str){
  49. rapidjson::StringBuffer strBuf;
  50. rapidjson::Writer<rapidjson::StringBuffer> writer(strBuf);
  51. this->objectToJson(writer);
  52. str = strBuf.GetString();
  53. }
  54. void objectToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer){
  55. writer.StartObject();
  56. writer.Key("cid");
  57. writer.String(cid.c_str());
  58. writer.Key("cname");
  59. writer.String(cname.c_str());
  60. writer.Key("dtype");
  61. writer.String(dtype.c_str());
  62. writer.Key("did");
  63. writer.String(did.c_str());
  64. writer.Key("command");
  65. writer.StartArray();
  66. for(auto iter = command.begin(); iter != command.end(); iter++){
  67. iter->objectToJson(writer);
  68. }
  69. writer.EndArray();
  70. writer.EndObject();
  71. }
  72. };
  73. #endif