Exemplo n.º 1
0
void Executor::run()
{
    Lock xx(mutex);
    while(true) {
        while(head.get()==NULL) {
            xx.unlock();
            moreWork.wait();
            xx.lock();
        }
        CommandPtr command = head;
        if(command.get()==NULL) continue;
        if(command.get()==shutdown.get()) break;
        xx.unlock();
        try {
            command->command();
        }catch(std::exception& e){
            //TODO: feed into logging mechanism
            fprintf(stderr, "Executor: Unhandled exception: %s",e.what());
        }catch(...){
            fprintf(stderr, "Executor: Unhandled exception");
        }

        xx.lock();
    }
    stopped.signal();
}
Exemplo n.º 2
0
void rss_parser::add_item_to_feed(std::tr1::shared_ptr<rss_feed> feed, std::tr1::shared_ptr<rss_item> item) {
	// only add item to feed if it isn't on the ignore list or if there is no ignore list
	if (!ign || !ign->matches(item.get())) {
		feed->add_item(item);
		LOG(LOG_INFO, "rss_parser::parse: added article title = `%s' link = `%s' ign = %p", item->title().c_str(), item->link().c_str(), ign);
	} else {
		LOG(LOG_INFO, "rss_parser::parse: ignored article title = `%s' link = `%s'", item->title().c_str(), item->link().c_str());
	}
}
Exemplo n.º 3
0
void App::pollOSC()
{
    if (0 == osc_receiver_.get())
        return;
    if (osc_receiver_.get()->isRunning())
    {
        std::vector<tempi::Message> messages = osc_receiver_.get()->poll();
        std::vector<tempi::Message>::iterator iter;
        for (iter = messages.begin(); iter != messages.end(); ++iter)
        {
            tempi::Message msg = (*iter);
            if (msg.indexMatchesType(0, tempi::STRING))
                if (! handleOscMessage(msg))
                    std::cout << "Unhandled OSC message: " << msg << std::endl;
                else if (verbose_)
                    std::cout << "Handled OSC message: " << msg << std::endl;
        }
    }
}
Exemplo n.º 4
0
    inline Value push(std::tr1::shared_ptr<T> newProp)
    {
      if (dynamic_cast<NumericProperty*>(newProp.get()))
	{
	  _numericProperties.push_back(Value(newProp));
	  return _numericProperties.back();
	}    
    
      _namedProperties.push_back(Value(newProp));
      return _namedProperties.back();
    }
Exemplo n.º 5
0
DWORD GetMainThreadId(void) 
{
	const std::tr1::shared_ptr<void> hThreadSnapshot(CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0), CloseHandle);
	if (hThreadSnapshot.get() == INVALID_HANDLE_VALUE) 
	{
		add_log("GetMainThreadId failed");
		return 0;
	}
	THREADENTRY32 tEntry;
	tEntry.dwSize = sizeof(THREADENTRY32);
	DWORD result = 0;
	DWORD currentPID = GetCurrentProcessId();
	for (BOOL success = Thread32First(hThreadSnapshot.get(), &tEntry);
		!result && success && GetLastError() != ERROR_NO_MORE_FILES;
		success = Thread32Next(hThreadSnapshot.get(), &tEntry))
	{
		if (tEntry.th32OwnerProcessID == currentPID) 
		{
			result = tEntry.th32ThreadID;
		}
	}
	return result;
}
Exemplo n.º 6
0
bool App::startOSC()
{
    // starts OSC
    if (osc_recv_port_ == 0)
    {
        std::cout << "OSC receiving disabled." << std::endl;
        return false;
    }
    else
    {
        osc_receiver_.reset(new tempi::osc::OscReceiver(osc_recv_port_));
        std::cout << "Receive OSC from " << (*osc_receiver_.get()) << std::endl;
    }
    return true;
}
Exemplo n.º 7
0
 bool hasValue() const
 {
     std::tr1::try_mutex::scoped_try_lock lock(*mutex);
     return lock && result->get();
 }
		struct Sub {Object *_o; Sub(Object *o) :_o(o) {} bool operator ()(const std::tr1::shared_ptr<Object > &a) {return _o == a.get(); } };
		struct Sub {bool operator ()(const std::tr1::shared_ptr<Object > &a) {return dynamic_cast<Target *>(a.get()) != 0; } };
			struct Sub {bool operator ()(const std::tr1::shared_ptr<Object > &a)
				{Target *const one = dynamic_cast<Target *>(a.get()); return one != 0 && !one->Hit(); } };