void work(void)
    {
        #ifdef _MSC_VER
        //TODO use windows API to have timeout
        #else
        //setup timeval for timeout
        timeval tv;
        tv.tv_sec = 0;
        tv.tv_usec = this->workInfo().maxTimeoutNs/1000; //ns->us

        //setup rset for timeout
        fd_set rset;
        FD_ZERO(&rset);
        FD_SET(_fd, &rset);

        //call select with timeout
        if (::select(_fd+1, &rset, NULL, NULL, &tv) <= 0) return this->yield();
        #endif

        auto out0 = this->output(0);
        void *ptr = out0->buffer();
        auto r = read(_fd, ptr, out0->buffer().length);
        if (r == 0 and _rewind) lseek(_fd, 0, SEEK_SET);
        if (r >= 0) out0->produce(size_t(r)/out0->dtype().size());
        else
        {
            poco_error_f3(Poco::Logger::get("BinaryFileSource"), "read() returned %d -- %s(%d)", int(r), std::string(strerror(errno)), errno);
        }
    }
Exemple #2
0
/***********************************************************************
 * Comparison registration handling
 **********************************************************************/
static void handleHashFcnPluginEvent(const Pothos::Plugin &plugin, const std::string &event)
{
    poco_debug_f2(Poco::Logger::get("Pothos.Object.handleHashFcnPluginEvent"), "plugin %s, event %s", plugin.toString(), event);
    POTHOS_EXCEPTION_TRY
    {
        //validate the plugin -- if we want to handle it -- check the signature:
        if (plugin.getObject().type() != typeid(Pothos::Callable)) return;
        const auto &call = plugin.getObject().extract<Pothos::Callable>();
        if (call.type(-1) != typeid(size_t)) return;
        if (call.getNumArgs() != 1) return;

        Poco::RWLock::ScopedWriteLock lock(getMapMutex());
        if (event == "add")
        {
            getHashFcnMap()[call.type(0).hash_code()] = plugin;
        }
        if (event == "remove")
        {
            getHashFcnMap()[call.type(0).hash_code()] = Pothos::Plugin();
        }
    }
    POTHOS_EXCEPTION_CATCH(const Pothos::Exception &ex)
    {
        poco_error_f3(Poco::Logger::get("Pothos.Object.handleHashFcnPluginEvent"),
            "exception %s, plugin %s, event %s", ex.displayText(), plugin.toString(), event);
    }
Exemple #3
0
static void callPluginEventHandler(const Pothos::Object &handler, const Pothos::Plugin &plugin, const std::string &event)
{
    if (not canObjectHandleEvent(handler)) return;
    POTHOS_EXCEPTION_TRY
    {
        handler.extract<Pothos::Callable>().callVoid(plugin, event);
    }
    POTHOS_EXCEPTION_CATCH(const Pothos::Exception &ex)
    {
        poco_error_f3(Poco::Logger::get("Pothos.PluginRegistry.handlePluginEvent"),
        "exception %s, plugin %s, event %s", ex.displayText(), plugin.toString(), event);
    }