Exemplo n.º 1
0
RPCServer::RPCServer(int port){

  QSettings settings;
  bool ok = false;
  while(!ok){
    ok = listen(QHostAddress::Any, port);
    if(!ok && port < rpcMaxPort){
      /* Try going for higher ports until we can listen to one */
      qDebug("RPCServer: Failed to bind to port %d. Trying higher ports...",port);
      port++;
    }else{
      qDebug("RPCServer: Listening on port %d",port);
      settings.setValue("RPCServer/serverPort",port);
    }
  }  
  if(!ok){
    qDebug("RPCServer: All ports exhausted. Binding failed.");
    return;
  }
  attachSlot(QString("reconstructionStarted()"),this,SLOT(reconstructionStarted(quint64)));
  attachSlot(QString("reconstructionStopped()"),this,SLOT(reconstructionStopped(quint64)));
  attachSlot(QString("identificationKeySent(int)"),this,SLOT(receiveIdentificationKey(quint64,int)));
  QObject::connect(this,SIGNAL(clientConnected(quint64)),this,SLOT(onClientConnected(quint64)));
  QObject::connect(this,SIGNAL(clientDisconnected(quint64)),this,SLOT(onClientDisconnected(quint64)));
}
Exemplo n.º 2
0
        void ServerBase::update(void)
        {
            if (!mIsRunning)
                return;

            ENetEvent event;
            while (enet_host_service(mInternalHost, &event, 0) > 0)
            {
                switch(event.type)
                {
                    case ENET_EVENT_TYPE_CONNECT:
                    {
                        IncomingClientBase *client = new Kiaro::Network::IncomingClientBase(event.peer, this);
                        event.peer->data = client;

                        mConnectedClientSet.insert(mConnectedClientSet.end(), (size_t)client);
                        onClientConnected(client);

                        break;
                    }

                    case ENET_EVENT_TYPE_DISCONNECT:
                    {
                        Kiaro::Network::IncomingClientBase *disconnected = (Kiaro::Network::IncomingClientBase*)event.peer->data;
                        onClientDisconnected(disconnected);

                        mConnectedClientSet.erase((size_t)disconnected);
                        delete disconnected;

                        break;
                    }

                    case ENET_EVENT_TYPE_RECEIVE:
                    {
                        if (!event.peer->data)
                        {
                            enet_packet_destroy(event.packet);
                            throw std::runtime_error("ServerBase: Invalid ENet peer data on packet receive!");
                        }

                        Kiaro::Network::IncomingClientBase *sender = (Kiaro::Network::IncomingClientBase*)event.peer->data;
                        Kiaro::Support::BitStream incomingStream(event.packet->data, event.packet->dataLength, event.packet->dataLength);

                        onReceivePacket(incomingStream, sender);
                        enet_packet_destroy(event.packet);

                        break;
                    }

                    case ENET_EVENT_TYPE_NONE:
                        break;
                }
            }
        }
