예제 #1
0
TopologyType DatabaseTopology::registerType( const string& name ) throw() {
    TopologyType tmpType;

    // Check if Type is in database
    // Create a new transaction. It gets automatically destroyed at the end of this funtion.
    pqxx::work selectAction(*conn, "registerType");
    // Perform a select
    pqxx::result resultSelect = selectAction.exec(("SELECT id FROM topology.type WHERE name='" + selectAction.esc(name) + "'"));

    // Check if there is only one result, if so -> return the object
    if (resultSelect.size() == 1) {
        TopologyTypeId tmpTypeID;
        // Check if results are sane (and convert them)
        if (!resultSelect[0]["id"].to(tmpTypeID)) {
            assert(false);
        }

        Release<TopologyTypeImplementation> newType(new TopologyTypeImplementation(name, tmpTypeID));
        tmpType.setObject(newType);

        selectAction.commit();

        return tmpType;
    }
    else if (resultSelect.size() != 0) {
        // Something very strange happened
        assert(false);
    }

    // It's not in the database, perform an insert
    resultSelect = selectAction.exec("INSERT INTO topology.type (name) VALUES ('"+selectAction.esc(name)+"') returning id");

    // Check if there is only one result
    if (resultSelect.size() == 1) {
        TopologyTypeId tmpTypeID;
        // Check if results are sane (and convert them)
        if (!resultSelect[0]["id"].to(tmpTypeID)) {
            assert(false);
        }

        Release<TopologyTypeImplementation> newType(new TopologyTypeImplementation(name, tmpTypeID));
        tmpType.setObject(newType);

        selectAction.commit();

        return tmpType;
    }
    else {
        // Something very strange happened
        assert(false);
    }

   return tmpType;
}
예제 #2
0
TopologyType DatabaseTopology::lookupTypeById( TopologyTypeId anId ) throw() {
    string tmpName;

    // Create a new transaction. It gets automatically destroyed at the end of this funtion.
    pqxx::work selectAction(*conn, "lookupTypeById");

    // Perform a select
    pqxx::result resultSelect = selectAction.exec("SELECT name FROM topology.Type WHERE id='"+to_string(anId)+"'");
    selectAction.commit();

    // Check if there is only one result
    if (resultSelect.size() == 1) {
        TopologyType tmpType;
        // Check if results are sane (and convert them)
        if (!resultSelect[0]["name"].to(tmpName)) {
            assert(false);
        }
        Release<TopologyTypeImplementation> newType(new TopologyTypeImplementation(tmpName));
        newType->id = anId;
        tmpType.setObject(newType);
        return tmpType;

    }
    else {
        // Not found
        return TopologyType();
    }
}
예제 #3
0
TopologyType DatabaseTopology::lookupTypeByName( const string& name ) throw() {
    // Create a new transaction. It gets automatically destroyed at the end of this funtion.
    pqxx::work selectAction(*conn, "lookupTypeByName");

    // Perform a select
    pqxx::result resultSelect = selectAction.exec(("SELECT id FROM topology.Type WHERE name='" + selectAction.esc(name) + "'"));
    selectAction.commit();

    // Check if there is only one result
    if (resultSelect.size() == 1) {
        TopologyTypeId tmpId;
        TopologyType tmpType;
        // Check if results are sane (and convert them)
        if (!resultSelect[0]["id"].to(tmpId)) {
            assert(false);
        }

        Release<TopologyTypeImplementation> newType(new TopologyTypeImplementation(name, tmpId));
        tmpType.setObject(newType);

        return tmpType;
    }
    else {
        // Not found
        return TopologyType();
    }
}
예제 #4
0
TopologyType NetworkForwarderTopology::lookupTypeByName( const string& name ) throw() {

    NetworkForwarderRequestMessage mess;
    mess.request_type = NETWORK_FORWARDER_TOPOLOGY_TYPE_REGISTER;
    mess.id = 0;
    mess.name = "";

    BlockingRPCMessage container;
    {
        unique_lock<mutex> lock(container.m);
        client->isend(& mess, & container);

        printf("1");
        fflush(stdout);

        // wait for the response
        container.cv.wait(lock);

        printf("10");
        fflush(stdout);

    }

    TopologyType returnType;
    Release<TopologyTypeImplementation> newType(new TopologyTypeImplementation(name, (size_t) container.response.id));
    returnType.setObject(newType);

    return returnType;
}
예제 #5
0
TopologyType NetworkForwarderTopology::lookupTypeById( TopologyTypeId anId ) throw() {

    NetworkForwarderRequestMessage mess;
    mess.type = NETWORK_FORWARDER_TOPOLOGY_TYPE_LOOKUP_BY_ID;
    mess.id = anId;
    mess.name = "";

    BlockingRPCMessage container;
    {
        unique_lock<mutex> lock(container.m);
        client->isend(& mess, & container);

        // wait for the response
        container.cv.wait(lock);
    }

    TopologyType returnType;
    Release<TopologyTypeImplementation> newType(new TopologyTypeImplementation( container.response.name, anId));
    returnType.setObject(newType);

    return returnType;
}