コード例 #1
0
//TCP自动监听
bool LiLANMangeServer::autoListen()
{
    while(serverPort()==0)
    {
        listen(QHostAddress::AnyIPv4,allPort);
        addAllPort();
    }
    qDebug()<<"Server绑定端口号:"<<serverPort();
//    emit debug("Server绑定端口号:"+serverPort());
    return true;
}
コード例 #2
0
    /**
     * @brief Converts to QVariantMap
     */
    QVariant ConnectionSettings::toVariant() const
    {
        QVariantMap map;
        map.insert("connectionName", QtUtils::toQString(connectionName()));
        map.insert("serverHost", QtUtils::toQString(serverHost()));
        map.insert("serverPort", serverPort());
        map.insert("defaultDatabase", QtUtils::toQString(defaultDatabase()));
        map.insert("isReplicaSet", isReplicaSet());
        if (isReplicaSet()) {
            map.insert("replicaSet", _replicaSetSettings->toVariant());
        }

#ifdef MONGO_SSL
        SSLInfo infl = _info.sslInfo();
        map.insert("sslEnabled", infl._sslSupport);
        map.insert("sslPemKeyFile", QtUtils::toQString(infl._sslPEMKeyFile));
#endif
        QVariantList list;
        for (QList<CredentialSettings *>::const_iterator it = _credentials.begin(); it != _credentials.end(); ++it) {
            CredentialSettings *credential = *it;
            list.append(credential->toVariant());
        }
        map.insert("credentials", list);

        map.insert("ssh", _sshSettings->toVariant());
        map.insert("ssl", _sslSettings->toVariant());
        map.insert("uuid", _uuid); 

        return map;
    }
