MumbleCommunicator.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include <mumlib.hpp>
  3. #include <log4cpp/Category.hh>
  4. #include <boost/noncopyable.hpp>
  5. #include <string>
  6. #include <stdexcept>
  7. namespace mumble {
  8. class Exception : public std::runtime_error {
  9. public:
  10. Exception(const char *message) : std::runtime_error(message) { }
  11. };
  12. class MumlibCallback;
  13. class MumbleCommunicator : boost::noncopyable {
  14. public:
  15. MumbleCommunicator(
  16. boost::asio::io_service &ioService);
  17. void connect(
  18. std::string user,
  19. std::string password,
  20. std::string host,
  21. int port = 0);
  22. virtual ~MumbleCommunicator();
  23. void sendPcmSamples(int16_t *samples, unsigned int length);
  24. /**
  25. * This callback is called when communicator has received samples.
  26. * Arguments: session ID, sequence number, PCM samples, length of samples
  27. */
  28. std::function<void(int, int, int16_t *, int)> onIncomingPcmSamples;
  29. /**
  30. * This callback is called when a channel state message (e.g. Channel
  31. * information) is received. Arguments: channel_id, name
  32. */
  33. std::function<void(std::string, int)> onIncomingChannelState;
  34. std::function<void()> onServerSync;
  35. void sendTextMessage(std::string message);
  36. void joinChannel(int channel_id);
  37. public:
  38. boost::asio::io_service &ioService;
  39. log4cpp::Category &logger;
  40. std::shared_ptr<mumlib::Mumlib> mum;
  41. std::unique_ptr<MumlibCallback> callback;
  42. friend class MumlibCallback;
  43. };
  44. }