Ejemplo n.º 1
0
//============================================================================
//		NMessageServer::SocketDidClose : A socket has been closed.
//----------------------------------------------------------------------------
void NMessageServer::SocketDidClose(NSocket *theSocket, NStatus theErr)
{	NSocket						*clientSocket;
	NClientInfoMapIterator		theIter;



	// Stop the server
	if (theSocket == &mSocket)
		{
		// Remove the clients
		//
		// Closing the client sockets will cause them to call us back (as we are
		// the socket delegate), which will cause us to remove them from the client
		// list).
		do
			{
			// Get the state we need
			mLock.Lock();
				if (mClients.empty())
					clientSocket = NULL;
				else
					clientSocket = mClients.begin()->second.theSocket;
			mLock.Unlock();


			// Remove the client
			if (clientSocket != NULL)
				clientSocket->Close();
			}
		while (clientSocket != NULL);


		// Stop the server
		mStatus = kNServerStopped;
		ServerStopped(theErr);
		}



	// Remove a client
	//
	// The client may not have been accepted by the server, so we may not actually
	// find its socket in the client list. Clients which never reached the connected
	// state can just be ignored when their socket is closed.
	else
		{
		mLock.Lock();

		for (theIter = mClients.begin(); theIter != mClients.end(); theIter++)
			{
			if (theIter->second.theSocket == theSocket)
				{
				DisconnectClient(theIter->first);
				break;
				}
			}

		mLock.Unlock();
		}
}
Ejemplo n.º 2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->actionStop_mouse_listening->setEnabled(false);
    try
    {
        QDesktopWidget desktop;
        QSize screenSize = desktop.geometry().size();
        Singleton::Instance().GetFacade()->GetMouseListener()->SetScreenSize(screenSize);
        Singleton::Instance().GetFacade()->GetMouseListener()->SetTCPPortNumber(TCPPortNumber);
        Singleton::Instance().GetFacade()->GetMouseListener()->SetUDPPortNumber(UDPPortNumber);
        Singleton::Instance().GetFacade()->GetMouseListener()->SetBroadCastPortNumber(broadCastPortNumber);

        connect(Singleton::Instance().GetFacade(),
                SIGNAL(ServerStartedSignal()), this, SLOT(ServerStarted()));
        connect(Singleton::Instance().GetFacade(),
                SIGNAL(ServerStoppedSignal()), this, SLOT(ServerStopped()));
        connect(Singleton::Instance().GetFacade(),
                SIGNAL(ErrorSendCommandToDeviceSignal()), this, SLOT(ErrorSendCommandToDevice()));
        connect(Singleton::Instance().GetFacade(),
                SIGNAL(ClientConnectedSignal(QString,int)), this, SLOT(ClientConnected(QString,int)));
        connect(Singleton::Instance().GetFacade(),
                SIGNAL(ClientDisconnectedSignal(QString,int)), this, SLOT(ClientDisconnected(QString,int)));
        connect(Singleton::Instance().GetFacade(),
                SIGNAL(ClientBroadCastSignal(QString,int)), this, SLOT(ClientBroadCast(QString,int)));
    }
    catch (Exception& exception)
    {}
}