bef_effect_ai_license_wrapper.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #include "bef_effect_ai_public_define.h"
  3. #include <iostream>
  4. #include <map>
  5. namespace EffectsSDK {
  6. typedef struct RequestInfo{
  7. std::string url;
  8. std::map<std::string, std::string> requestHead;
  9. const char* bodydata;
  10. int bodySize;
  11. void* userdata;
  12. } RequestInfo;
  13. typedef struct ResponseInfo{
  14. int status_code;
  15. std::map<std::string, std::string> responseHead;
  16. char* bodydata;
  17. int bodySize;
  18. void* userdata;
  19. } ResponseInfo;
  20. class HttpRequestProvider
  21. {
  22. public:
  23. virtual bool getRequest(const RequestInfo* request, ResponseInfo& response) = 0;
  24. virtual bool postRequest(const RequestInfo* request, ResponseInfo& response) = 0;
  25. };
  26. typedef struct ErrorInfo {
  27. int errorCode;
  28. std::string errorMsg;
  29. } ErrorInfo;
  30. typedef void (*licenseCallback)(const char* retmsg, int retSize, ErrorInfo error, void* userdata);
  31. /*
  32. params: <mode:license模式,必需, OFFLINE/ONLINE/ACCOUNT 对应 离线/在线/账号>
  33. <licensePath:自定义license路径,不用可不传>
  34. <url:请求的url, 离线模式不需要>
  35. <key: 仅用于在线请求的key,其他模式可不传>
  36. <secret:仅用于在线请求的secret, 其他模式可不传>
  37. <ticket:仅用于账号模式的票据值,其他模式可不传>
  38. <deviceId: 仅用于账号模式的设备id值,其他模式可不传>
  39. */
  40. class LicenseProvider
  41. {
  42. public:
  43. static LicenseProvider* GetInstanceWithParam(const std::map<std::string, std::string>& params, HttpRequestProvider* provider = NULL);
  44. /*
  45. getLicenseWithParams 支持带参数去获取license,也可以提前通过setParam传入参数,这里传空,会去使用提前设置好的参数
  46. 三种模式:
  47. 1.离线模式, 可以不依赖其他参数,licensePath是可选项,固定为同步操作
  48. 2.在线模式, url,key和secret为必需项,licensePath为可选项,其他不需要,本地不存在的话,才会去发起请求,否则直接返回本地license文件
  49. 3.账号模式, url,ticket和deviceId为必需项,其他不需要
  50. params: 用来获取license的参数,这里设置的参数只用来请求,不对原本的参数进行替换
  51. isAsyn: 是否为异步请求,对离线模式无效
  52. callback: 返回结果的回调函数
  53. */
  54. virtual int getLicenseWithParams(const std::map<std::string, std::string>& params, bool isAsyn, licenseCallback callback, void* userdata = NULL) = 0;
  55. /*
  56. updateLicenseWithParams 支持带参数去更新本地的license文件,也可以提前通过setParam传入参数,这里传空,会去使用提前设置好的参数
  57. 仅支持在线模式,url,key和secret为必需项,licensePath为可选项,每次都会去更新本地的license
  58. params: 用来获取license的参数,这里设置的参数只用来请求,不对原本的参数进行替换
  59. isAsyn: 是否为异步请求
  60. callback: 返回结果的回调函数
  61. */
  62. virtual int updateLicenseWithParams(const std::map<std::string, std::string>& params, bool isAsyn, licenseCallback callback, void* userdata = NULL) = 0;
  63. /*
  64. registerHttpProvider 为用户提供网络注入
  65. provider: 用户实现的HttpRequestProvider对象,用户注册之后,网络请求部分会使用用户的实现
  66. */
  67. virtual void registerHttpProvider(HttpRequestProvider* provider) = 0;
  68. /*
  69. setParam 设置参数
  70. name: 参数名
  71. value: 参数值
  72. */
  73. virtual void setParam(const std::string& name, const std::string& value) = 0;
  74. virtual std::string getParam(const std::string& name) = 0;
  75. virtual void clearParams() = 0;
  76. };
  77. }
  78. BEF_SDK_API EffectsSDK::LicenseProvider* bef_effect_ai_get_license_wrapper_instance();