connection.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "defs.h"
  3. #include "message.h"
  4. #include <util/generic/ptr.h>
  5. namespace NBus {
  6. struct TBusClientConnection {
  7. /// if you want to open connection early
  8. virtual void OpenConnection() = 0;
  9. /// Send message to the destination
  10. /// If addr is set then use it as destination.
  11. /// Takes ownership of addr (see ClearState method).
  12. virtual EMessageStatus SendMessage(TBusMessage* pMes, bool wait = false) = 0;
  13. virtual EMessageStatus SendMessageOneWay(TBusMessage* pMes, bool wait = false) = 0;
  14. /// Like SendMessage but cares about message
  15. template <typename T /* <: TBusMessage */>
  16. EMessageStatus SendMessageAutoPtr(const TAutoPtr<T>& mes, bool wait = false) {
  17. EMessageStatus status = SendMessage(mes.Get(), wait);
  18. if (status == MESSAGE_OK)
  19. Y_UNUSED(mes.Release());
  20. return status;
  21. }
  22. /// Like SendMessageOneWay but cares about message
  23. template <typename T /* <: TBusMessage */>
  24. EMessageStatus SendMessageOneWayAutoPtr(const TAutoPtr<T>& mes, bool wait = false) {
  25. EMessageStatus status = SendMessageOneWay(mes.Get(), wait);
  26. if (status == MESSAGE_OK)
  27. Y_UNUSED(mes.Release());
  28. return status;
  29. }
  30. EMessageStatus SendMessageMove(TBusMessageAutoPtr message, bool wait = false) {
  31. return SendMessageAutoPtr(message, wait);
  32. }
  33. EMessageStatus SendMessageOneWayMove(TBusMessageAutoPtr message, bool wait = false) {
  34. return SendMessageOneWayAutoPtr(message, wait);
  35. }
  36. // TODO: implement similar one-way methods
  37. virtual ~TBusClientConnection() {
  38. }
  39. };
  40. namespace NPrivate {
  41. struct TBusClientConnectionPtrOps {
  42. static void Ref(TBusClientConnection*);
  43. static void UnRef(TBusClientConnection*);
  44. };
  45. }
  46. using TBusClientConnectionPtr = TIntrusivePtr<TBusClientConnection, NPrivate::TBusClientConnectionPtrOps>;
  47. }