Exemplo n.º 1
0
void Node::coalesce()
{
    printf("%sCoalescing %c at (%d,%d)\n", indent(), color() + 'A', x(), y());
    std::shared_ptr<Node> sharedThis = shared_from_this();

    NodeList adjacents = adjacentNodes_; // Copy the list so we can modify it as we iterate through it
    for (NodeList::iterator i = adjacents.begin(); i != adjacents.end(); ++i)
    {
        std::shared_ptr<Node> const & aNode = *i;
        if (color_ == aNode->color())
        {
            // Disconnect the adjacent node from everyone and connect this node to its adjacent nodes
            for (NodeList::iterator i2 = aNode->adjacentNodes_.begin(); i2 != aNode->adjacentNodes_.end(); ++i2)
            {
                std::shared_ptr<Node> const & aaNode = *i2;
                printf("%sDisconnecting %c at (%d,%d) from %c at (%d,%d)\n",
                    indent(),
                    aNode->color() + 'A',
                    aNode->x(),
                    aNode->y(),
                    aaNode->color() + 'A',
                    aaNode->x(),
                    aaNode->y());

                // Disconnect the adjacent-adjacent node (which might be this node) from the adjacent node
                aaNode->disconnect(aNode);

                // If the adjacent-adjacent node is not this node and is not already connected to this node,
                // then connect it
                if (aaNode.get() != this && !connectedTo(aaNode))
                {
                    printf("%sConnecting %c at (%d,%d) to %c at (%d,%d)\n",
                        indent(),
                        aaNode->color() + 'A',
                        aaNode->x(),
                        aaNode->y(),
                        color() + 'A',
                        x(),
                        y());
                    connect(aaNode);
                    aaNode->connect(sharedThis);
                }
            }
            // At this point, the adjacent node is only referenced by the copied list and will be deleted when
            // the list goes out of scope
        }
    }
}
Exemplo n.º 2
0
MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow),
	logic(this),
	connectDialog(new ZeroconfConnectDialog(this)),
	ipConnectDialog(new IPConnectDialog(this))
{
	ui->setupUi(this);

	ui->centralwidget->setClientLogic(&logic);
/*
	connect(connectDialog, SIGNAL(connectedTo(QHostAddress,quint16)),
			this,		   SLOT(newServerConnection(QHostAddress,quint16)));
*/
	connect(ipConnectDialog, SIGNAL(setLocalAddress(QHostAddress)),
			&logic,			 SLOT(setLocalAddress(QHostAddress)));

	connect(ipConnectDialog, SIGNAL(connectedTo(QHostAddress,quint16)),
			this,		   SLOT(newServerConnection(QHostAddress,quint16)));



	connect(ui->centralwidget, SIGNAL(take(QString)),
			this,			   SLOT(takeNode(QString)));

	connect(ui->centralwidget, SIGNAL(give(QString)),
			this,			   SLOT(giveNode(QString)));

	connect(&logic,			   SIGNAL(serverPoolChanged()),
			ui->centralwidget, SLOT(updateServerPool()));

	connect(&logic,			   SIGNAL(localPoolChanged()),
			ui->centralwidget, SLOT(updateLocalPool()));

	connect(&logic,			   SIGNAL(sendLog(QString)),
			ui->centralwidget, SLOT(addLog(QString)));
}
Exemplo n.º 3
0
void BmNetworkTCPClient::connectionSet()
{
    mIsConnected = true;
    emit connectedTo( mSocket->peerName() );
}