error impostor_resource::wire_op( 
     const std::string& _key,
     plugin_operation   _op ) {
     // =-=-=-=-=-=-=-
     // add the operation via a wrapper to the operation map
     oper_rule_exec_mgr_ptr rex_mgr(
             new operation_rule_execution_manager(
                 "impostor_resource", _key ) );
     operations_[ _key ] = operation_wrapper(
             rex_mgr,
             "impostor_resource",
             _key,
             _op );
     return SUCCESS();
 } // wire_op
Example #2
0
// =-=-=-=-=-=-=-
// public - function which pulls all of the symbols out of the shared object and
//          associates them with their keys in the operations table
    error database::delay_load(
        void* _handle ) {
        // =-=-=-=-=-=-=-
        // check params
        if ( ! _handle ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "void handle pointer" );
        }

        if ( ops_for_delay_load_.empty() ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "empty operations list" );
        }

        // =-=-=-=-=-=-=-
        // check if we need to load a start function
        if ( !start_opr_name_.empty() ) {
            dlerror();
            database_maintenance_operation start_op = reinterpret_cast< database_maintenance_operation >(
                        dlsym( _handle, start_opr_name_.c_str() ) );
            if ( !start_op ) {
                std::stringstream msg;
                msg  << "failed to load start function ["
                     << start_opr_name_ << "]";
                return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
            }
            else {
                start_operation_ = start_op;
            }
        } // if load start


        // =-=-=-=-=-=-=-
        // check if we need to load a stop function
        if ( !stop_opr_name_.empty() ) {
            dlerror();
            database_maintenance_operation stop_op = reinterpret_cast< database_maintenance_operation >(
                        dlsym( _handle, stop_opr_name_.c_str() ) );
            if ( !stop_op ) {
                std::stringstream msg;
                msg << "failed to load stop function ["
                    << stop_opr_name_ << "]";
                return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
            }
            else {
                stop_operation_ = stop_op;
            }
        } // if load stop


        // =-=-=-=-=-=-=-
        // iterate over list and load function. then add it to the map via wrapper functor
        std::vector< std::pair< std::string, std::string > >::iterator itr = ops_for_delay_load_.begin();
        for ( ; itr != ops_for_delay_load_.end(); ++itr ) {
            // =-=-=-=-=-=-=-
            // cache values in obvious variables
            std::string& key = itr->first;
            std::string& fcn = itr->second;

            // =-=-=-=-=-=-=-
            // check key and fcn name before trying to load
            if ( key.empty() ) {
                std::cout << "[!]\tirods::database::delay_load - empty op key for ["
                          << fcn << "], skipping." << std::endl;
                continue;
            }

            // =-=-=-=-=-=-=-
            // check key and fcn name before trying to load
            if ( fcn.empty() ) {
                std::cout << "[!]\tirods::database::delay_load - empty function name for ["
                          << key << "], skipping." << std::endl;
                continue;
            }

            // =-=-=-=-=-=-=-
            // call dlsym to load and check results
            dlerror();
            plugin_operation res_op_ptr = reinterpret_cast< plugin_operation >( dlsym( _handle, fcn.c_str() ) );
            if ( !res_op_ptr ) {
                std::cout << "[!]\tirods::database::delay_load - failed to load ["
                          << fcn << "].  error - " << dlerror() << std::endl;
                continue;
            }

            // =-=-=-=-=-=-=-
            // add the operation via a wrapper to the operation map
#ifdef LINK_NO_OP_RE_MGR
            oper_rule_exec_mgr_ptr rex_mgr(
                new operation_rule_execution_manager_no_op(
                    instance_name_, key ) );
#else
            oper_rule_exec_mgr_ptr rex_mgr(
                new operation_rule_execution_manager(
                    instance_name_, key ) );
#endif
            // =-=-=-=-=-=-=-
            // add the operation via a wrapper to the operation map
            operations_[ key ] = operation_wrapper(
                                     rex_mgr,
                                     instance_name_,
                                     key,
                                     res_op_ptr );
        } // for itr


        // =-=-=-=-=-=-=-
        // see if we loaded anything at all
        if ( operations_.size() < 0 ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "operations map is emtpy" );
        }

        return SUCCESS();

    } // delay_load