Пример #1
0
// =-=-=-=-=-=-=-
// public - accessor for parent pointer.  return value based on validity of the pointer
    error resource::get_parent( resource_ptr& _resc ) {
        _resc = parent_;
        if ( _resc.get() ) {
            return SUCCESS();
        }
        else {
            return ERROR( SYS_INVALID_INPUT_PARAM, "null parent pointer" );
        }

    } // get_parent
Пример #2
0
// =-=-=-=-=-=-=-
// function to load and return an initialized resource plugin
    error load_resource_plugin( resource_ptr&     _plugin,
                                const std::string _plugin_name,
                                const std::string _inst_name,
                                const std::string _context ) {
        // =-=-=-=-=-=-=-
        // resolve plugin directory
        std::string plugin_home;
        error ret = resolve_plugin_path( PLUGIN_TYPE_RESOURCE, plugin_home );
        if ( !ret.ok() ) {
            return PASS( ret );
        }

        resource* resc = 0;
        ret = load_plugin< resource >(
                  resc,
                  _plugin_name,
                  plugin_home,
                  _inst_name,
                  _context );
        if ( ret.ok() && resc ) {
            _plugin.reset( resc );

        }
        else {
            rodsLog(
                LOG_DEBUG,
                "loading impostor resource for [%s] of type [%s] with context [%s]",
                _inst_name.c_str(),
                _plugin_name.c_str(),
                _context.c_str() );
            _plugin.reset(
                new impostor_resource(
                    "impostor_resource", "" ) );

        }

        return SUCCESS();

    } // load_resource_plugin
Пример #3
0
// =-=-=-=-=-=-=-
// public - add a child resource to this resource.  this is virtual in case a developer wants to
//          do something fancier.
    error resource::add_child( const std::string& _name, const std::string& _data, resource_ptr _resc ) {
        // =-=-=-=-=-=-=-
        // check params
        if ( _name.empty() ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "empty name" );
        }

        if ( 0 == _resc.get() ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "null resource pointer" );
        }

        // =-=-=-=-=-=-=-
        // add resource and data to the table
        children_[ _name ] = std::pair< std::string, resource_ptr >( _data, _resc );

        return SUCCESS();

    } // add_child
        error resolve_from_property( std::string   _prop,    // property key
                                     value_type    _value,   // property value
                                     resource_ptr& _resc ) { // outgoing resource variable
            // =-=-=-=-=-=-=-
            // simple flag to state a resource matching the prop and value is found
            bool found = false;

            // =-=-=-=-=-=-=-
            // quick check on the resource table
            if ( resources_.empty() ) {
                return ERROR( SYS_INVALID_INPUT_PARAM, "empty resource table" );
            }

            // =-=-=-=-=-=-=-
            // iterate through the map and search for our path
            lookup_table< resource_ptr >::iterator itr = resources_.begin();
            for ( ; itr != resources_.end(); ++itr ) {
                // =-=-=-=-=-=-=-
                // query resource for the property value
                value_type value = NULL;
                error ret = itr->second->get_property< value_type >( _prop, value );

                // =-=-=-=-=-=-=-
                // if we get a good parameter
                if ( ret.ok() ) {
                    // =-=-=-=-=-=-=-
                    // compare incoming value and stored value, assumes that the
                    // values support the comparison operator
                    if ( _value == value ) {
                        // =-=-=-=-=-=-=-
                        // if we get a match, cache the resource pointer
                        // in the given out variable and bail
                        found = true;
                        _resc = itr->second;
                        break;
                    }
                }
                else {
                    std::stringstream msg;
                    msg << "resource_manager::resolve_from_property - ";
                    msg << "failed to get vault parameter from resource";
                    irods::error err = PASSMSG( msg.str(), ret );

                }

            } // for itr

            // =-=-=-=-=-=-=-
            // did we find a resource and is the ptr valid?
            if ( true == found && _resc.get() ) {
                return SUCCESS();
            }
            else {
                std::stringstream msg;
                msg << "failed to find resource for property [";
                msg << _prop;
                msg << "] and value [";
                msg << _value;
                msg << "]";
                return ERROR( SYS_RESC_DOES_NOT_EXIST, msg.str() );
            }

        } // resolve_from_property