예제 #1
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();
    }
}
예제 #2
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();
    }
}
예제 #3
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;
}
예제 #4
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;
}
예제 #5
0
	TopologyObject Topology::lookupObjectByPath( const vector<ObjectPathElement> & path, TopologyObjectId parent ) throw(){
		TopologyObjectId resultId = parent;
		TopologyObject result;
		for( size_t i = 0; i < path.size(); i++ ) {
			const ObjectPathElement & curComponent = path[i];
			//Lookup the corresponding relation and update resultId.
			TopologyType relationType = lookupTypeByName( curComponent.relationName );
			if( !relationType ) return TopologyObject();
			TopologyRelation relation = lookupRelation( resultId, relationType.id(), curComponent.name );
			if( !relation )  return TopologyObject();
			resultId = relation.child();
		}
		return lookupObjectById( resultId );
	}
예제 #6
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;
}
    virtual void messageReceivedCB(std::shared_ptr<ServerClientMessage> msg, const char * message_data, uint64_t buffer_size) {

        NetworkForwarderRequestMessage reqMess;
        NetworkForwarderResponseMessage resMess;
        TopologyType type;
        TopologyObject object;
        TopologyRelation relation;
        TopologyAttribute attribute;
        uint64_t pos = 0;

        j_serialization::deserialize(reqMess, message_data, pos, buffer_size);

        switch(reqMess.request_type) {
            case NETWORK_FORWARDER_TOPOLOGY_TYPE_REGISTER: 
                type = topologyBackend->registerType(reqMess.name);

                if(type) {
                    resMess.id = (size_t) type.id();
                }
                else {
                    resMess.id = -1;
                }

                msg->isendResponse(&resMess);
                break;
            case NETWORK_FORWARDER_TOPOLOGY_TYPE_LOOKUP_BY_NAME: 
                type = topologyBackend->lookupTypeByName(reqMess.name);

                if(type) {
                    resMess.id = (size_t) type.id();
                }
                else {
                    resMess.id = -1;
                }

                msg->isendResponse(&resMess);
                break;
            case NETWORK_FORWARDER_TOPOLOGY_TYPE_LOOKUP_BY_ID: 
                type = topologyBackend->lookupTypeById(reqMess.id);

                if(type) {
                    resMess.name = type.name();
                }
                else {
                    //TODO: -1 als reserved keyword okay?
                    resMess.name = "-1";
                }

                msg->isendResponse(&resMess);
                break;

            case NETWORK_FORWARDER_TOPOLOGY_OBJECT_REGISTER:
                object = topologyBackend->registerObject(reqMess.id, reqMess.type, reqMess.name, reqMess.other);

                if(object) {
                    resMess.id = object.id();
                }
                else {
                    resMess.id = -1;
                }

                msg->isendResponse(&resMess);
                break;
            case NETWORK_FORWARDER_TOPOLOGY_OBJECT_LOOKUP:
                object = topologyBackend->lookupObjectById(reqMess.id);

                if(object) {
                    resMess.id = object.id();
                    resMess.type = object.type();
                }
                else {
                    resMess.id = -1;
                }

                msg->isendResponse(&resMess);
                break;

            case NETWORK_FORWARDER_TOPOLOGY_RELATION_REGISTER:
                relation = topologyBackend->registerRelation(reqMess.id, reqMess.type, reqMess.name, reqMess.other);

                if(relation) {
                    // Wont be read, but we'll send a success signal anyway
                    resMess.id = 0;
                }
                else {
                    resMess.id = -1;
                }

                msg->isendResponse(&resMess);
                break;       
            case NETWORK_FORWARDER_TOPOLOGY_RELATION_LOOKUP:
                relation = topologyBackend->lookupRelation(reqMess.id, reqMess.type, reqMess.name);

                if(relation) {
                    resMess.id = relation.child();
                }
                else {
                    resMess.id = -1;
                }

                msg->isendResponse(&resMess);
                break;    
            case NETWORK_FORWARDER_TOPOLOGY_ATTRIBUTE_REGISTER:
                attribute = topologyBackend->registerAttribute(reqMess.id, reqMess.name, (VariableDatatype::Type) reqMess.other);

                if(attribute) {
                    resMess.id = attribute.id();
                }
                else {
                    resMess.id = -1;
                }
                msg->isendResponse(&resMess);

                break;                       
            case NETWORK_FORWARDER_TOPOLOGY_ATTRIBUTE_LOOKUP_BY_NAME:
                attribute = topologyBackend->lookupAttributeByName(reqMess.id, reqMess.name);

                if(attribute) {
                    resMess.id = attribute.id();
                    resMess.other = (intmax_t) attribute.dataType();
                }
                else {
                    resMess.id = -1;
                }
                msg->isendResponse(&resMess);

                break;
    
            case NETWORK_FORWARDER_TOPOLOGY_ATTRIBUTE_LOOKUP_BY_ID:
                attribute = topologyBackend->lookupAttributeById(reqMess.id);

                if(attribute) {
                    resMess.name = attribute.name();
                    resMess.id = attribute.domainId();
                    resMess.other = (intmax_t) attribute.dataType();
                }
                else {
                    resMess.id = -1;
                }
                msg->isendResponse(&resMess);

                break;

            case NETWORK_FORWARDER_TOPOLOGY_ATTRIBUTE_SET:

                bool ret;

                ret = topologyBackend->setAttribute(reqMess.id, reqMess.type, reqMess.var);

                if(ret) {
                    resMess.id = 1;
                }
                else {
                    resMess.id = -1;
                }

                msg->isendResponse(&resMess);

                break;

            case NETWORK_FORWARDER_TOPOLOGY_ATTRIBUTE_GET:

                TopologyValue value = topologyBackend->getAttribute(reqMess.id, reqMess.type);

                if(value) {
                    resMess.id = 1;
                    resMess.var = value.value();
                }
                else {
                    resMess.id = -1;
                }
                msg->isendResponse(&resMess);

                break;                           
        }
    }