コード例 #3
0
CWebChannelServer::CWebChannelServer(const QHostAddress &anAddress, quint16 nPort, QObject *pParent)
	:	QObject(pParent),
		m_server("King James Pure Bible Search WebChannel Server", QWebSocketServer::NonSecureMode),
		m_clientWrapper(&m_server),
		m_HostAddress(anAddress),
		m_nHostPort(nPort)
{
	m_pGeoLocater = new CWebChannelGeoLocate(this);
	connect(m_pGeoLocater, SIGNAL(locationInfo(const CWebChannelClient *, const QString &, const QString &)), this, SLOT(setClientLocation(const CWebChannelClient *, const QString &, const QString &)));

	// setup the QWebSocketServer
	m_server.listen(anAddress, nPort);

	// create the CWebChannelAdminObjects
	m_pWebChannelAdminObjects = new CWebChannelAdminObjects(this);
	connect(m_pWebChannelAdminObjects.data(), SIGNAL(broadcast(const QString &)), this, SLOT(sendBroadcast(const QString &)));

	// Handle connections:
	connect(&m_clientWrapper, SIGNAL(clientConnected(WebSocketTransport*)), this, SLOT(en_clientConnected(WebSocketTransport*)));

#ifdef IS_CONSOLE_APP
	if (m_server.isListening()) {
		std::cout << QString("%1 UTC : KJPBS-WebChannel (pid=%2) started on interface \"%3\" port %4\n")
							.arg(QDateTime::currentDateTimeUtc().toString(Qt::ISODate))
							.arg(QCoreApplication::applicationPid())
							.arg(serverAddress().toString())
							.arg(serverPort())
							.toUtf8().data();
		std::cout.flush();
	}
#endif
}
コード例 #4
0
ファイル: statusapi.cpp プロジェクト: BinChengfei/cantata
HttpRequestHandler::HandleStatus StatusApi::handle(HttpRequest *request, HttpResponse *response)
{
    if (HttpRequest::Method_Get==request->method()) {
        if (request->path()=="/api/v1/status/socket") {
            response->write("{\"port\":"+QByteArray::number(serverPort())+"}");
            return Status_Handled;
        } else if (request->path()=="/api/v1/status") {
            response->write(statusMessage());
            return Status_Handled;
        } else if (request->path()=="/api/v1/status/current") {
            response->write(currentSongMessage());
            return Status_Handled;
        }
    } else if(HttpRequest::Method_Post==request->method() && request->path()=="/api/v1/status") {
        QString repeat=request->parameter("repeat");
        QString random=request->parameter("random");
        QString single=request->parameter("single");
        QString consume=request->parameter("consume");
        DBUG << repeat << random << single << consume;
        if (!repeat.isEmpty()) {
            emit setRepeat(isSet(repeat));
        }
        if (!random.isEmpty()) {
            emit setRandom(isSet(random));
        }
        if (!single.isEmpty()) {
            emit setSingle(isSet(single));
        }
        if (!consume.isEmpty()) {
            emit setConsume(isSet(consume));
        }
        return Status_Handled;
    }
    return Status_BadRequest;
}
コード例 #5
0
ファイル: server.cpp プロジェクト: simon0xia/Summoners
Server::Server(QObject *parent)
	: QTcpServer(parent)
{
	QSettings *ConfigIni = new QSettings("./Settings.ini", QSettings::IniFormat, this);
	port = ConfigIni->value("/COMM/Port", 7000).toInt();
	maxClient = ConfigIni->value("/COMM/MaxClient", 1).toInt();
	delete ConfigIni;

	ClientCount = 0;

	if (!listen(QHostAddress::Any, port))
	{
		qDebug() << tr("SWServer Server"), tr("Unable to start the server: %1.").arg(errorString());
		return;
	}

	QString ipAddress;
	QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
	// use the first non-localhost IPv4 address
	for (int i = 0; i < ipAddressesList.size(); ++i) {
		if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
			ipAddressesList.at(i).toIPv4Address()) {
			ipAddress = ipAddressesList.at(i).toString();
			break;
		}
	}

	// if we did not find one, use IPv4 localhost
	if (ipAddress.isEmpty())
		ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
	qDebug() << (tr("The server is running on\nIP: %1\tport: %2\n")
		.arg(ipAddress).arg(serverPort()));

	startTimer(1000);
}
コード例 #6
0
void OftServer::listen()
{
	m_timer.start();
	QTcpServer::listen();
	debug() << "Started listening for incoming connections on port" << serverPort();
	//emit m_conn->localPortChanged(serverPort());
}
コード例 #7
0
bool sctpServer::start(const QString &config)
{
    parseConfig(config);

    if (!listen(QHostAddress::Any, mPort))
    {
        qCritical() << QObject::tr("Unable to start the server: %1").arg(errorString());
        return false;
    }

    QString ipAddress;
    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    // use the first non-localhost IPv4 address
    for (int i = 0; i < ipAddressesList.size(); ++i) {
        if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
                ipAddressesList.at(i).toIPv4Address()) {
            ipAddress = ipAddressesList.at(i).toString();
            break;
        }
    }

    // if we did not find one, use IPv4 localhost
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
    QString message = QObject::tr("The server is running on\nIP: %1\tport: %2\n")
                                  .arg(ipAddress).arg(serverPort());
    qDebug() << message.toUtf8().constData();

    // initialize sc-memory
    qDebug() << "Initialize sc-memory\n";
    sc_memory_params params;
    sc_memory_params_clear(&params);

    std::string config_path = config.toStdString();
    std::string repo_path = mRepoPath.toStdString();
    std::string ext_path = mExtPath.toStdString();

    params.clear = SC_FALSE;
    params.config_file = config_path.c_str();
    params.repo_path = repo_path.c_str();
    params.ext_path = ext_path.c_str();

    mContext = sc_memory_initialize(&params);
    if (mContext == 0)
        return false;

    mEventManager = new sctpEventManager();
    mEventManager->initialize();

    if (mStatUpdatePeriod > 0)
    {
        mStatistic = new sctpStatistic(this);
        mStatistic->initialize(mStatPath, mStatUpdatePeriod, mContext);
    }

    QTimer::singleShot(mSavePeriod * 1000, this, SLOT(onSave()));

    return true;
}
コード例 #8
0
ThreadedTcpServer::ThreadedTcpServer(QObject *parent) :
    QTcpServer(parent)
{
	if (listen(QHostAddress::AnyIPv4, 5555))
		qDebug() << Q_FUNC_INFO << "listening on port" << serverPort();
	else
		qDebug() << Q_FUNC_INFO << "listening failed";
}
コード例 #9
0
ファイル: httpserver.cpp プロジェクト: jhihn/Vaudeville
HttpServer::HttpServer(QObject *parent) :
	QTcpServer(parent)
{
	if (listen())
		qDebug() << "HttpServer listening on port" << serverPort();
	else
		qDebug() << "HttpServer listening failed";

	connect(&m_socket, SIGNAL(readyRead()), this, readData());
}
コード例 #10
0
bool LocalServer::start()
{
    while (!isListening() && !listen(QHostAddress::LocalHost, PORT)) {
        uERROR << "cannot start listening";
        return false;
    }

    uINFO << "listening on port" << serverPort();
    return true;
}
コード例 #11
0
ファイル: KDSoapServer.cpp プロジェクト: hporten/KDSoap
QString KDSoapServer::endPoint() const {
    const QHostAddress address = serverAddress();
    if (address == QHostAddress::Null)
        return QString();
    const QString addressStr = address == QHostAddress::Any ? QString::fromLatin1("127.0.0.1") : address.toString();
    return QString::fromLatin1("%1://%2:%3%4")
            .arg(QString::fromLatin1((d->m_features & Ssl)?"https":"http"))
            .arg(addressStr)
            .arg(serverPort())
            .arg(d->m_path);
}
コード例 #12
0
void MonServeur::startServer()
{
	qDebug() << "Start server :";
	if(!listen(QHostAddress::Any,1234))
	{
		qDebug() << "Could not start server";
	}
	else
	{
		qDebug() << "Listening on port : " << serverPort();
	}
}
コード例 #13
0
ファイル: KDSoapServer.cpp プロジェクト: hporten/KDSoap
void KDSoapServer::suspend()
{
    d->m_portBeforeSuspend = serverPort();
    d->m_addressBeforeSuspend = serverAddress();
    close();

    // Disconnect connected sockets, otherwise they could still make calls
    if (d->m_threadPool) {
        d->m_threadPool->disconnectSockets(this);
    } else if (d->m_mainThreadSocketList) {
        d->m_mainThreadSocketList->disconnectAll();
    }
}
コード例 #14
0
ファイル: SharedDaemon.C プロジェクト: burlen/visit_vtk_7_src
void SharedDaemon::init()
{
    if(listen_port > 0) {
        listen(QHostAddress::Any,listen_port);
    } else {
        listen(QHostAddress::Any);
        listen_port = serverPort();
    }

    if(isListening())
        std::cerr << "Starting to listen on port: " << listen_port << std::endl;
    else
        std::cerr << "WARNING: Failed to start listening server on port: " << listen_port << std::endl;
}
コード例 #15
0
ファイル: Server.cpp プロジェクト: marcoscao/sandbox
   void Server::start()
   {
      listen();

      cout << "Starting server..." << endl;

      cout << "note: server will shutdown automatically after an inactivity period of " << INACTIVITY_TIMEOUT / 1000 << " seconds" << endl;
      //cout << " -> active threads: " << threadpool_->activeThreadCount() << endl;

      cout << endl;

      cout << "Server starting to listen on address " << serverAddress().toString().toStdString();
      cout << " and port " << serverPort() << endl;

      inactivity_timer_.start( INACTIVITY_TIMEOUT );
   }
