mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Defining a name for a Connection
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
#include "Connection.h"
|
||||
#include "Log.h"
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define CONNECTION_DEBUG
|
||||
#endif
|
||||
@@ -39,6 +38,9 @@ bool Connection::init()
|
||||
// through exception runtime if fails
|
||||
receiver_ = new UdpListeningReceiveSocket( IpEndpointName( IpEndpointName::ANY_ADDRESS,
|
||||
connections_[0].port_handshake ), &listener_ );
|
||||
// validate hostname
|
||||
connections_[0].name = APP_NAME "@" + NetworkToolkit::hostname() +
|
||||
"." + std::to_string(connections_[0].port_handshake-HANDSHAKE_PORT);
|
||||
// all good
|
||||
trial = MAX_HANDSHAKE;
|
||||
}
|
||||
@@ -87,11 +89,26 @@ ConnectionInfo Connection::info(int index)
|
||||
}
|
||||
|
||||
|
||||
void Connection::print()
|
||||
struct hasName: public std::unary_function<ConnectionInfo, bool>
|
||||
{
|
||||
for(int i = 0; i<connections_.size(); i++) {
|
||||
Log::Info(" - %s:%d", connections_[i].address_.c_str(), connections_[i].port_handshake);
|
||||
inline bool operator()(const ConnectionInfo elem) const {
|
||||
return (elem.name.compare(_a) == 0);
|
||||
}
|
||||
hasName(std::string a) : _a(a) { }
|
||||
private:
|
||||
std::string _a;
|
||||
};
|
||||
|
||||
|
||||
int Connection::index(const std::string &name) const
|
||||
{
|
||||
int id = -1;
|
||||
|
||||
std::vector<ConnectionInfo>::const_iterator p = std::find_if(connections_.begin(), connections_.end(), hasName(name));
|
||||
if (p != connections_.end())
|
||||
id = std::distance(connections_.begin(), p);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
int Connection::index(ConnectionInfo i) const
|
||||
@@ -105,6 +122,13 @@ int Connection::index(ConnectionInfo i) const
|
||||
return id;
|
||||
}
|
||||
|
||||
void Connection::print()
|
||||
{
|
||||
for(int i = 0; i<connections_.size(); i++) {
|
||||
Log::Info(" - %s %s:%d", connections_[i].name.c_str(), connections_[i].address.c_str(), connections_[i].port_handshake);
|
||||
}
|
||||
}
|
||||
|
||||
void Connection::listen()
|
||||
{
|
||||
#ifdef CONNECTION_DEBUG
|
||||
@@ -187,6 +211,7 @@ void ConnectionRequestListener::ProcessMessage( const osc::ReceivedMessage& m,
|
||||
osc::OutboundPacketStream p( buffer, IP_MTU_SIZE );
|
||||
p.Clear();
|
||||
p << osc::BeginMessage( OSC_PREFIX OSC_PONG );
|
||||
p << Connection::manager().connections_[0].name.c_str();
|
||||
p << Connection::manager().connections_[0].port_handshake;
|
||||
p << Connection::manager().connections_[0].port_stream_send;
|
||||
p << Connection::manager().connections_[0].port_stream_receive;
|
||||
@@ -203,10 +228,11 @@ void ConnectionRequestListener::ProcessMessage( const osc::ReceivedMessage& m,
|
||||
|
||||
// create info struct
|
||||
ConnectionInfo info;
|
||||
info.address_ = remote_ip;
|
||||
info.address = remote_ip;
|
||||
|
||||
// add all ports info
|
||||
osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
|
||||
info.name = std::string( (arg++)->AsString() );
|
||||
info.port_handshake = (arg++)->AsInt32();
|
||||
info.port_stream_send = (arg++)->AsInt32();
|
||||
info.port_stream_receive = (arg++)->AsInt32();
|
||||
|
||||
12
Connection.h
12
Connection.h
@@ -18,34 +18,37 @@ protected:
|
||||
|
||||
struct ConnectionInfo {
|
||||
|
||||
std::string address_;
|
||||
std::string address;
|
||||
int port_handshake;
|
||||
int port_stream_send;
|
||||
int port_stream_receive;
|
||||
std::string name;
|
||||
int alive;
|
||||
|
||||
ConnectionInfo () {
|
||||
address_ = "localhost";
|
||||
address = "127.0.0.1";
|
||||
port_handshake = HANDSHAKE_PORT;
|
||||
port_stream_send = STREAM_REQUEST_PORT;
|
||||
port_stream_receive = STREAM_RESPONSE_PORT;
|
||||
name = "user@localhost";
|
||||
alive = ALIVE;
|
||||
}
|
||||
|
||||
inline ConnectionInfo& operator = (const ConnectionInfo& o)
|
||||
{
|
||||
if (this != &o) {
|
||||
this->address_ = o.address_;
|
||||
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;
|
||||
this->name = o.name;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool operator == (const ConnectionInfo& o) const
|
||||
{
|
||||
return this->address_.compare(o.address_) == 0
|
||||
return this->address.compare(o.address) == 0
|
||||
&& this->port_handshake == o.port_handshake;
|
||||
}
|
||||
|
||||
@@ -73,6 +76,7 @@ public:
|
||||
|
||||
int numHosts () const;
|
||||
int index(ConnectionInfo i) const;
|
||||
int index(const std::string &name) const;
|
||||
ConnectionInfo info(int index = 0); // index 0 for self
|
||||
|
||||
private:
|
||||
|
||||
@@ -156,3 +156,12 @@ std::string NetworkToolkit::closest_host_ip(const std::string &ip)
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
std::string NetworkToolkit::hostname()
|
||||
{
|
||||
char hostname[1024];
|
||||
hostname[1023] = '\0';
|
||||
gethostname(hostname, 1023);
|
||||
|
||||
return std::string(hostname);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ std::vector<std::string> host_ips();
|
||||
bool is_host_ip(const std::string &ip);
|
||||
std::string closest_host_ip(const std::string &ip);
|
||||
|
||||
std::string hostname();
|
||||
|
||||
}
|
||||
|
||||
#endif // NETWORKTOOLKIT_H
|
||||
|
||||
@@ -39,6 +39,7 @@ using namespace std;
|
||||
#include "Log.h"
|
||||
#include "SystemToolkit.h"
|
||||
#include "RenderingManager.h"
|
||||
#include "Connection.h"
|
||||
#include "ActionManager.h"
|
||||
#include "Resource.h"
|
||||
#include "FileDialog.h"
|
||||
@@ -2311,21 +2312,12 @@ void Navigator::RenderNewPannel()
|
||||
new_source_preview_.setSource( Mixer::manager().createSourceDevice(namedev), namedev);
|
||||
}
|
||||
}
|
||||
|
||||
// for (uint n = 0; n < NetworkToolkit::DEFAULT; ++n){
|
||||
// if (ImGui::Selectable( NetworkToolkit::protocol_name[n] )) {
|
||||
// new_source_preview_.setSource( Mixer::manager().createSourceNetwork("192.168.0.30") );
|
||||
// }
|
||||
// }
|
||||
|
||||
for (int d = 0; d < NetworkHosts::manager().numHosts(); ++d){
|
||||
std::string namehost = NetworkHosts::manager().name(d);
|
||||
for (int d = 1; d < Connection::manager().numHosts(); ++d){
|
||||
std::string namehost = Connection::manager().info(d).name;
|
||||
if (ImGui::Selectable( namehost.c_str() )) {
|
||||
|
||||
new_source_preview_.setSource( Mixer::manager().createSourceNetwork(namehost), namehost);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user