コード例 #1
0
ReaderServicePtr LibraryManager::getReaderService(ReaderUnitPtr reader, ReaderServiceType type)
{
    ReaderServicePtr srv;
    for (auto &&itr : libLoaded)
    {
        IDynLibrary *lib = itr.second;

        if (lib->hasSymbol("getReaderService"))
        {
            int (*fptr)(ReaderUnitPtr, ReaderServicePtr &, ReaderServiceType) = nullptr;
            fptr = reinterpret_cast<decltype(fptr)>(lib->getSymbol("getReaderService"));
            assert(fptr);
            fptr(reader, srv, type);
            if (srv)
                break;
        }
    }
    return srv;
}
コード例 #2
0
std::shared_ptr<CardService> LibraryManager::getCardService(std::shared_ptr<Chip> chip,
                                                            CardServiceType type)
{
    std::shared_ptr<CardService> srv;
    for (auto &&itr : libLoaded)
    {
        IDynLibrary *lib = itr.second;

        if (lib->hasSymbol("getCardService"))
        {
            int (*fptr)(std::shared_ptr<Chip>, std::shared_ptr<CardService> &, CardServiceType) = nullptr;
            fptr = reinterpret_cast<decltype(fptr)>(lib->getSymbol("getCardService"));
            assert(fptr);
            fptr(chip, srv, type);
            if (srv)
                break;
        }
    }
    return srv;
}
コード例 #3
0
    std::shared_ptr<AccessControlCardService> LibraryManager::getAccessControlCardService(
            std::shared_ptr<Chip> chip)
    {
        std::shared_ptr<AccessControlCardService> srv;
        for (auto &&itr : libLoaded)
        {
            const std::string &libname = itr.first;
            IDynLibrary *lib = itr.second;

            int (*fptr)(std::shared_ptr<Chip>, std::shared_ptr<AccessControlCardService> &) = nullptr;
            if (lib->hasSymbol("getAccessControlCardService"))
            {
                fptr = reinterpret_cast<decltype(fptr)>(lib->getSymbol("getAccessControlCardService"));
                assert(fptr);
                fptr(chip, srv);
                if (srv)
                    break;
            }
        }
        return srv;
    }
コード例 #4
0
    std::shared_ptr<ReaderUnit> LibraryManager::getReader(const std::string &readerName) const
    {
        // The idea here is simply to loop over all shared library
        // and opportunistically call the `getReaderUnit()` function if it exists, hoping
        // that some module will be able to fulfil our request.
        std::shared_ptr<ReaderUnit> readerUnit;
        for (auto &&itr : libLoaded)
        {
            IDynLibrary *lib = itr.second;

            if (lib->hasSymbol("getReaderUnit"))
            {
				int(*fptr)(const std::string &, std::shared_ptr<ReaderUnit> &) = nullptr;
                fptr = reinterpret_cast<decltype(fptr)>(lib->getSymbol("getReaderUnit"));
                assert(fptr);
                fptr(readerName, readerUnit);
                if (readerUnit)
                    break;
            }
        }
        return readerUnit;
    }
コード例 #5
0
    void LibraryManager::scanPlugins()
    {
        void* fct = NULL;
        boost::filesystem::directory_iterator end_iter;
        std::string extension = EXTENSION_LIB;
        Settings* setting = Settings::getInstance();
        std::string fctname = "getLibraryName";

        for (std::vector<std::string>::iterator it = setting->PluginFolders.begin(); it != setting->PluginFolders.end(); ++it)
        {
            boost::filesystem::path pluginDir(*it);
            if (boost::filesystem::exists(pluginDir) && boost::filesystem::is_directory(pluginDir))
            {
                LOG(LogLevel::PLUGINS) << "Scanning library folder " << pluginDir.string() << " ...";
                for (boost::filesystem::directory_iterator dir_iter(pluginDir); dir_iter != end_iter; ++dir_iter)
                {
                    LOG(LogLevel::PLUGINS) << "Checking library " << dir_iter->path().filename().string() << "...";
                    if ((boost::filesystem::is_regular_file(dir_iter->status()) || boost::filesystem::is_symlink(dir_iter->status()))
                        && dir_iter->path().extension() == extension
                        && (hasEnding(dir_iter->path().filename().string(), enumType[LibraryManager::CARDS_TYPE] + extension)
                        || hasEnding(dir_iter->path().filename().string(), enumType[LibraryManager::READERS_TYPE] + extension)
                        || hasEnding(dir_iter->path().filename().string(), enumType[LibraryManager::UNIFIED_TYPE] + extension)))
                    {
                        try
                        {
                            if (libLoaded.find(dir_iter->path().filename().string()) == libLoaded.end())
                            {
                                IDynLibrary* lib = newDynLibrary(dir_iter->path().string());
                                fct = lib->getSymbol(fctname.c_str());
                                if (fct != NULL)
                                {
                                    LOG(LogLevel::PLUGINS) << "Library " << dir_iter->path().filename().string() << " loaded.";
                                    libLoaded[dir_iter->path().filename().string()] = lib;
                                }
                                else
                                {
                                    LOG(LogLevel::PLUGINS) << "Cannot found library entry point in " << dir_iter->path().filename().string() << ". Skipped.";
                                    delete lib;
                                }
                            }
                            else
                            {
                                LOG(LogLevel::PLUGINS) << "Library " << dir_iter->path().filename().string() << " already loaded. Skipped.";
                            }
                        }
                        catch (const std::exception &e)
                        {
                            LOG(LogLevel::ERRORS) << "Something bad happened when handling " << dir_iter->path().filename().string() <<
                            ": " << e.what();
                        }
                    }
                    else
                    {
                        LOG(LogLevel::PLUGINS) << "File " << dir_iter->path().filename().string() << " does not match excepted filenames. Skipped.";
                    }
                }
            }
            else
            {
                LOG(LogLevel::WARNINGS) << "Cannot found plug-in folder " << (*it);
            }
        }
    }