eBus.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. // 下列 ifdef 块是创建使从 DLL 导出更简单的
  3. // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 EBUS_EXPORTS
  4. // 符号编译的。在使用此 DLL 的
  5. // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
  6. // EBUS_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
  7. // 符号视为是被导出的。
  8. #ifndef EBUS_EXPORTS
  9. #ifdef _WIN64
  10. #ifdef _DEBUG
  11. #pragma comment(lib, "eBusX64D.lib")
  12. #else
  13. #pragma comment(lib, "eBusX64.lib")
  14. #endif
  15. #else
  16. #ifdef _DEBUG
  17. #pragma comment(lib, "eBusD.lib")
  18. #else
  19. #pragma comment(lib, "eBus.lib")
  20. #endif
  21. #endif
  22. #endif
  23. #ifdef EBUS_EXPORTS
  24. #define EBUS_API __declspec(dllexport)
  25. #define EBUS_C_API extern "C" __declspec(dllexport)
  26. #else
  27. #define EBUS_API __declspec(dllimport)
  28. #define EBUS_C_API extern "C" __declspec(dllimport)
  29. #endif
  30. #include "DeviceBus.h"
  31. #define EBUS_CONNECTION_LOCAL ("Local")
  32. #define EBUS_CONNECTION_BUSID ("BusId")
  33. #define EBUS_CONNECTION_PORT ("Port")
  34. #define EBUS_CONNECTION_ROUTERIP ("RouterIp")
  35. EBUS_C_API void InitEbusEnv(bool EnableLog);
  36. EBUS_C_API void QuitEbusEnv();
  37. class EBUS_API eBus : public DeviceBUS
  38. {
  39. HANDLE m_pBusService;
  40. bool TryGetConnectOptions(ResDataObject &connection, const char *pKey, ResDataObject &result);
  41. public:
  42. eBus(void);
  43. virtual ~eBus(void);
  44. //Local Connection
  45. //Local:1
  46. //Port:xxx (OPTIONAL)
  47. //srcBusId:BusId
  48. //Ethernet Connection
  49. //Local:0
  50. //Port:xxx (OPTIONAL)
  51. //RouterIp:ipaddress
  52. //srcBusId:BusId
  53. /*
  54. if RouterIp is empty,eBus will find one .
  55. if eBus found more than one,it will fail and return false.
  56. */
  57. virtual bool Connect(ResDataObject &connection);
  58. virtual void DisConnect();
  59. virtual bool IsConnected();
  60. virtual void Quit();
  61. virtual void SetLogPath(const char *pPath);
  62. virtual bool SendSMPacket(const char *pTargetID, const char *pContext, unsigned long long nShareMemID);
  63. virtual bool SendRawPacket(const char *pTargetID, const char *pContext, DWORD ChannelId);
  64. virtual bool SendPacket(const char *pTargetID, const char *pContext, const char *pBlock = NULL, DWORD BlockSize = 0);
  65. virtual void BlobDataArrived(const char *pMsg, unsigned char *pBlockData, DWORD BlockDataLen);
  66. virtual void InitP2P(const char *pszIp, const char *pszLocalBusId, bool AsServer);
  67. virtual void UnRegistThread(DWORD Tid);
  68. };