i_engine.hpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
  3. This file is part of libzmq, the ZeroMQ core engine in C++.
  4. libzmq is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU Lesser General Public License (LGPL) as published
  6. by the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. As a special exception, the Contributors give you permission to link
  9. this library with independent modules to produce an executable,
  10. regardless of the license terms of these independent modules, and to
  11. copy and distribute the resulting executable under terms of your choice,
  12. provided that you also meet, for each linked independent module, the
  13. terms and conditions of the license of that module. An independent
  14. module is a module which is not derived from or based on this library.
  15. If you modify this library, you must extend this exception to your
  16. version of the library.
  17. libzmq is distributed in the hope that it will be useful, but WITHOUT
  18. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  20. License for more details.
  21. You should have received a copy of the GNU Lesser General Public License
  22. along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #ifndef __ZMQ_I_ENGINE_HPP_INCLUDED__
  25. #define __ZMQ_I_ENGINE_HPP_INCLUDED__
  26. #include "endpoint.hpp"
  27. #include "macros.hpp"
  28. namespace zmq
  29. {
  30. class io_thread_t;
  31. // Abstract interface to be implemented by various engines.
  32. struct i_engine
  33. {
  34. enum error_reason_t
  35. {
  36. protocol_error,
  37. connection_error,
  38. timeout_error
  39. };
  40. virtual ~i_engine () ZMQ_DEFAULT;
  41. // Indicate if the engine has an handshake stage.
  42. // If engine has handshake stage, engine must call session.engine_ready when the handshake is complete.
  43. virtual bool has_handshake_stage () = 0;
  44. // Plug the engine to the session.
  45. virtual void plug (zmq::io_thread_t *io_thread_,
  46. class session_base_t *session_) = 0;
  47. // Terminate and deallocate the engine. Note that 'detached'
  48. // events are not fired on termination.
  49. virtual void terminate () = 0;
  50. // This method is called by the session to signalise that more
  51. // messages can be written to the pipe.
  52. // Returns false if the engine was deleted due to an error.
  53. // TODO it is probably better to change the design such that the engine
  54. // does not delete itself
  55. virtual bool restart_input () = 0;
  56. // This method is called by the session to signalise that there
  57. // are messages to send available.
  58. virtual void restart_output () = 0;
  59. virtual void zap_msg_available () = 0;
  60. virtual const endpoint_uri_pair_t &get_endpoint () const = 0;
  61. };
  62. }
  63. #endif