mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 02:40:00 +01:00
Creation of the Connection Manager : this new mechanism continuously
checks for the presence of vimix programs in the network neibourhood. The list of connections can then be used for indentifying streaming requests and offers.
This commit is contained in:
90
Connection.h
Normal file
90
Connection.h
Normal file
@@ -0,0 +1,90 @@
|
||||
#ifndef CONNECTION_H
|
||||
#define CONNECTION_H
|
||||
|
||||
#include "osc/OscReceivedElements.h"
|
||||
#include "osc/OscPacketListener.h"
|
||||
#include "ip/UdpSocket.h"
|
||||
|
||||
#include "NetworkToolkit.h"
|
||||
|
||||
class ConnectionRequestListener : public osc::OscPacketListener {
|
||||
|
||||
protected:
|
||||
virtual void ProcessMessage( const osc::ReceivedMessage& m,
|
||||
const IpEndpointName& remoteEndpoint );
|
||||
};
|
||||
|
||||
struct ConnectionInfo {
|
||||
|
||||
std::string address_;
|
||||
int port_handshake;
|
||||
int port_stream_send;
|
||||
int port_stream_receive;
|
||||
int status;
|
||||
|
||||
ConnectionInfo () {
|
||||
address_ = "localhost";
|
||||
port_handshake = HANDSHAKE_PORT;
|
||||
port_stream_send = STREAM_REQUEST_PORT;
|
||||
port_stream_receive = STREAM_RESPONSE_PORT;
|
||||
status = 0;
|
||||
}
|
||||
|
||||
inline ConnectionInfo& operator = (const ConnectionInfo& o)
|
||||
{
|
||||
if (this != &o) {
|
||||
this->address_ = o.address_;
|
||||
this->port_handshake = o.port_handshake;
|
||||
this->port_stream_send = o.port_stream_send;
|
||||
this->port_stream_receive = o.port_stream_receive;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool operator == (const ConnectionInfo& o) const
|
||||
{
|
||||
return this->address_.compare(o.address_) == 0
|
||||
&& this->port_handshake == o.port_handshake;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Connection
|
||||
{
|
||||
friend class ConnectionRequestListener;
|
||||
|
||||
// Private Constructor
|
||||
Connection();
|
||||
Connection(Connection const& copy); // Not Implemented
|
||||
Connection& operator=(Connection const& copy); // Not Implemented
|
||||
|
||||
public:
|
||||
static Connection& manager()
|
||||
{
|
||||
// The only instance
|
||||
static Connection _instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
bool init();
|
||||
void terminate();
|
||||
|
||||
int numHosts () const;
|
||||
int index(ConnectionInfo i) const;
|
||||
ConnectionInfo info(int index = 0); // index 0 for self
|
||||
|
||||
private:
|
||||
|
||||
std::string hostname_;
|
||||
|
||||
static void ask();
|
||||
static void listen();
|
||||
ConnectionRequestListener listener_;
|
||||
UdpListeningReceiveSocket *receiver_;
|
||||
|
||||
std::vector< ConnectionInfo > connections_;
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
#endif // CONNECTION_H
|
||||
Reference in New Issue
Block a user