You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB

4 months ago
  1. /*
  2. * IXConnectionState.h
  3. * Author: Benjamin Sergeant
  4. * Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
  5. */
  6. #pragma once
  7. #include <atomic>
  8. #include <functional>
  9. #include <memory>
  10. #include <stdint.h>
  11. #include <string>
  12. namespace ix
  13. {
  14. using OnSetTerminatedCallback = std::function<void()>;
  15. class ConnectionState
  16. {
  17. public:
  18. ConnectionState();
  19. virtual ~ConnectionState() = default;
  20. virtual void computeId();
  21. virtual const std::string& getId() const;
  22. void setTerminated();
  23. bool isTerminated() const;
  24. const std::string& getRemoteIp();
  25. int getRemotePort();
  26. static std::shared_ptr<ConnectionState> createConnectionState();
  27. private:
  28. void setOnSetTerminatedCallback(const OnSetTerminatedCallback& callback);
  29. void setRemoteIp(const std::string& remoteIp);
  30. void setRemotePort(int remotePort);
  31. protected:
  32. std::atomic<bool> _terminated;
  33. std::string _id;
  34. OnSetTerminatedCallback _onSetTerminatedCallback;
  35. static std::atomic<uint64_t> _globalId;
  36. std::string _remoteIp;
  37. int _remotePort;
  38. friend class SocketServer;
  39. };
  40. } // namespace ix