BaseMonitor.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #pragma once
  2. #include <CrossPlatformDefine/PlatformDef.h>
  3. #include <CrossPlatformDefine/XErrorCode.h>
  4. #include <memory>
  5. #ifdef XPHONE_STATIC
  6. #define XPHONEDLL_API
  7. #else
  8. #ifdef XPHONEDLL_EXPORTS
  9. #define XPHONEDLL_API __declspec(dllexport)
  10. #else
  11. #define XPHONEDLL_API __declspec(dllimport)
  12. #endif // XPHONEDLL_EXPORTS
  13. #endif // XPHONE_STATIC
  14. enum XConnectMode
  15. {
  16. XConnectMode_USB,
  17. XConnectMode_WIFI
  18. };
  19. enum XDeviceChange
  20. {
  21. XDeviceChange_Unknow = 0,
  22. XDeviceChange_Add = 1,
  23. XDeviceChange_Remove = 2,
  24. };
  25. struct XDeviceInfo
  26. {
  27. XString szIdentify;
  28. XString szDeviceName;
  29. XString szResolution;
  30. XString szBrand;
  31. XString szIMEI;
  32. XString szModel;
  33. };
  34. //屏幕回显的回掉
  35. class IXPhoneScreenShow
  36. {
  37. public:
  38. //回掉屏幕的数据,一个完整的PNG 图像,包括PNG 头
  39. virtual void OnScreenShow(const byte* buffer, int iBufferLen) = 0;
  40. };
  41. //手机端发过来的主动TCP 信息
  42. class IXPhoneCommonRecvMsg
  43. {
  44. public:
  45. virtual void OnRecvTcpMsg(const XString& strDeviceIdentify, const byte* buffer, int iBufferLen) = 0;
  46. virtual void OnCommonDisconnect(const XString& strDeviceIdentify) = 0;
  47. };
  48. class IXPhoneDevice
  49. {
  50. public:
  51. virtual ~IXPhoneDevice();
  52. //获取设备唯一标识符
  53. virtual XString GetIdentify() = 0;//获取设备唯一标识
  54. virtual XConnectMode GetConnectMode() = 0;//获取连接模式
  55. //0 正常模式 1 简易模式
  56. virtual XErrorcode ConnectToDevice() = 0;//链接设备
  57. virtual XErrorcode DisConnectDevice() = 0;//断开设备连接
  58. virtual XErrorcode GetDeviceInfo(XDeviceInfo& deviceInfo, bool bStartCapture) = 0;//获取设备信息
  59. //设置屏幕回显回掉
  60. virtual XErrorcode SetScreenShowCallback(IXPhoneScreenShow* pCallback) = 0;
  61. //设备操作
  62. virtual XErrorcode RestartDevice() = 0;//重启设备
  63. virtual XErrorcode ExecuteHomeCommand() = 0;//模拟按下手机的HOME 按键
  64. virtual XErrorcode ExecuteBackCommand() = 0;//模拟按下手机的Back 按键
  65. virtual XErrorcode ExecuteMenuCommand() = 0;//模拟按下手机的Menu 按键
  66. //提供一个adb 命令
  67. virtual XErrorcode ExecuteAdbCommand(const XString&strAdbCommand, XString& strResult) = 0;
  68. //安装应用接口
  69. virtual XErrorcode InstallApp(const XString &strSrcPath) = 0;
  70. virtual XErrorcode UnInstallApp(const XString &strPackageName) = 0;
  71. //屏幕触摸接口
  72. virtual XErrorcode ScreenTouchDown(int x, int y) = 0;
  73. virtual XErrorcode ScreenTouchUp(int x, int y) = 0;
  74. virtual XErrorcode ScreenTouchMove(int x, int y) = 0;
  75. //脚本录制
  76. virtual XErrorcode StartRecord() = 0;
  77. virtual XErrorcode StopRecord(const XString& strSavePath) = 0;
  78. virtual XErrorcode PlayRecord(const XString& strSavepath,bool* pbStop) = 0;
  79. //文本输入
  80. virtual XErrorcode InputText(const XString& strText) = 0;
  81. virtual XErrorcode SwitchIME() = 0;
  82. virtual XErrorcode ExecuteDelCommand() =0;
  83. //普通TCP 消息回掉
  84. virtual XErrorcode SetCommonTcpMsgCallback(IXPhoneCommonRecvMsg* pCallback) = 0;
  85. virtual XErrorcode SendCommonTcpMSG(const byte* buffer, int iBufferLen) = 0;
  86. //切换到前台
  87. virtual XErrorcode SwitchForground() = 0;
  88. };
  89. class IXPhoneDeviceEvent
  90. {
  91. public:
  92. virtual void XPhoneDeviceChanged(
  93. /* [in] */ std::shared_ptr<IXPhoneDevice> pXPhoneDevice,
  94. /* [in] */ enum XDeviceChange changeType) = 0;
  95. };
  96. //所有监视器基类
  97. class XPHONEDLL_API IXPhoneMonitorAddin
  98. {
  99. public:
  100. virtual ~IXPhoneMonitorAddin();
  101. //初始化
  102. virtual XErrorcode Init(IXPhoneDeviceEvent* pXPhoneEvent) = 0;
  103. //反初始化
  104. virtual void UnInit() = 0;
  105. //开始监听
  106. virtual XErrorcode StartListen( void) = 0;
  107. virtual XErrorcode GetWifiConnectParam(std::string& strIP, int& iPort)=0;
  108. static IXPhoneMonitorAddin* CreateInstance();
  109. static void DestroyInstance(IXPhoneMonitorAddin* pInstance);
  110. //提供一个静态函数,用来执行adb 命令
  111. static XString ExecuteAdbCommand(const XString& strCommand);
  112. };