Example #1
0
bool YarpPluginSettings::open(SharedLibraryFactory& factory) {
    YARP_SPRINTF3(impl::Logger::get(),debug,"Plugin [name: %s] [dll: %s] [fn: %s]",
                  name.c_str(),dll_name.c_str(),fn_name.c_str());
    if (selector!=NULL && name != "") {
        // we may have a YARP-specific search path available,
        // and a proper name for the DLL
        Bottle paths = selector->getSearchPath();
        for (int i=0; i<paths.size(); i++) {
            Searchable& options = paths.get(i);
            ConstString path = options.find("path").asString();
            ConstString ext = options.find("extension").asString();
            ConstString prefix = options.find("prefix").asString();
            ConstString full = path + "/" + prefix + name + ext;
            bool ok = subopen(factory,full,(fn_name=="")?name:fn_name);
            if (ok) return true;
        }
    }
    if (dll_name!=""||fn_name!="") {
        return open(factory,dll_name, fn_name);
    }
#ifdef YARP_HAS_ACE
    bool ok = false;
    ConstString str(name);
    ConstString libName = name;
    ConstString fnName = name;
    int sindex = str.find(":");
    if (sindex>=0) {
        libName = str.substr(0,sindex);
        fnName = str.substr(sindex+1);
        ok = open(factory,libName,fnName);
    }
    if ((!ok) && sindex<0) {
        libName = ConstString("yarp_") + name;
        fnName = name;
        ok = open(factory,libName,fnName);
    }
    if ((!ok) && sindex<0) {
        int index = str.find("_");
        if (index>=0) {
            libName = ConstString("yarp_") + str.substr(0,index);
            fnName = str;
            ok = open(factory,libName,fnName);
        }
    }
    return ok;
#else
    return factory.open(dll_name.c_str(), fn_name.c_str());
#endif
}
Example #2
0
bool YarpPluginSettings::subopen(SharedLibraryFactory& factory, 
                                 const ConstString& dll_name,
                                 const ConstString& fn_name) {
    YARP_SPRINTF2(impl::Logger::get(),debug,"Trying plugin [dll: %s] [fn: %s]",
                  dll_name.c_str(),fn_name.c_str());
    bool ok = factory.open(dll_name.c_str(),fn_name.c_str());
    if (verbose) {
        fprintf(stderr,"Trying to find library '%s' containing function '%s' -- %s\n", dll_name.c_str(), fn_name.c_str(), ok?"found":"not found");
    }
    if (ok) {
        YARP_SPRINTF2(impl::Logger::get(),debug,
                      "Found plugin [dll: %s] [fn: %s]",
                      dll_name.c_str(),fn_name.c_str());
        this->dll_name = dll_name;
        this->fn_name = fn_name;
    }
    return ok;
}
Example #3
0
bool YarpPluginSettings::subopen(SharedLibraryFactory& factory,
                                 const ConstString& dll_name,
                                 const ConstString& fn_name) {
    YARP_SPRINTF2(impl::Logger::get(),debug,"Trying plugin [dll: %s] [fn: %s]",
                  dll_name.c_str(),fn_name.c_str());
    bool ok = factory.open(dll_name.c_str(),fn_name.c_str());
    if (verbose) {
        fprintf(stderr,"Trying to find library '%s' containing function '%s' -- %s\n", dll_name.c_str(), fn_name.c_str(), ok ? "found" :"fail");
    }
    if (ok) {
        YARP_SPRINTF2(impl::Logger::get(),debug,
                      "Found plugin [dll: %s] [fn: %s]",
                      dll_name.c_str(),fn_name.c_str());
        this->dll_name = dll_name;
        this->fn_name = fn_name;
    } else if (verbose || (factory.getStatus() != SharedLibraryFactory::STATUS_LIBRARY_NOT_FOUND)) {
        fprintf(stderr, "error while opening %s:\n  %s\n", dll_name.c_str(), factory.getError().c_str());
    }
    return ok;
}
Example #4
0
bool YarpPluginSettings::open(SharedLibraryFactory& factory) {
    YARP_SPRINTF3(impl::Logger::get(),debug,"Plugin [name: %s] [dll: %s] [fn: %s]",
                  name.c_str(),dll_name.c_str(),fn_name.c_str());
    if (selector!=YARP_NULLPTR && name != "") {
        // we may have a YARP-specific search path available,
        // and a proper name for the DLL
        Bottle paths = selector->getSearchPath();
        for (int i=0; i<paths.size(); i++) {
            Searchable& options = paths.get(i);
            ConstString path = options.find("path").asString();
            ConstString ext = options.find("extension").asString();
            ConstString basename = (dll_name.find('.')!=ConstString::npos) ? name : dll_name;
            ConstString fn = (fn_name=="")?name:fn_name;

            ConstString fullpath;

#if defined(_MSC_VER) && !defined(NDEBUG)
            // MSVC DEBUG build: try debug name before basic name
            fullpath = path + "/" + basename + "d" + ext;
            if (subopen(factory, fullpath, fn))
                return true;
#endif // defined(_MSC_VER) && !defined(NDEBUG)

            // Basic name
            fullpath = path + "/" + basename + ext;
            if (subopen(factory, fullpath, fn))
                return true;

#if defined(_MSC_VER) && defined(NDEBUG)
            // MSVC RELEASE build: try debug name after basic name
            fullpath = path + "/" + basename + "d" + ext;
            if (subopen(factory, fullpath, fn))
                return true;
#endif // defined(_MSC_VER) && defined(NDEBUG)


#ifdef CMAKE_INTDIR
            // On multi-config system, try to find the plugin in the
            // current config subdirectory

#if defined(_MSC_VER) && !defined(NDEBUG)
            // MSVC DEBUG build: try debug name before basic name
            fullpath = path + "/" +  CMAKE_INTDIR + "/" + dll_name + "d" + ext;
            if (subopen(factory, fullpath, fn))
                return true;
#endif // defined(_MSC_VER) && !defined(NDEBUG)

            // Basic name
            fullpath = path + "/" +  CMAKE_INTDIR + "/" + dll_name + ext;
            if (subopen(factory, fullpath, fn))
                return true;

#if defined(_MSC_VER) && defined(NDEBUG)
            // MSVC RELEASE build: try debug name after basic name
            fullpath = path + "/" +  CMAKE_INTDIR + "/" + dll_name + "d" + ext;
            if (subopen(factory, fullpath, fn))
                return true;
#endif // defined(_MSC_VER) && defined(NDEBUG)

#endif // CMAKE_INTDIR

        }
    }
    if (dll_name!=""||fn_name!="") {
        return open(factory, dll_name, fn_name);
    }
    return factory.open((ConstString("yarp_") + name).c_str(),
                        (fn_name=="")?name.c_str():fn_name.c_str());
}