void CFilePreviewDlg::OnRun() { HANDLE hFile = CreateFile( m_sSourceName, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if ( hFile != INVALID_HANDLE_VALUE ) { if ( ! RunPlugin( hFile ) && ! m_bCancel ) RunManual( hFile ); CloseHandle( hFile ); } m_bThread = FALSE; PostMessage( WM_TIMER, 3 ); }
void Framework::operator()() { /* Plugins: Start in their own thread. */ for ( auto& plugin : this->plugins) { this->threads.push_back(std::thread([&]() {RunPlugin(std::move(plugin));})); } /* ZMQ: Wait for ready messages. */ for( auto& subscriber : subscriptions) { while(this->base_window->poll()) { zmq::message_t zmq_message; if (subscriber->recv(&zmq_message, ZMQ_NOBLOCK)) { if (zeug::string_hash("Ready") == zeug::string_hash(zmq_message.data())) { break; } } } } /* ZMQ: Send start message. */ { zeug::string_hash message("Start"); zmq::message_t zmq_message; memcpy(zmq_message.data(), message.Get(), message.Size()); this->zmq_framework_publisher->send(zmq_message); } /* Framework: Loop. */ auto stop = false; while(!stop) { if(!this->base_window->poll()) { stop = true; } for( auto& subscriber : subscriptions) { zmq::message_t zmq_message; if (subscriber->recv(&zmq_message, ZMQ_NOBLOCK)) { if (zeug::string_hash("Stop") == zeug::string_hash(zmq_message.data())) { stop = true; break; } } } } /* ZMQ: Send stop message. */ { zeug::string_hash message("Stop"); zmq::message_t zmq_message; memcpy(zmq_message.data(), message.Get(), message.Size()); this->zmq_framework_publisher->send(zmq_message); } /* Plugins: Wait for threads to finish. */ for ( auto& thread : this->threads) { thread.join(); } /* Plugins: Rethrow propagated exceptions */ for(const std::exception_ptr& exception : propagated_exceptions) { if(exception) { std::rethrow_exception(exception); } } }