コード例 #16
0
ファイル: httpsocket.cpp プロジェクト: CDrummond/cantata
HttpSocket::HttpSocket(const QString &iface, quint16 port)
    : QTcpServer(nullptr)
    , cfgInterface(iface)
    , terminated(false)
{
    if (!openPort(port)) {
        openPort(0);
    }

    DBUG << isListening() << serverPort();

    connect(MPDConnection::self(), SIGNAL(socketAddress(QString)), this, SLOT(mpdAddress(QString)));
    connect(MPDConnection::self(), SIGNAL(cantataStreams(QList<Song>,bool)), this, SLOT(cantataStreams(QList<Song>,bool)));
    connect(MPDConnection::self(), SIGNAL(cantataStreams(QStringList)), this, SLOT(cantataStreams(QStringList)));
    connect(MPDConnection::self(), SIGNAL(removedIds(QSet<qint32>)), this, SLOT(removedIds(QSet<qint32>)));
    connect(this, SIGNAL(newConnection()), SLOT(handleNewConnection()));
}
コード例 #17
0
ファイル: rpcserver.cpp プロジェクト: anju61188/ostinato
bool RpcServer::registerService(::google::protobuf::Service *service,
    QHostAddress address, quint16 tcpPortNum)
{
    this->service = service;

    if (!listen(address, tcpPortNum))
    {
        qDebug("Unable to start the server on <%s>: %s",
                qPrintable(address.toString()),
                errorString().toAscii().constData());
        return false;
    }

    qDebug("The server is running on %s: %d", 
            serverAddress().toString().toAscii().constData(),
            serverPort());
    return true;
}
コード例 #18
0
void LoginWidget::verifyUser(){

    if(canLogin()){
        QString serverHostAddress = serverAddress();
        //        if(serverHostAddress.isEmpty()){
        //            QMessageBox::critical(this, tr("Error"), tr("Server Address Required!"));
        //            localServer->close();
        //            ui.toolButtonConfig->click();
        //            if(!ui.comboBoxServerIP->count()){
        //                ui.toolButtonServersManager->click();
        //            }
        //            return;
        //        }

        switchUI(VERIFYING);
        emit signalRequestLogin(QHostAddress(serverHostAddress), serverPort());
        
        //QTimer::singleShot(30000, this, SLOT(loginTimeout()));
    }


    //	Login login(user,this);
    //	if(canLogin() && login.isVerified()){
    //		//发射验证成功的消息
    //		emit signalUserVerified();

    //		qDebug()<<"----LoginWidget::verifyUser()~~User Verified!";

    //		return true;
    //	}else{
    //		user->setUserID("");
    //		user->setPassword("");
    //		user->setVerified(false);
    //		localServer->close();
    //		switchUI(NORMAL);
    //		qDebug()<<"XXXXLoginWidget::verifyUser()~~User Verify Failed!";
    //	}

    //	return false;

}
コード例 #19
0
ファイル: main.cpp プロジェクト: pokerspiel/metaserver
int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    ApplicationHelper appHelper;

    QObject::connect(&app, SIGNAL(aboutToQuit()), &appHelper, SLOT(aboutToQuit()));
    signal(SIGINT, signalHandler);

    // Set application variables
    QCoreApplication::setApplicationName("pokerspiel-metaserver");
    QCoreApplication::setApplicationVersion("0.1.0");
    QCoreApplication::setOrganizationName("PokerSpielServices");
    QCoreApplication::setOrganizationDomain("pokerspielservices.me");

    // Get command line arguments
    QCommandLineParser parser;
    parser.addHelpOption();
    parser.addVersionOption();

    QCommandLineOption serverPort(QStringList() << "P" << "port",
                                  "Port of the websocket server.",
                                  "ws_port",
                                  WEBSOCKET_PORT);
    parser.addOption(serverPort);
    QCommandLineOption mysqlHost(QStringList() << "h" << "host",
                                  "Hostname for mysql database.",
                                  "mysql_hostname",
                                  MYSQL_HOSTNAME);
    parser.addOption(mysqlHost);
    QCommandLineOption mysqlUsername(QStringList() << "u" << "username",
                                  "Username for mysql database.",
                                  "mysql_username",
                                  MYSQL_USERNAME);
    parser.addOption(mysqlUsername);
    QCommandLineOption mysqlPassword(QStringList() << "p" << "password",
                                  "Password of the mysql database.",
                                  "mysql_password",
                                  MYSQL_PASSWORD);
    parser.addOption(mysqlPassword);
    QCommandLineOption mysqlDatabase(QStringList() << "d" << "database",
                                  "Name of the mysql database.",
                                  "mysql_db",
                                  MYSQL_DB);
    parser.addOption(mysqlDatabase);

    QCommandLineOption jsonLog("json");
    jsonLog.setDescription("Output log in JSON format");
    parser.addOption(jsonLog);

    parser.process(app);

    if (parser.isSet(jsonLog)) {
        appHelper.jsonOutput = true;
        qInstallMessageHandler(jsonOutput);
    } else {
        appHelper.jsonOutput = false;
        qInstallMessageHandler(messageOutput);
    }

    // Connect to database
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName(parser.value(mysqlHost));
    db.setDatabaseName(parser.value(mysqlDatabase));
    db.setUserName(parser.value(mysqlUsername));
    db.setPassword(parser.value(mysqlPassword));
    db.setConnectOptions("MYSQL_OPT_RECONNECT=1");
    if (!db.open()) {
        qFatal("SQL Error: %s", db.lastError().text().toUtf8().constData());
    } else {
        qDebug() << "Connection to MYSQL-Server established (" << db.userName() << "@" << db.hostName() << ")";
    }

    // Start websocket server
    WebSocketServer server(parser.value(serverPort).toUInt());
    Q_UNUSED(server);

    return app.exec();
}
コード例 #20
0
void LoginWidget::updateUserLoginServerInfo(){
    qDebug()<<"--LoginWidget::updateUserLoginServerInfo() serverAddress:"<<serverAddress();

    user->setLoginServerAddress(serverAddress());
    user->setLoginServerPort(serverPort());
}
コード例 #21
0
//我在这
void LiLANMangeServer::iAmHere()
{
    broadcastMessage("HelloClient|Name=="+myName+"|Port=="+QString::number(serverPort())+"|");
    broadcastMessageAllAccurate("*"+localIPV4Address+"*"+QString::number(serverPort())+"*");
}
コード例 #22
0
ファイル: server.cpp プロジェクト: signatal/strine
int Server::Port() const
{
    return static_cast<int>(serverPort());
}
コード例 #23
0
int ClientNetwork::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: packetReceived(); break;
        case 1: packetCorrupted(); break;
        case 2: pingUpdated((*reinterpret_cast< quint32(*)>(_a[1]))); break;
        case 3: chatReceived((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3])),(*reinterpret_cast< ENUM_TYPE(*)>(_a[4]))); break;
        case 4: serverInformationsChanged((*reinterpret_cast< ServerInformations(*)>(_a[1]))); break;
        case 5: clientIDChanged((*reinterpret_cast< CLID(*)>(_a[1]))); break;
        case 6: nicknameChanged((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 7: error((*reinterpret_cast< ENUM_TYPE(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 8: clientVoted((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< CLID(*)>(_a[2]))); break;
        case 9: newGameMaster((*reinterpret_cast< CLID(*)>(_a[1]))); break;
        case 10: serverName((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 11: motdChanged((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 12: gameLaunched(); break;
        case 13: narrationChanged((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 14: mapChanged((*reinterpret_cast< MapPtr(*)>(_a[1]))); break;
        case 15: mapFlare((*reinterpret_cast< QPoint(*)>(_a[1])),(*reinterpret_cast< CLID(*)>(_a[2]))); break;
        case 16: scriptToGMMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 17: scriptToOwnerMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 18: scriptActionMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 19: scriptToPlayerMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 20: scriptMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 21: scriptError((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 22: updateEntities((*reinterpret_cast< const QList<EntityInformations>(*)>(_a[1]))); break;
        case 23: updateEntity((*reinterpret_cast< const EntityInformations(*)>(_a[1]))); break;
        case 24: entityDeleted((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 25: scriptReceived((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 26: ressourcesUpdated((*reinterpret_cast< const QMap<QString,RSID>(*)>(_a[1]))); break;
        case 27: connectionEtablished(); break;
        case 28: connectionLost(); break;
        case 29: diceRolled((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2])),(*reinterpret_cast< quint16(*)>(_a[3]))); break;
        case 30: sanctionned((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< ENUM_TYPE(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3]))); break;
        case 31: clientJoined((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 32: clientLeft((*reinterpret_cast< CLID(*)>(_a[1]))); break;
        case 33: playSound((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 34: syncLibs((*reinterpret_cast< QList<SoundLibInformations>(*)>(_a[1]))); break;
        case 35: syncLanguagesList((*reinterpret_cast< QList<QPair<QString,QString> >(*)>(_a[1]))); break;
        case 36: syncDictionariesList((*reinterpret_cast< QStringList(*)>(_a[1]))); break;
        case 37: syncScriptList((*reinterpret_cast< QStringList(*)>(_a[1]))); break;
        case 38: updateCharacterList((*reinterpret_cast< const QStringList(*)>(_a[1]))); break;
        case 39: send((*reinterpret_cast< Packet*(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
        case 40: send((*reinterpret_cast< Packet*(*)>(_a[1]))); break;
        case 41: send((*reinterpret_cast< Packet(*)>(_a[1]))); break;
        case 42: send((*reinterpret_cast< qint32(*)>(_a[1])),(*reinterpret_cast< const QByteArray(*)>(_a[2]))); break;
        case 43: ping(); break;
        case 44: { qint32 _r = getPing();
            if (_a[0]) *reinterpret_cast< qint32*>(_a[0]) = _r; }  break;
        case 45: { QString _r = serverIP();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        case 46: { quint16 _r = serverPort();
            if (_a[0]) *reinterpret_cast< quint16*>(_a[0]) = _r; }  break;
        case 47: flush(); break;
        case 48: connection(); break;
        case 49: disconnection(); break;
        case 50: { bool _r = setServer((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 51: connected(); break;
        case 52: disconnected(); break;
        case 53: dataReceived(); break;
        case 54: socketError((*reinterpret_cast< QAbstractSocket::SocketError(*)>(_a[1]))); break;
        case 55: operatePacket((*reinterpret_cast< Packet*(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 56;
    }
    return _id;
}
コード例 #24
0
ファイル: main.cpp プロジェクト: kierzek/MUFINS
int main(int argc, char** argv) {
    if (argc != 3 && argc != 5 && argc != 6) {
        cout << VERSION << endl;
        cout << "USAGE FOR STANDALONE: qsspn qsspn_file ctrl_file" << endl;
        cout << "USAGE FOR SERVER: qsspn qsspn_file ctrl_file address port cache_size" << endl;
        cout << "USAGE FOR CLIENT: qsspn qsspn_file ctrl_file address port" << endl;
        cout << "The qsspn_file file with extension .json is read as Json file" << endl;
        cout << "The qsspn file without .json extension is assumed to be in old qsspn format" << endl;
        cout << "Example cache size is 100000000" << endl;
        exit(1);
    }

    if (argc == 3) {//standalone
        PetriNet *pn = new PetriNet();
        string path(argv[1]);
        string path1(argv[2]);
        if (isJason(path)) {
            pn->readModel(path);
        } else {
            pn->readPetriNet(path);
        }
        pn->runWorkflowStandalone(path1);
        exit(0);
    } else if (argc == 5) {//client
        PetriNet *pn = new PetriNet();
        string path(argv[1]);
        string path1(argv[2]);
        string serverAddress(argv[3]);
        string serverPort(argv[4]);
        if (isJason(path)) {
            pn->readModel(path);
        } else {
            pn->readPetriNet(path);
        }
       pn->runWorkflowClient(path1, serverAddress, serverPort);
        exit(0);
    } else try {//server
        string path(argv[1]);
        string path1(argv[2]);
        string address(argv[3]);
        string port(argv[4]);
        int cache_size = atoi(argv[5]);

        Cache *cache = new Cache(cache_size);
        PetriNet *pn = new PetriNet();
        if (isJason(path)) {
            pn->readModel(path);
        } else {
            pn->readPetriNet(path);
        }

        fstream infile;
        string word;
        vector<string> text;

        infile.open(path1.c_str());
        if (!infile) {
            cerr << "Could not open file:" << path1 << endl;
            exit(0);
        }

        while (infile >> word) text.push_back(word);
        infile.close();

        asio::io_service io_service;

        MetabolismServer server(address, port, io_service, 1, pn, cache, text);

        server.run();

        delete pn;
        delete cache;
    } catch (std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }
    return 0;
}