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.

80 lines
2.9KB

  1. #ifndef TSOSCCOMMUNICATOR_HPP
  2. #define TSOSCCOMMUNICATOR_HPP
  3. #include <thread> // std::thread
  4. #include <mutex>
  5. #include <string.h>
  6. //#include <stdio.h>
  7. #include <map>
  8. #include "../lib/oscpack/osc/OscOutboundPacketStream.h"
  9. #include "../lib/oscpack/ip/UdpSocket.h"
  10. #include "../lib/oscpack/osc/OscReceivedElements.h"
  11. #include "../lib/oscpack/osc/OscPacketListener.h"
  12. #include "TSOSCSequencerListener.hpp"
  13. // OSC connection information
  14. typedef struct TSOSCInfo {
  15. // OSC output IP address.
  16. std::string oscTxIpAddress;
  17. // OSC output port number.
  18. uint16_t oscTxPort;
  19. // OSC input port number.
  20. uint16_t oscRxPort;
  21. } TSOSCConnectionInfo;
  22. // OSC Connection / track ports used to try to auto-increment and probably eventually allow multiple guys to talk on the same
  23. // ports just with namespace or id routing.
  24. class TSOSCConnector
  25. {
  26. public:
  27. static TSOSCConnector* Connector();
  28. // Get an id for the module instance.
  29. int getId();
  30. // Register the usage of these ports.
  31. bool registerPorts(int id, uint16_t txPort, uint16_t rxPort);
  32. // Clear the usage of these ports.
  33. bool clearPorts(int id, uint16_t txPort, uint16_t rxPort);
  34. // Register the usage of these ports.
  35. bool registerPort(int id, uint16_t port);
  36. // Clear the usage of these ports.
  37. bool clearPort(int id, uint16_t port);
  38. // Get an available port.
  39. uint16_t getAvailablePort(int id, uint16_t desiredPort);
  40. // See if the port is in use (returns the id of the module using it or 0 if it is free).
  41. int portInUse(uint16_t port);
  42. // Get an id for the module instance.
  43. static int GetId() { return Connector()->getId(); }
  44. // Get an available port.
  45. static uint16_t GetAvailablePort(int id, uint16_t desiredPort) { return Connector()->getAvailablePort(id, desiredPort); }
  46. // Register the usage of these ports.
  47. static bool RegisterPorts(int id, uint16_t txPort, uint16_t rxPort) { return Connector()->registerPorts(id, txPort, rxPort); }
  48. // Clear the usage of these ports.
  49. static bool ClearPorts(int id, uint16_t txPort, uint16_t rxPort) { return Connector()->clearPorts(id, txPort, rxPort);}
  50. // Register the usage of these ports.
  51. static bool RegisterPort(int id, uint16_t port) { return Connector()->registerPort(id, port); }
  52. // Clear the usage of these ports.
  53. static bool ClearPort(int id, uint16_t port) { return Connector()->clearPort(id, port); }
  54. // See if the port is in use (returns the id of the module using it or 0 if it is free).
  55. static int PortInUse(uint16_t port) { return Connector()->portInUse(port); }
  56. private:
  57. TSOSCConnector();
  58. //TSOSCConnector(TSOSCConnector const&) {}; // copy constructor is private
  59. //TSOSCConnector& operator=(TSOSCConnector const&) { return this; }; // assignment operator is private
  60. static TSOSCConnector* _instance;
  61. // The last id we gave out.
  62. int _lastId;
  63. // The ports that are in use by which id.
  64. std::map<uint16_t, int> _portMap;
  65. // Port mutex.
  66. std::mutex _mutex;
  67. };
  68. #endif // !TSOSCCOMMUNICATOR_HPP