Exemplo n.º 3
0
void Server::startServer(quint16 port)
{
    bool started = m_server->listen(QHostAddress::Any, port);

    connect(m_server, SIGNAL(newConnection()),
            this, SLOT(onClientConnected()));

    if (started) {
        emit serverStarted(m_server->serverPort());
        qDebug() << Q_FUNC_INFO << "Server started on port :" << m_server->serverPort();
    }
}
Exemplo n.º 4
0
void Server::incomingConnection(qintptr socketDescriptor)
{
    Client *client = new Client(socketDescriptor);
    clients->push_back(client);
    QObject::connect(client,SIGNAL(sendMessageToAll(QString)),this,SLOT(sendMessageToAll(QString)));
    QObject::connect(client,SIGNAL(showDialog(QString)),this,SLOT(onShowDialog(QString)));
    QObject::connect(client,SIGNAL(signalDisconnected(QString)),this,SLOT(onClientDisconnected(QString)));
    QObject::connect(client,SIGNAL(signalConnected(QString)),this,SLOT(onClientConnected(QString)));
    QObject::connect(client,SIGNAL(saveHistory(QString)),this,SLOT(onSaveHistory(QString)));
    QObject::connect(client,SIGNAL(getHistory()),this,SLOT(onGetHistory(Client*)));
    onGetHistory(client);
}
Exemplo n.º 5
0
FtpServer::FtpServer(QObject *parent) : QObject(parent) {
    connect(&sv, SIGNAL(newConnection()), this, SLOT(onClientConnected()));
    connect(this, SIGNAL(msg(QString)), this, SLOT(onMsg(QString)));
    mAnonymous = false;
    mAuthenticated = false;
    mUsername = "******";
    mPassword = QCryptographicHash::hash(QString("user").toLatin1(),QCryptographicHash::Sha1);
    mAccount = "";
    mRootPath = "C:/t2/";
    mCurrentPath = mRootPath;
    mIPAddress = "127.0.0.1";
    mPassive = false;
    mFilePosition = 0;
    fsc = 0;
}
Exemplo n.º 6
0
NetworkControl::NetworkControl() {
    client = new Client();

    QObject::connect(client, SIGNAL(connected()), this, SLOT(onConnected()));
    QObject::connect(client, SIGNAL(hostFound()), this, SLOT(onHostFound()));
    QObject::connect(client, SIGNAL(loggingIn()), this, SLOT(onLoggingIn()));
    QObject::connect(client, SIGNAL(successfullJoin()), this, SLOT(onConnectionAccepted()));
    QObject::connect(client, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
    QObject::connect(client, SIGNAL(presentationReceived(QString, QList<QImage>)), this, SLOT(onPresentationReceived(QString, QList<QImage>)));

    server = new Server();
    QObject::connect(server, SIGNAL(listening()), this, SLOT(onStarted()));
    QObject::connect(server, SIGNAL(connectionAccepted()), this, SLOT(onClientConnected()));
    QObject::connect(server, SIGNAL(clientVerified()), this, SLOT(onClientVerified()));
    QObject::connect(server, SIGNAL(clientLeft()), this, SLOT(onClientLeft()));
    QObject::connect(server, SIGNAL(closing()), this, SLOT(onClosed()));

}
Exemplo n.º 7
0
ScreenProvider::ScreenProvider(QObject* parent): QTcpServer(parent)
{
    streaming_ = false;
    orientation_ = QOrientationReading::TopUp;
    struct fb_var_screeninfo var;
    struct fb_fix_screeninfo fix;

    framebufferinfo_.fbmmap = (char*)MAP_FAILED;
    framebufferinfo_.scrinfo = var;
    framebufferinfo_.fix_scrinfo = fix;
    framebufferinfo_.fps = 0.0;
    framebufferinfo_.compression = 50;

    fpstimer_.setInterval(1000);
    connect(&fpstimer_, SIGNAL(timeout()), this, SLOT(updateFps()));
    connect(this, SIGNAL(clientConnected()), this, SLOT(onClientConnected()));

    if ((fbDevice_ = open("/dev/fb0", O_RDONLY)) == -1)
    {
        return;
    }

    if (ioctl(fbDevice_, FBIOGET_FSCREENINFO, &framebufferinfo_.fix_scrinfo) != 0){
        return;
    }

    if (ioctl(fbDevice_, FBIOGET_VSCREENINFO, &framebufferinfo_.scrinfo) != 0){
        return;
    }

    framebufferinfo_.fbmmap = (unsigned int*)mmap(NULL,
                                                  framebufferinfo_.fix_scrinfo.smem_len,
                                                  PROT_READ,
                                                  MAP_SHARED,
                                                  fbDevice_,
                                                  0);

    if ((char*)framebufferinfo_.fbmmap == MAP_FAILED){
        return;
    }
}
Exemplo n.º 8
0
GomokuWindow::GomokuWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    m_client(new LocalClient(this))
{
    ui->setupUi(this);

    connect(ui->createServer, SIGNAL(clicked(bool)),
            this, SLOT(createServer()));

    connect(ui->message, SIGNAL(returnPressed()),
            this, SLOT(sendMessage()));

    connect(ui->sendButton, SIGNAL(clicked(bool)),
            this, SLOT(sendMessage()));

    m_serverDiscovery = new ServerDiscovery(this);
    m_server = new Server(this);

    connect(m_server, SIGNAL(serverStarted(quint16)),
            this, SLOT(addServerToDiscovery(quint16)));

    connect(m_server, SIGNAL(messageReceived(QString,QString)),
            this, SLOT(onServerMessageReceived(QString,QString)));

    connect(m_serverDiscovery,SIGNAL(serverFound(QString,quint16)),
            this, SLOT(addServer(QString,quint16)));

    connect(m_client, SIGNAL(messageReceived(QString,QString)),
            this, SLOT(addMessage(QString,QString)));

    connect(m_client, SIGNAL(connected()),
            this, SLOT(onClientConnected()));

    connect(m_client, SIGNAL(participantsReceived(QList<int>,QStringList)),
            this, SLOT(participantsOnReceived(QList<int>,QStringList)));

    m_serverDiscovery->discoveryServer();
}
/*!
  Creates and connects server and its signals
*/
void WlanConnection::startServer()
{
    if (!mServer) {
        mServer = new WlanServer(this);

        QObject::connect(mServer, SIGNAL(read(QByteArray)),
                         this, SLOT(onRead(QByteArray)));
        QObject::connect(mServer, SIGNAL(clientConnected(QString)),
                         this, SLOT(onClientConnected(QString)));
        QObject::connect(mServer, SIGNAL(clientDisconnected(int)),
                         this, SLOT(onClientDisconnected(int)));
        QObject::connect(mServer, SIGNAL(reconnectToNetwork()),
                         this, SLOT(onReconnect()));
        QObject::connect(mServer, SIGNAL(socketError(int)),
                         this, SLOT(onSocketError(int)));

        WlanNetworkMgr& mgr = Network::networkManager();
        QObject::connect(&mgr, SIGNAL(stateChanged(QNetworkSession::State)),
                         mServer, SLOT(onNetworkStateChanged(QNetworkSession::State)));
        QObject::connect(&mgr, SIGNAL(ipChanged(QString)),
                         mServer, SLOT(onIpChanged(QString)));

    }
Exemplo n.º 10
0
NetworkControl::NetworkControl(PresentationControl* p) {
    pc = p;
    QObject::connect(pc, SIGNAL(presentationChanged()), this, SLOT(onPresentationChanged()));
    QThread* networkThread = new QThread();

    client = new Client();
    QObject::connect(client, SIGNAL(currentPageReceived(qint64)), pc, SLOT(onCurrenPageChanged(qint64)));
    QObject::connect(client, SIGNAL(connected()), this, SLOT(onConnected()));
    QObject::connect(client, SIGNAL(hostFound()), this, SLOT(onHostFound()));
    QObject::connect(client, SIGNAL(loggingIn()), this, SLOT(onLoggingIn()));
    QObject::connect(client, SIGNAL(successfullJoin()), this, SLOT(onConnectionAccepted()));
    QObject::connect(client, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
    QObject::connect(client, SIGNAL(presentationReceived(QString, QList<QImage>)), this, SLOT(onPresentationReceived(QString, QList<QImage>)));

    server = new Server();

    server->setPresentation(p->getPresentation());
    QObject::connect(server, SIGNAL(listening()), this, SLOT(onStarted()));
    QObject::connect(server, SIGNAL(connectionAccepted()), this, SLOT(onClientConnected()));
    QObject::connect(server, SIGNAL(clientVerified()), this, SLOT(onClientVerified()));
    QObject::connect(server, SIGNAL(clientLeft()), this, SLOT(onClientLeft()));
    QObject::connect(server, SIGNAL(closing()), this, SLOT(onClosed()));
}
Exemplo n.º 11
0
void HostServer::onConnected(const PeerPtr& peer)
{
    peers.push_back(peer);
    onClientConnected(peer);
}
Exemplo n.º 12
0
void HostClient::onConnected(const PeerPtr& newPeer)
{
    peer = newPeer;
    state = HostState::Connected;
    onClientConnected(peer);
}
MainController::MainController(MainView *view, QString settingsFilePath,
                               QObject *parent) :
  QObject(parent)
  ,m_view(view)
  ,m_settings(new Settings(this))
  ,m_heartbeatText(HEARTBEAT_TEXT)
  ,m_heartbeatResponseText(HEARTBEAT_RESPONSE_TEXT)
  ,m_heartbeat_interval(0)
  ,m_hearbeatTimer(new QTimer(this))
  ,m_errorTimer(new QTimer(this))
  ,m_appSettings(new ApplicationSettings(this))
{
    connect(m_appSettings, SIGNAL(error(QString)),this, SLOT(onAppSettingsError(QString)));

    /* load setting from the json file */
    if (m_appSettings->parseJSON(settingsFilePath))
    {
        m_screen = new Screen(view, m_appSettings->screenSaverTimeout(), m_appSettings->screenOriginalBrigtness(),
                              m_appSettings->screenDimBrigtness(), this);
        m_watchdog = new Watchdog(this, m_appSettings->enableWatchdog());
        m_beep = new Beep(this);

        /* Define objects that can be used in qml */
        m_view->rootContext()->setContextProperty("connection",this);
        m_view->rootContext()->setContextProperty("settings", m_settings);
        m_view->rootContext()->setContextProperty("screen", m_screen);
        m_view->rootContext()->setContextProperty("watchdog", m_watchdog);
        m_view->rootContext()->setContextProperty("beeper", m_beep);

        /* Enable or disable ack */
        if (m_appSettings->enableAck())
            enableLookupAck();
        else
            disableLookupAck();

        /* Enablle or disable heartbeat */
        connect(m_hearbeatTimer,SIGNAL(timeout()),this, SLOT(onHeartbeatTimerTimeout()));
        if (m_appSettings->enableHeartbeat())
            enableHeartbeat(m_appSettings->heartbeatInterval());
        else
            disableHeartbeat();

        /* Add a connection to the view statusChanged signal */
        connect(m_view, SIGNAL(statusChanged(QQuickView::Status)), this, SLOT(onViewStatusChanged(QQuickView::Status)));

        m_clients = 0;
        m_enableTranslator = false;
        m_startUpError = "";

        /* Create the TCP string servers and add connections */
        int i = 0;
        foreach(const StringServerSetting &server, m_appSettings->stringServers())
        {
            StringServer *stringServer =  new StringServer(this, server.port(), server.parseJson(),
                                                           server.translate(), server.translateId(),
                                                           server.primaryConnection());
            if (server.translate())
                m_enableTranslator = true;
            connect(stringServer, SIGNAL(PrimaryConnectionAvailable()), this, SLOT(onPrimaryConnectionAvailable()));
            connect(stringServer, SIGNAL(MessageAvailable(QByteArray, bool, bool, QString))
                    , this, SLOT(onMessageAvailable(QByteArray, bool, bool, QString)));
            connect(stringServer, SIGNAL(ClientConnected()), this, SLOT(onClientConnected()));
            connect(stringServer, SIGNAL(ClientDisconnected()), this, SLOT(onClientDisconnected()));

            if (stringServer->Start())
            {
                m_stringServerList.append(stringServer);
                i += 1;
            }
            else
            {
                delete stringServer;
            }
        }


        /* Create the Serial Servers and add the connections */
        i = 0;
        foreach(const SerialServerSetting &server, m_appSettings->serialServers())
        {
            SerialServer *serialServer = new SerialServer(server, this);
            connect(serialServer, SIGNAL(ClientConnected()), this, SLOT(onClientConnected()));
            connect(serialServer, SIGNAL(PrimaryConnectionAvailable()), this, SLOT(onPrimaryConnectionAvailable()));
            connect(serialServer, SIGNAL(MessageAvailable(QByteArray, bool, bool, QString))
                    , this, SLOT(onMessageAvailable(QByteArray, bool, bool, QString)));
            connect(serialServer, SIGNAL(Error(QString)), this, SLOT(showError(QString)));

            if (server.translate())
                m_enableTranslator = true;

            if (serialServer->Start())
            {
                m_serialServerList.append(serialServer);
                i += 1;
            }
            else
            {
                delete serialServer;
            }

        }

        if (m_enableTranslator){
            /* Initialize the Translator object */
            m_transLator = new Translator(m_appSettings->translateFile(), m_appSettings->translateMaxMapSize(), this);
            /* Load and parse the translate file. */
            m_transLator->loadTranslations();
        }

        /* check if we need to load a language translate file */
        if (m_appSettings->languageFile().length() > 0)
        {
            loadLanguageTranslator(m_appSettings->languageFile());
        }

        setMainViewPath(m_appSettings->mainView());
        m_view->show();
    }