コード例 #1
0
ファイル: menu.cpp プロジェクト: Njallzzz/Skilaverkefni
void Search( vector<Computer> & list, Computer p ) {        // Search for members in list based on template person p
    vector<Computer> SearchList;                      // Create search result vector

    for( unsigned int x = 0; x < list.size(); x++) {    // Search each entry of list
        bool add = true;                                    // We say the entry should be added by default then exclude it based on the template person
        if( p.getName() != "" )
            if( !list[x].getName().contains( p.getName(), Qt::CaseInsensitive ) )
                add = false;

        if( p.getType() != "" )
            if( !list[x].getType().contains( p.getType() , Qt::CaseInsensitive ) )
                add = false;

        if( p.getWasBuilt() != 2 )
            if( !(list[x].getWasBuilt() == p.getWasBuilt() ) )
                add = false;

        if( p.getYear() != "" )
            if( !(list[x].getYear() == p.getYear() ) )
                add = false;

        if(add)
            SearchList.push_back( list[x] );
    }
    displayComputer( SearchList );              // Display search results
}
コード例 #2
0
ファイル: manager.cpp プロジェクト: lessc0de/yarp
bool Manager::updateResource(GenericResource* resource)
{
    YarpBroker broker;
    broker.init();

    Computer* comp = dynamic_cast<Computer*>(resource);
    if(!comp || !strlen(comp->getName()))
        return false;

    if(compareString(comp->getName(), "localhost"))
        return false;

    yarp::os::SystemInfoSerializer info;
    string strServer = comp->getName();
    if(strServer[0] != '/')
        strServer = string("/") + strServer;
    if(!broker.getSystemInfo(strServer.c_str(), info))
    {
        logger->addError(broker.error());
        comp->setAvailability(false);
    }
    else
    {
        comp->setAvailability(true);

        comp->getMemory().setTotalSpace(info.memory.totalSpace*1024);
        comp->getMemory().setFreeSpace(info.memory.freeSpace*1024);

        comp->getStorage().setTotalSpace(info.storage.totalSpace*1024);
        comp->getStorage().setFreeSpace(info.storage.freeSpace*1024);

        //comp->getNetwork().setIP4(info.network.ip4.c_str());
        //comp->getNetwork().setIP6(info.network.ip6.c_str());
        //comp->getNetwork().setMAC(info.network.mac.c_str());


        comp->getProcessor().setArchitecture(info.processor.architecture.c_str());
        comp->getProcessor().setCores(info.processor.cores);
        comp->getProcessor().setSiblings(info.processor.siblings);
        comp->getProcessor().setFrequency(info.processor.frequency);
        comp->getProcessor().setModel(info.processor.model.c_str());
        LoadAvg load;
        load.loadAverageInstant = (double)info.load.cpuLoadInstant;
        load.loadAverage1 = info.load.cpuLoad1;
        load.loadAverage5 = info.load.cpuLoad5;
        load.loadAverage15 = info.load.cpuLoad15;
        comp->getProcessor().setCPULoad(load);

        comp->getPlatform().setName(info.platform.name.c_str());
        comp->getPlatform().setDistribution(info.platform.distribution.c_str());
        comp->getPlatform().setRelease(info.platform.release.c_str());
    }
    return true;
}
コード例 #3
0
ファイル: addlink.cpp プロジェクト: SenpaiPlz/0011Week
void AddLink::displayComp(vector<Computer>& computer)
{
    ui->table_linking->setSortingEnabled(false);

    ui->table_linking->clearContents();
    ui->table_linking->setColumnCount(5);
    ui->table_linking->setRowCount(computer.size());

    ui->table_linking->setHorizontalHeaderItem(0,new QTableWidgetItem(QString("id")));
    ui->table_linking->setHorizontalHeaderItem(1,new QTableWidgetItem(QString("Name")));
    ui->table_linking->setHorizontalHeaderItem(2,new QTableWidgetItem(QString("Year")));
    ui->table_linking->setHorizontalHeaderItem(3,new QTableWidgetItem(QString("Type")));
    ui->table_linking->setHorizontalHeaderItem(4,new QTableWidgetItem(QString("Built")));

    for(size_t i = 0; i < computer.size(); i++)
    {
        Computer temp = computer[i];

        QTableWidgetItem* id = new QTableWidgetItem;
        id->setData(Qt::DisplayRole,temp.getID());

        ui->table_linking->setItem(i,0, id);
        ui->table_linking->setItem(i,1, new QTableWidgetItem(QString::fromStdString(temp.getName())));
        ui->table_linking->setItem(i,2, new QTableWidgetItem(QString::number(temp.getYear())));
        ui->table_linking->setItem(i,3, new QTableWidgetItem(QString::fromStdString(temp.getType())));
        ui->table_linking->setItem(i,4, new QTableWidgetItem(QString::number(temp.getBuilt())));
    }

    ui->table_linking->setSortingEnabled(true);
}
コード例 #4
0
ファイル: mainwindow.cpp プロジェクト: axelboga/hopur32
void MainWindow::displayComputersForScientistConnections(vector<Computer> computers) {
    ui->computer_list_scientist_connections->clear();
    for (unsigned int i = 0; i < computers.size(); i++) {
        Computer currentComputer = computers.at(i);
        QString name = QString::fromStdString(currentComputer.getName());
        ui->computer_list_scientist_connections->addItem(name);
    }
}
コード例 #5
0
void ComputerRepository::addToDatabase(Computer computer) {
    QSqlQuery query(datab);
    query.prepare("INSERT INTO Computers(Name, Type, WasBuilt, YearBuilt) VALUES (:Name, :Type, :WasBuilt, :YearBuilt)");
    query.bindValue(":Name", QString::fromStdString(computer.getName()));
    query.bindValue(":Type", QString::fromStdString(computer.getType()));
    query.bindValue(":WasBuilt", QString::fromStdString(computer.getWasBuilt()));
    query.bindValue(":YearBuilt", QString::fromStdString(computer.getYear()));
    query.exec();
}
コード例 #6
0
void Scientist::setComputers(std::vector<Computer> newComputers)
{
    destroyComputers();

    for (unsigned int i = 0; i < newComputers.size(); i++)
    {
        Computer currentComputer = newComputers.at(i);
        this->computers.push_back(new Computer(currentComputer.getId(), currentComputer.getName(), currentComputer.getType(), currentComputer.getYearBuilt()));
    }
}
コード例 #7
0
ファイル: computerrepository.cpp プロジェクト: VLN-H7/Skil2
void ComputerRepository::add(Computer &comp) {
    auto query = SQLConnection::getInstance()->getQuery();
    query->prepare("INSERT INTO computers (name, type, build_year, built) VALUES (?,?,?,?)");
    query->addBindValue(QString::fromStdString(comp.getName()));
    query->addBindValue(QString::fromStdString(comp.getType()));
    query->addBindValue(comp.getBuildYear());
    query->addBindValue(comp.getBuilt());
    if(!query->exec())
        throw std::runtime_error(query->lastError().text().toStdString());
}
コード例 #8
0
ファイル: database.cpp プロジェクト: Dagnyb/VLN-1
void Database::addComputer(Computer computer)
{
    QSqlQuery query(connectDatabase());

    query.prepare("INSERT INTO Computers (ComputersName, YearBuilt, Type, WasItBuilt) VALUES (:name, :year, :type, :built)");
    query.bindValue(":name",         QString::fromStdString(computer.getName()));
    query.bindValue(":year",         QString::number(computer.getYear()));
    query.bindValue(":type",         QString::fromStdString(computer.getType()));
    query.bindValue(":built",        QString::number(computer.getwasItBuilt()));
    query.exec();
}
コード例 #9
0
ファイル: computerrepository.cpp プロジェクト: VLN-H7/Skil2
void ComputerRepository::update(Computer &comp, Computer &replace) {
    auto query = SQLConnection::getInstance()->getQuery();
    query->prepare("UPDATE computers SET name = ?, type = ?, build_year = ?, built = ? WHERE id = ?");
    query->addBindValue(QString::fromStdString(replace.getName()));
    query->addBindValue(QString::fromStdString(replace.getType()));
    query->addBindValue(replace.getBuildYear());
    query->addBindValue(replace.getBuilt());
    query->addBindValue(comp.getID());
    if(!query->exec())
        throw std::runtime_error(query->lastError().text().toStdString());
}
コード例 #10
0
int SQLITEHandler::addEntry( Computer c ) {         // Add Computer to database
    if( !status )                                   // If not connected, fail
        return 1;
    q.prepare( "INSERT INTO computers (name, creation, type, constructed) VALUES (:name, :creation, :type, :constructed)" );
    q.bindValue( ":name", c.getName() );
    q.bindValue( ":creation", c.getYear() );
    q.bindValue( ":type", c.getType() );
    q.bindValue( ":constructed", c.getWasBuilt() );
    if( !q.exec() )                                 // Attempt to execute query
        return 1;
    return 0;                   // Return Success
}
コード例 #11
0
int SQLITEHandler::modifyEntry( Computer c ) {      // Modify computer in database
    if( !status )                                   // If not connected, fail
        return 1;
    q.prepare( "UPDATE computers SET name = (:name), creation = (:creation), type = (:type), constructed = (:constructed) WHERE id = (:id)" );
    q.bindValue( ":id", c.getId() );
    q.bindValue( ":name", c.getName() );
    q.bindValue( ":creation", c.getYear() );
    q.bindValue( ":type", c.getType() );
    q.bindValue( ":constructed", c.getWasBuilt() );
    if( !q.exec() )                                 // Attempt to execute query
        return 2;
    return 0;                   // Return Success
}
コード例 #12
0
void Interface::addComputer()
{
    clearConsole();
    printLines();
    printMenuHead("ADD COMPUTER");
    Computer temp;
    char ch;
    cin >> temp;

    cout << "Are you sure you want to add " << temp.getName().toStdString() << "?(y/n): ";
    cin >> ch;
    if(ch == 'y' || ch == 'Y')
    {
        if(request.addComputer(temp))
        {
            setStatus("\"" + temp.getName().toStdString() + "\" added to computers!");
        }
        else
        {
            setStatus("\"" + temp.getName().toStdString() + "\" could not be added to computers!");
        }
    }
}
コード例 #13
0
bool ComputerRepository::add(Computer c) {
    db.open();
    QSqlQuery query;
    query.prepare("INSERT INTO Computers(Name, BuildYear, Type, Built)"
                  "VALUES (:name, :buildyear, :type, :built)");
    query.bindValue(":name", QString::fromStdString(c.getName()));
    query.bindValue(":buildyear", QString::fromStdString(c.getBuildYear()));
    query.bindValue(":type", QString::fromStdString(c.getType()));
    query.bindValue(":built", QString::number(c.getBuilt()));
    query.exec();
    db.close();
    return true;

}
コード例 #14
0
bool Computerrepository::addToDatabase(Computer newComp) {
    QSqlQuery query;

    QString name       = QString::fromStdString((newComp.getName()));
    int     builtY     = newComp.getBuildYear();
    QString type       = QString::fromStdString((newComp.getType()));
    bool    builtOrNot = newComp.getBuild();

    query.prepare("INSERT INTO Computers (Name, YearBuilt, Type, BuiltOrNot) "
                  "VALUES (:Name, :YearBuilt, :Type, :BuiltOrNot)");
    query.bindValue(":Name",       name);
    query.bindValue(":YearBuilt",  builtY);
    query.bindValue(":Type",       type);
    query.bindValue(":BuiltOrNot", builtOrNot);

    return query.exec();
}
コード例 #15
0
ファイル: mainwindow.cpp プロジェクト: axelboga/hopur32
void MainWindow::displayComputer(vector<Computer> computers) {
    ui->table_computers->clearContents();
    ui->table_computers->setRowCount(computers.size());

    for (unsigned int i = 0; i < computers.size(); i++) {
        Computer currentComputer = computers.at(i);
        QString Name = QString::fromStdString(currentComputer.getName());
        QString Type = QString::fromStdString(currentComputer.getType());
        QString WasBuilt = QString::fromStdString(currentComputer.getWasBuilt());
        QString Year = QString::fromStdString(currentComputer.getYear());

        ui->table_computers->setItem(i, 0, new QTableWidgetItem(Name));
        ui->table_computers->setItem(i, 1, new QTableWidgetItem(Type));
        ui->table_computers->setItem(i, 2, new QTableWidgetItem(WasBuilt));
        ui->table_computers->setItem(i, 3, new QTableWidgetItem(Year));
    }
    currentlyDisplayedComputers = computers;
}
コード例 #16
0
bool Computerrepository::updateComputer(Computer computerUpdate) {
    QSqlQuery query;

    int     id         = computerUpdate.getId();
    QString name       = QString::fromStdString((computerUpdate.getName()));
    int     builtY     = computerUpdate.getBuildYear();
    QString type       = QString::fromStdString((computerUpdate.getType()));
    bool    builtOrNot = computerUpdate.getBuild();

    query.prepare("UPDATE Computers SET Name=:Name, YearBuilt=:YearBuilt,"
                        " Type=:Type, BuiltOrNot=:BuiltOrNot WHERE id=:id");
    query.bindValue(":id",         id);
    query.bindValue(":Name",       name);
    query.bindValue(":YearBuilt",  builtY);
    query.bindValue(":Type",       type);
    query.bindValue(":BuiltOrNot", builtOrNot);

    return query.exec();
}
コード例 #17
0
bool DbManager::addComputer(Computer comp)
{
    QString was_built = "";
    switch (comp.getBuilt())
    {
    case 0:
        was_built = "0";
        break;
    case 1:
        was_built = "1";
        break;
    }

    return execQuery("INSERT INTO Computers (name, year, type, built) "
                     "VALUES ( '" +
                     comp.getName() + "'," +
                     comp.getYear() + ",'" +
                     comp.getType() + "', " +
                     was_built + " )");
}
コード例 #18
0
bool DbManager::editComputer(Computer comp)
{
    QString was_built = "";
    switch (comp.getBuilt())
    {
    case 0:
        was_built = "0";
        break;
    case 1:
        was_built = "1";
        break;
    }

    return execQuery("UPDATE Computers "
                     "SET name = '" + comp.getName() + "', "
                     "year = " + comp.getYear() + ", "
                     "type = '" + comp.getType() + "', "
                     "built = " + was_built + " "
                     "WHERE cID = " + comp.getId());
}
コード例 #19
0
ファイル: addcomtosci.cpp プロジェクト: alexi15/verk1
void addComToSci::displayComputers()
{
    ui->table_computers->clearContents();

    ui->table_computers->setRowCount(computers.size());

    for(unsigned int i = 0; i < computers.size(); i++){
        Computer current = computers[i];

        QString name = QString::fromStdString(current.getName());
        QString buildYear = QString::number(current.getBuildYear());
        QString type = QString::fromStdString(current.getType());
        QString made = QString::fromStdString(current.getMade());
        QString Id = QString::number(current.getID());

        ui->table_computers->setItem(i, 0, new QTableWidgetItem(name));
        ui->table_computers->setItem(i, 1, new QTableWidgetItem(buildYear));
        ui->table_computers->setItem(i, 2, new QTableWidgetItem(type));
        ui->table_computers->setItem(i, 3, new QTableWidgetItem(made));
        ui->table_computers->setItem(i, 4, new QTableWidgetItem(Id));
        ui->table_computers->setColumnHidden(4, true);
    }
}
コード例 #20
0
ファイル: menu.cpp プロジェクト: Njallzzz/Skilaverkefni
Computer SearchComputerMenu() {
    Computer temp;    char key = 0;   QTextStream in(stdin);
    temp.setName("");
    temp.setType("");
    temp.setWasBuilt(2);
    while( key != '5' ) {           // while looping while inserting search parameters
        cout << "Please specify search parameters" << endl;
        cout << "\t1. Search by name(";
        if( temp.getName() == "" )               // If wildcard
            cout << "any)" << endl;
        else                                // if user specified
            cout << temp.getName().toUtf8().constData() << ")" << endl;     // Write current name parameters

        cout << "\t2. Search by type(";
        if( temp.getType() == "" )              // If wildcard
            cout << "any)" << endl;
        else
            cout << temp.getType().toUtf8().constData() << ")" << endl;     // Write current type parameters

        cout << "\t3. Search by built(";
        if( temp.getWasBuilt() == 2 )         // If wildcard
            cout << "any)" << endl;
        else if( temp.getWasBuilt() == 0 )                               // if user specified
            cout << "not built)" << endl;  // Write current birth parameters
        else if( temp.getWasBuilt() == 1 )
            cout << "built)" << endl;  // Write current birth parameters

        cout << "\t4. Search by year(";
        if( temp.getYear() == "" )         // If wildcard
            cout << "any)" << endl;
        else                                // if user specified
            cout << temp.getYear().toUtf8().constData() << ")" << endl;  // Write current death parameters
        cout << "\t5. Search" << endl;

        cout << "Your choice: ";
        cin >> key;                 // Get user input for next action, 1: name parameter, 2: gender parameter, 3: birth parameter, 4: death parameter and 5: Search
        cin.ignore();

        if( key == '1' ) {          // Set user name search parameter
            cout << "Insert name to search for: ";
            temp.setName( in.readLine() );
        } else if( key == '2' ) {   // Set user type search parameter
            cout << "Insert type to search for: ";
            temp.setType( in.readLine() );
        } else if( key == '3' ) {   // Set user birth search parameter
            temp.setWasBuilt( -1 );
            while( (temp.getWasBuilt() < 0) || (temp.getWasBuilt() > 2) ) {
                QString built;
                cout << "Insert built or not to search for(any/built/not built): ";
                built = in.readLine();
                if( built == "any" || built == "Any" )
                    temp.setWasBuilt( 2 );
                else if( built == "not built" || built == "Not built" || built == "not Built" || built == "Not Built" )
                    temp.setWasBuilt( 0 );
                else if( built == "built" || built == "Built" )
                    temp.setWasBuilt( 1 );
                else
                    cout << "Invalid input!" << endl;
            }
        } else if( key == '4' ) {   // Set user death search parameter
            QString deathstring = "";
            temp.setYear( "" );   // Set empty date (Also used as wildcard)
            while( deathstring != "0" && temp.getYear() == "" ) {
                cout << "Insert death date(dd.mm.yyyy, 0 for any): ";
                deathstring = in.readLine();
                if( deathstring != "0" )
                    temp.setYear( deathstring );
            }
        }
    }
    cout << endl;
    return temp;        // Returns template for person to search for
}
コード例 #21
0
ファイル: ymanager.cpp プロジェクト: AbuMussabRaja/yarp
bool YConsoleManager::process(const vector<string> &cmdList)
{
    if (!cmdList.size() || cmdList[0] == "")
        return true;

    /**
     * help
     */
     if((cmdList.size() == 1) &&
        (cmdList[0] == "help"))
     {
         help();
         return true;
     }


    /**
     * add application
     */
     if((cmdList.size() == 3) &&
        (cmdList[0] == "add") && (cmdList[1] == "app"))
     {
         if(addApplication(cmdList[2].c_str()))
            cout<<INFO<<cmdList[2]<<" is successfully added."<<ENDC<<endl;
         reportErrors();
        #ifdef WITH_READLINE
        updateAppNames(&appnames);
        #endif
         return true;
     }

    /**
     * add module
     */
     if((cmdList.size() == 3) &&
        (cmdList[0] == "add") && (cmdList[1] == "mod"))
     {
         if(addModule(cmdList[2].c_str()))
            cout<<INFO<<cmdList[2]<<" is successfully added."<<ENDC<<endl;
         reportErrors();
         return true;
     }

    /**
     * add resource
     */
     if((cmdList.size() == 3) &&
        (cmdList[0] == "add") && (cmdList[1] == "res"))
     {
         if(addResource(cmdList[2].c_str()))
            cout<<INFO<<cmdList[2]<<" is successfully added."<<ENDC<<endl;
         reportErrors();
         return true;
     }


    /**
     * load application
     */
     if((cmdList.size() == 3) &&
        (cmdList[0] == "load") && (cmdList[1] == "app"))
     {
         if(loadApplication(cmdList[2].c_str()))
         {
            //cout<<cmdList[2]<<" is successfully loaded."<<endl;
            which();
         }
         reportErrors();
         return true;
     }

    /**
     * load module
     */
    /*
     if((cmdList.size() >= 3) &&
        (cmdList[0] == "load") && (cmdList[1] == "mod"))
     {
         if(cmdList.size() > 3)
         {
            if(manager.loadModule(cmdList[2].c_str(), cmdList[3].c_str()))
                cout<<cmdList[2]<<" is successfully loaded."<<endl;
         }
        else
            if(manager.loadModule(cmdList[2].c_str()))
                cout<<cmdList[2]<<" is successfully loaded."<<endl;
         reportErrors();
         return true;
     }
    */

    /**
     * run
     */
     if((cmdList.size() == 1) &&
        (cmdList[0] == "run"))
     {
         bShouldRun = run();
         reportErrors();
         return true;
     }
     if((cmdList.size() >= 2) &&
        (cmdList[0] == "run"))
     {
        bShouldRun = false;
        for(unsigned int i=1; i<cmdList.size(); i++)
            bShouldRun |= run(atoi(cmdList[i].c_str()));
        reportErrors();
        return true;
     }

    /**
     * stop
     */
     if((cmdList.size() == 1) &&
        (cmdList[0] == "stop"))
     {
         bShouldRun = false;
         stop();
         reportErrors();
         return true;
     }
     if((cmdList.size() >= 2) &&
        (cmdList[0] == "stop"))
     {
         //bShouldRun = false;
        for(unsigned int i=1; i<cmdList.size(); i++)
            stop(atoi(cmdList[i].c_str()));
         bShouldRun = !suspended();
         reportErrors();
         return true;
     }

    /**
     * kill
     */
     if((cmdList.size() == 1) &&
        (cmdList[0] == "kill"))
     {
         bShouldRun = false;
         kill();
         reportErrors();
         return true;
     }
     if((cmdList.size() >= 2) &&
        (cmdList[0] == "kill"))
     {
         //bShouldRun = false;
         for(unsigned int i=1; i<cmdList.size(); i++)
            kill(atoi(cmdList[i].c_str()));
         bShouldRun = !suspended();
         reportErrors();
         return true;
     }

    /**
     * connect
     */
     if((cmdList.size() == 1) &&
        (cmdList[0] == "connect"))
     {
         connect();
         reportErrors();
         return true;
     }
     if((cmdList.size() >= 2) &&
        (cmdList[0] == "connect"))
     {
        for(unsigned int i=1; i<cmdList.size(); i++)
            connect(atoi(cmdList[i].c_str()));
        reportErrors();
        return true;
     }


    /**
     * disconnect
     */
     if((cmdList.size() == 1) &&
        (cmdList[0] == "disconnect"))
     {
         disconnect();
         reportErrors();
         return true;
     }
     if((cmdList.size() >= 2) &&
        (cmdList[0] == "disconnect"))
     {
        for(unsigned int i=1; i<cmdList.size(); i++)
            disconnect(atoi(cmdList[i].c_str()));
        reportErrors();
        return true;
     }


    /**
     * which
     */
     if((cmdList.size() == 1) &&
        (cmdList[0] == "which"))
     {
        which();
        return true;
     }

    /**
     * check for dependencies
     */
    if((cmdList.size() == 2) &&
        (cmdList[0] == "check") && (cmdList[1] == "dep"))
    {
        if(checkDependency())
            cout<<INFO<<"All of resource dependencies are satisfied."<<ENDC<<endl;
        reportErrors();
        return true;
    }


    /**
     * check for running state
     */
    if((cmdList.size() == 3) &&
        (cmdList[0] == "check") && (cmdList[1] == "state"))
    {
        ExecutablePContainer modules = getExecutables();
        unsigned int id = (unsigned int)atoi(cmdList[2].c_str());
        if(id>=modules.size())
        {
            cout<<FAIL<<"ERROR:   "<<INFO<<"Module id is out of range."<<ENDC<<endl;
            return true;
        }

        if(running(id))
            cout<<OKGREEN<<"<RUNNING> ";
        else
            cout<<FAIL<<"<STOPPED> ";
        cout<<INFO<<"("<<id<<") ";
        cout<<modules[id]->getCommand();
        cout<<" ["<<modules[id]->getHost()<<"]"<<ENDC<<endl;
        reportErrors();
        return true;
    }
    if((cmdList.size() == 2) &&
        (cmdList[0] == "check") && (cmdList[1] == "state"))
    {
        checkStates();
        reportErrors();
        return true;
    }


    /**
     * check for connection state
     */
    if((cmdList.size() == 3) &&
        (cmdList[0] == "check") && (cmdList[1] == "con"))
    {

        CnnContainer connections  = getConnections();
        unsigned int id = (unsigned int)atoi(cmdList[2].c_str());
        if(id>=connections.size())
        {
            cout<<FAIL<<"ERROR:   "<<INFO<<"Connection id is out of range."<<ENDC<<endl;
            return true;
        }

        if(connected(id))
            cout<<OKGREEN<<"<CONNECTED> ";
        else
            cout<<FAIL<<"<DISCONNECTED> ";

        cout<<INFO<<"("<<id<<") ";
        cout<<connections[id].from()<<" - "<<connections[id].to();
                cout<<" ["<<connections[id].carrier()<<"]"<<ENDC<<endl;
        reportErrors();
        return true;
    }
    if((cmdList.size() == 2) &&
        (cmdList[0] == "check") && (cmdList[1] == "con"))
    {
        checkConnections();
        return true;
    }



    /**
     *  list available modules
     */
    if((cmdList.size() == 2) &&
        (cmdList[0] == "list") && (cmdList[1] == "mod"))
    {
        KnowledgeBase* kb = getKnowledgeBase();
        ModulePContainer mods =  kb->getModules();
        int id = 0;
        for(ModulePIterator itr=mods.begin(); itr!=mods.end(); itr++)
        {
            string fname;
            string fpath = (*itr)->getXmlFile();

            size_t pos = fpath.rfind(PATH_SEPERATOR);
            if(pos!=string::npos)
                fname = fpath.substr(pos);
            else
                fname = fpath;
            cout<<INFO<<"("<<id++<<") ";
            cout<<OKBLUE<<(*itr)->getName()<<ENDC;
            cout<<INFO<<" ["<<fname<<"]"<<ENDC<<endl;
        }
        return true;
    }


    /**
     *  list available applications
     */
    if((cmdList.size() == 2) &&
        (cmdList[0] == "list") && (cmdList[1] == "app"))
    {
        KnowledgeBase* kb = getKnowledgeBase();
        ApplicaitonPContainer apps =  kb->getApplications();
        int id = 0;
        for(ApplicationPIterator itr=apps.begin(); itr!=apps.end(); itr++)
        {
            string fname;
            string fpath = (*itr)->getXmlFile();

            size_t pos = fpath.rfind(PATH_SEPERATOR);
            if(pos!=string::npos)
                fname = fpath.substr(pos);
            else
                fname = fpath;
            cout<<INFO<<"("<<id++<<") ";
            cout<<OKBLUE<<(*itr)->getName()<<ENDC;
            cout<<INFO<<" ["<<fname<<"]"<<ENDC<<endl;
        }
        return true;
    }

    /**
     *  list available resources
     */
    if((cmdList.size() == 2) &&
        (cmdList[0] == "list") && (cmdList[1] == "res"))
    {
        KnowledgeBase* kb = getKnowledgeBase();
        ResourcePContainer resources = kb->getResources();
        int id = 0;
        for(ResourcePIterator itr=resources.begin(); itr!=resources.end(); itr++)
        {
            Computer* comp = dynamic_cast<Computer*>(*itr);
            if(comp)
            {
                string fname;
                string fpath = comp->getXmlFile();
                size_t pos = fpath.rfind(PATH_SEPERATOR);
                if(pos!=string::npos)
                    fname = fpath.substr(pos);
                else
                    fname = fpath;
                cout<<INFO<<"("<<id++<<") ";
                if(comp->getDisable())
                    cout<<WARNING<<comp->getName()<<ENDC;
                else
                    cout<<OKBLUE<<comp->getName()<<ENDC;
                cout<<INFO<<" ["<<fname<<"]"<<ENDC<<endl;
            }
        }
        return true;
    }


    /**
     *  export knowledgebase graph
     */
    if((cmdList.size() == 2) &&
        (cmdList[0] == "export") )
    {
        if(!exportDependencyGraph(cmdList[1].c_str()))
            cout<<FAIL<<"ERROR:   "<<INFO<<"Cannot export graph to "<<cmdList[1]<<"."<<ENDC<<endl;
        return true;
    }


    /**
     * show module's information
     */
    if((cmdList.size() == 3) &&
        (cmdList[0] == "show") && (cmdList[1] == "mod"))
    {
        KnowledgeBase* kb = getKnowledgeBase();
        if(!kb->getModule(cmdList[2].c_str()))
        {
            cout<<FAIL<<"ERROR:   "<<INFO<<"'"<<cmdList[2].c_str()<<"' not found."<<ENDC<<endl;
            return true;
        }
        cout<<INFO;
        PRINT_MODULE(kb->getModule(cmdList[2].c_str()));
        cout<<ENDC;
        return true;
    }

    /**
     * set an option
     */
     if((cmdList.size() == 3) &&
        (cmdList[0] == "set"))
     {
         config.unput(cmdList[1].c_str());
         config.put(cmdList[1].c_str(), cmdList[2].c_str());

        if(cmdList[1] == string("watchdog"))
        {
            if(cmdList[2] == string("yes"))
                enableWatchDog();
            else
                disableWatchod();
        }

        if(cmdList[1] == string("auto_dependency"))
        {
            if(cmdList[2] == string("yes"))
                enableAutoDependency();
            else
                disableAutoDependency();
        }

        if(cmdList[1] == string("auto_connect"))
        {
            if(cmdList[2] == string("yes"))
                enableAutoConnect();
            else
                disableAutoConnect();
        }

        if(cmdList[1] == string("color_theme"))
        {
            if(cmdList[2] == string("dark"))
                setColorTheme(THEME_DARK);
            else if(cmdList[2] == string("light"))
                setColorTheme(THEME_LIGHT);
            else
                setColorTheme(THEME_NONE);
        }

        return true;
     }


    /**
     * get an option
     */
     if((cmdList.size() == 2) &&
        (cmdList[0] == "get"))
     {
         if(config.check(cmdList[1].c_str()))
         {
            cout<<OKBLUE<<cmdList[1]<<INFO<<" = ";
            cout<<OKGREEN<<config.find(cmdList[1].c_str()).asString()<<ENDC<<endl;
         }
         else
            cout<<FAIL<<"ERROR:   "<<INFO<<"'"<<cmdList[1].c_str()<<"' not found."<<ENDC<<endl;
         return true;
     }

    /**
     * load balancing
     */
    if((cmdList.size() == 2) &&
        (cmdList[0] == "assign") && (cmdList[1] == "hosts"))
    {
        loadBalance();
        reportErrors();
        return true;
    }

    return false;
}
コード例 #22
0
void ModulePropertyWindow::update(Module* module)
{
    m_pModule = module;
    m_refTreeModel->clear();
    m_refModelCombos.clear();

    Gtk::TreeModel::Row row;
    Gtk::TreeModel::Row childrow;
//    Gtk::TreeModel::Row cchildrow;

    Glib::RefPtr<Gtk::ListStore> m_refCombo = Gtk::ListStore::create(m_ColumnsCombo);
    //row = *(m_refCombo->append());
    //row[m_ColumnsCombo.m_col_choice] = "---";
    m_refModelCombos.push_back(m_refCombo);


    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Name";
    row[m_Columns.m_col_value] = m_pModule->getName();
    row[m_Columns.m_col_color_value] = Gdk::Color("#888888");
    row[m_Columns.m_col_editable] = false;
    row[m_Columns.m_col_choices] = m_refModelCombos.back();

    /*
    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Description";
    row[m_Columns.m_col_value] = m_pModule->getDescription();
    row[m_Columns.m_col_color_value] = Gdk::Color("#888888");
    row[m_Columns.m_col_editable] = false;
    row[m_Columns.m_col_choices] = m_refModelCombos.back();
    */

    //node
    m_refCombo = Gtk::ListStore::create(m_ColumnsCombo);
    row = *(m_refCombo->append());
    row[m_ColumnsCombo.m_col_choice] = "localhost";
    ResourcePContainer resources = m_pManager->getKnowledgeBase()->getResources();
    for(ResourcePIterator itr=resources.begin(); itr!=resources.end(); itr++)
    {
        Computer* comp = dynamic_cast<Computer*>(*itr);
        if(comp && !compareString(comp->getName(), "localhost"))
        {
            row = *(m_refCombo->append());
            row[m_ColumnsCombo.m_col_choice] = comp->getName();          
        }
    }
 
    m_refModelCombos.push_back(m_refCombo);
    
    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Node";
    row[m_Columns.m_col_value] = m_pModule->getHost();
    row[m_Columns.m_col_editable] = true;
    row[m_Columns.m_col_choices] = m_refModelCombos.back();

    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Stdio";
    row[m_Columns.m_col_value] = m_pModule->getStdio();
    row[m_Columns.m_col_editable] = true;
    row[m_Columns.m_col_choices] = m_refModelCombos.back();

    m_refCombo = Gtk::ListStore::create(m_ColumnsCombo);
    m_refModelCombos.push_back(m_refCombo);

    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Workdir";
    row[m_Columns.m_col_value] = m_pModule->getWorkDir();
    row[m_Columns.m_col_editable] = true;
    row[m_Columns.m_col_choices] = m_refModelCombos.back();

    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Prefix";
    row[m_Columns.m_col_value] = m_pModule->getBasePrefix();
    row[m_Columns.m_col_editable] = true;
    row[m_Columns.m_col_choices] = m_refModelCombos.back();

    //Deployer
    m_refCombo = Gtk::ListStore::create(m_ColumnsCombo);
    if(compareString(m_pModule->getBroker(), "yarpdev"))
    {
        row = *(m_refCombo->append());
        row[m_ColumnsCombo.m_col_choice] = "yarpdev";
    }
    else if(compareString(m_pModule->getBroker(), "icubmoddev"))
    {
        row = *(m_refCombo->append());
        row[m_ColumnsCombo.m_col_choice] = "icubmoddev";
    }
    else
    {
        row = *(m_refCombo->append());
        row[m_ColumnsCombo.m_col_choice] = "local";
        row = *(m_refCombo->append());
        row[m_ColumnsCombo.m_col_choice] = "yarprun";
    }
    m_refModelCombos.push_back(m_refCombo);

    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Deployer";
    if(strlen(m_pModule->getBroker()))
        row[m_Columns.m_col_value] = m_pModule->getBroker();
    else if(compareString(m_pModule->getHost(), "localhost"))
        row[m_Columns.m_col_value] = "local";
        
    if(m_pModule->getNeedDeployer())
    {  
        row[m_Columns.m_col_editable] = false;
        row[m_Columns.m_col_color_value] = Gdk::Color("#888888");
    }    
    else
        row[m_Columns.m_col_editable] = true;
    row[m_Columns.m_col_choices] = m_refModelCombos.back();

    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Parameters";
    row[m_Columns.m_col_value] = m_pModule->getParam();
    row[m_Columns.m_col_color_value] = Gdk::Color("#888888");
    row[m_Columns.m_col_editable] = false;
    row[m_Columns.m_col_choices] = m_refModelCombos.back();

    for(int i=0; i<m_pModule->argumentCount(); i++)
    {
        Gtk::TreeModel::Row comboRow;
        m_refCombo = Gtk::ListStore::create(m_ColumnsCombo);
        comboRow = *(m_refCombo->append());
        if(!m_pModule->getArgumentAt(i).isSwitch())
            comboRow[m_ColumnsCombo.m_col_choice] = m_pModule->getArgumentAt(i).getDefault();
        else
        {
            comboRow[m_ColumnsCombo.m_col_choice] = "on";    
            comboRow = *(m_refCombo->append());
            comboRow[m_ColumnsCombo.m_col_choice] = "off";
        }
        m_refModelCombos.push_back(m_refCombo);
     
        childrow = *(m_refTreeModel->append(row.children()));
        childrow[m_Columns.m_col_name] = m_pModule->getArgumentAt(i).getParam();
        childrow[m_Columns.m_col_value] = m_pModule->getArgumentAt(i).getValue();
        Glib::ustring strval = childrow[m_Columns.m_col_value];
        if(m_pModule->getArgumentAt(i).isRequired() 
            && !strval.size())
            childrow[m_Columns.m_col_color_item] = Gdk::Color("#BF0303");
        childrow[m_Columns.m_col_editable] = true;
        childrow[m_Columns.m_col_choices] = m_refModelCombos.back();
    }
    
    //updateParamteres();

    m_TreeView.expand_all();

}
コード例 #23
0
void PropertiesTable::showModuleTab(Module *mod)
{
    modules.clear();
    disconnect(moduleProperties,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onModItemChanged(QTreeWidgetItem*,int)));
    disconnect(moduleProperties,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(onModItemDoubleClicked(QTreeWidgetItem*,int)));

    currentApplication = NULL;
    currentModule = mod;
    propertiesTab->clear();
    propertiesTab->addTab(moduleProperties,"Module Properties");
    propertiesTab->addTab(moduleDescription,"Description");
    moduleProperties->clear();
    moduleDescription->clear();

    appProperties->hide();
    moduleProperties->show();
    moduleDescription->show();

    modName = new QTreeWidgetItem(moduleProperties,QStringList() << "Name" << mod->getName());
    modNode = new QTreeWidgetItem(moduleProperties,QStringList() << "Node");
    modStdio = new QTreeWidgetItem(moduleProperties,QStringList() << "Stdio" << mod->getStdio());
    modWorkDir = new QTreeWidgetItem(moduleProperties,QStringList() << "Workdir" << mod->getWorkDir());
    modPrefix = new QTreeWidgetItem(moduleProperties,QStringList() << "Prefix" << mod->getBasePrefix());
    modDeployer = new QTreeWidgetItem(moduleProperties,QStringList() << "Deployer");
    modParams = new QTreeWidgetItem(moduleProperties,QStringList() << "Parameters" << mod->getParam());

    lastPrefix = mod->getBasePrefix();

    modStdio->setFlags(modStdio->flags() | Qt::ItemIsEditable);
    modWorkDir->setFlags(modWorkDir->flags() | Qt::ItemIsEditable);
    modPrefix->setFlags(modPrefix->flags() | Qt::ItemIsEditable);

    moduleProperties->addTopLevelItem(modName);
    moduleProperties->addTopLevelItem(modNode);
    moduleProperties->addTopLevelItem(modStdio);
    moduleProperties->addTopLevelItem(modWorkDir);
    moduleProperties->addTopLevelItem(modPrefix);
    moduleProperties->addTopLevelItem(modDeployer);
    moduleProperties->addTopLevelItem(modParams);

    if(deployerCombo){
        delete deployerCombo;
        deployerCombo = NULL;
    }

    if(nodeCombo){
        delete nodeCombo;
        nodeCombo = NULL;
    }
    deployerCombo = new QComboBox();
    nodeCombo = new QComboBox();

    deployerCombo->setEditable(true);
    nodeCombo->setEditable(true);

    if(compareString(mod->getBroker(),"yarpdev")){
        deployerCombo->addItem("yarpdev");
    }else if(compareString(mod->getBroker(),"icubmoddev")){
        deployerCombo->addItem("icubmoddev");
    }else{
        deployerCombo->addItem("local");
        deployerCombo->addItem("yarprun");
    }

    if(strlen(mod->getBroker())){
        deployerCombo->setCurrentText(mod->getBroker());
    }else if(compareString(mod->getHost(),"localhost")){
        deployerCombo->setCurrentText("local");
    }
    if(mod->getNeedDeployer()){
        deployerCombo->setEditable(false);
    }


    nodeCombo->addItem(mod->getHost());
    if(QString(mod->getHost()) != "localhost"){
        nodeCombo->addItem("localhost");
    }
    ResourcePContainer resources = manager->getKnowledgeBase()->getResources();
    for(ResourcePIterator itr=resources.begin(); itr!=resources.end(); itr++){
        Computer* comp = dynamic_cast<Computer*>(*itr);
        if(comp && !compareString(comp->getName(), "localhost")){
            nodeCombo->addItem(comp->getName());
        }
    }
    connect(nodeCombo, SIGNAL(editTextChanged(QString)), paramsSignalMapper, SLOT(map()));
    connect(nodeCombo, SIGNAL(currentIndexChanged(int)), paramsSignalMapper, SLOT(map()));
    paramsSignalMapper->setMapping(nodeCombo,nodeCombo);

    connect(deployerCombo, SIGNAL(editTextChanged(QString)), paramsSignalMapper, SLOT(map()));
    connect(deployerCombo, SIGNAL(currentIndexChanged(int)), paramsSignalMapper, SLOT(map()));
    paramsSignalMapper->setMapping(deployerCombo,deployerCombo);




     /*****************************/
     // Populate paramters
     for(int i=0;i<mod->argumentCount();i++){
         Argument a = mod->getArgumentAt(i);
         QTreeWidgetItem *it = new QTreeWidgetItem(modParams,QStringList() << a.getParam());
         QComboBox *paramCombo = new QComboBox();
         paramCombo->setEditable(true);
         paramCombo->addItem(a.getValue());
         if(strcmp(a.getDefault(),a.getValue()) != 0 ){
            paramCombo->addItem(a.getDefault());
         }
         moduleProperties->setItemWidget(it,1,paramCombo);
         connect(paramCombo, SIGNAL(editTextChanged(QString)), paramsSignalMapper, SLOT(map()));
         connect(paramCombo, SIGNAL(currentIndexChanged(int)), paramsSignalMapper, SLOT(map()));
         paramsSignalMapper->setMapping(paramCombo,paramCombo);
     }
     /*****************************/

    moduleProperties->setItemWidget(modDeployer,1,deployerCombo);
    moduleProperties->setItemWidget(modNode,1,nodeCombo);
    modParams->setExpanded(true);


    QTreeWidgetItem *nameItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Name" << mod->getName());
    QTreeWidgetItem *versionItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Version" << mod->getVersion());
    QTreeWidgetItem *descriptionItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Description" << mod->getDescription());
    QTreeWidgetItem *parametersItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Parameters");
    for(int i=0;i<mod->argumentCount();i++){
        Argument a = mod->getArgumentAt(i);
        QTreeWidgetItem *it = new QTreeWidgetItem(parametersItem,QStringList() << a.getParam() << a.getDescription());

    }

    QTreeWidgetItem *authorsItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Authors" );
    for(int i=0;i<mod->authorCount();i++){
        Author a = mod->getAuthorAt(i);
        QTreeWidgetItem *it = new QTreeWidgetItem(authorsItem,QStringList() << a.getName() << a.getEmail());
    }

    QTreeWidgetItem *inputsItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Inputs" );
    for(int i=0;i<mod->inputCount();i++){
        InputData a = mod->getInputAt(i);

        QTreeWidgetItem *type = new QTreeWidgetItem(inputsItem,QStringList() << "Type" << a.getName());
        QTreeWidgetItem *port = new QTreeWidgetItem(type,QStringList() << "Port" << a.getPort());
        QTreeWidgetItem *desc = new QTreeWidgetItem(type,QStringList() << "Description" << a.getDescription());
        QTreeWidgetItem *req = new QTreeWidgetItem(type,QStringList() << "Required" << (a.isRequired() ? "yes" : "no"));
        Q_UNUSED(port);
        Q_UNUSED(desc);
        Q_UNUSED(req);
    }

    QTreeWidgetItem *outputsItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Outputs" );
    for(int i=0;i<mod->outputCount();i++){
        OutputData a = mod->getOutputAt(i); //TODO controllare

        QTreeWidgetItem *type = new QTreeWidgetItem(outputsItem,QStringList() << "Type" << a.getName());
        QTreeWidgetItem *port = new QTreeWidgetItem(type,QStringList() << "Port" << a.getPort());
        QTreeWidgetItem *desc = new QTreeWidgetItem(type,QStringList() << "Description" << a.getDescription());
        Q_UNUSED(port);
        Q_UNUSED(desc);
    }

    moduleDescription->addTopLevelItem(nameItem);
    moduleDescription->addTopLevelItem(versionItem);
    moduleDescription->addTopLevelItem(descriptionItem);
    moduleDescription->addTopLevelItem(parametersItem);
    moduleDescription->addTopLevelItem(authorsItem);
    moduleDescription->addTopLevelItem(inputsItem);
    moduleDescription->addTopLevelItem(outputsItem);

    connect(moduleProperties,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onModItemChanged(QTreeWidgetItem*,int)));
    connect(moduleProperties,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(onModItemDoubleClicked(QTreeWidgetItem*,int)));

}