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(); }
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()); } }
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; } } }
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(); }
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; }
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; }
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(); } };