PlayerControl.h 1.9 KB

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