本文整理汇总了C++中Dispatcher类的典型用法代码示例。如果您正苦于以下问题:C++ Dispatcher类的具体用法?C++ Dispatcher怎么用?C++ Dispatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char* argv[])
{
// We get the number of cores to be used. If we don't give any number,
// we set to 0 which implies the usage of all available cores
size_t nbCores = (argc >=2 ? atoi(argv[1]) : 0);
// We create an iterator over an integer range
int nmax = 1000;
Range<int>::Iterator it (1,nmax);
// We open a file. This will be our shared resource between threads.
fstream file ("out", std::fstream::out);
// For our file, we can't use intrinsics like we did for integer addition,
// so we need a general synchronization mechanism that will be shared by the threads.
ISynchronizer* synchro = System::thread().newSynchronizer();
// We create a dispatcher configured for 'nbCores' cores.
Dispatcher dispatcher (nbCores, 1);
// We iterate the range. NOTE: we could also use lambda expression (easing the code readability)
dispatcher.iterate (it, Functor(synchro,file));
// We close the file
file.close();
// We get rid of the synchronizer
delete synchro;
}
示例2: assert
/*=====================================================================*/
void GData::set_partition(GPartitioner *P)
{
partitioner = P;
assert(P);
child_cnt = P->y * P->x;
children = new GData*[child_cnt];
assert(P->y);
assert(P->x);
int m = M/P->y;
int n = N/P->x;
for(int i=0; i<child_cnt; i++)
{
int px = i/P->y;
int py = i%P->y;
ostringstream os;
os << name
<< "_" << setw(2) << setfill('0') << py
<< "_" << setw(2) << setfill('0') << px;
string ch_name = os.str();
LOG_INFO(LOG_MLEVEL,"Child data :%s of %dx%d at blk(%d,%d) is being created.\n",ch_name.c_str(),m,n,py,px);
children[i] = new GData(m,n,ch_name,this,i);
}
Dispatcher *dis = get_dispatcher();
if ( dis != nullptr)
dis->data_partitioned(this);
GPartitioner *next_p=partitioner->get_next();
if ( next_p != nullptr)
for(int i=0; i<child_cnt; i++)
{
LOG_INFO(LOG_MLEVEL,"Cascade partition to %s with %dx%d\n",children[i]->get_name().c_str(),next_p->y,next_p->x);
children[i]->set_partition(next_p);
}
}
示例3: getInput
void SRC_counter::parse_query_sequences (){
std::string bank_filename = getInput()->getStr(STR_URI_BANK_INPUT).substr(getInput()->getStr(STR_URI_BANK_INPUT).find_last_of("/\\") + 1);
BankAlbum banks (getInput()->getStr(STR_URI_QUERY_INPUT));
const std::vector<IBank*>& banks_of_queries = banks.getBanks();
const int number_of_read_sets = banks_of_queries.size();
FILE * pFile;
pFile = fopen (getInput()->getStr(STR_OUT_FILE).c_str(), "wb");
cout<<"Query "<<kmer_size<<"-mers from "<<getInput()->getStr(STR_URI_QUERY_INPUT)<<endl;
for( int bank_id=0;bank_id<number_of_read_sets;bank_id++){ // iterate each bank
IBank* bank=banks_of_queries[bank_id];
LOCAL (bank);
// BooleanVector bv;
// unsigned long bank_size = get_bank_nb_items(bank);
// bv.init_false(bank_size); // quick and dirty. Todo: implement a realocation of the bv in case the estimation is too low.
// bv.set_comment(string("Reads from "+bank->getId()+" in "+getInput()->getStr(STR_URI_BANK_INPUT)+" with threshold "+to_string(threshold)));
string message("#query_read_id (from bank "+bank->getId()+") mean median min max percentage_shared_positions -- number of shared "+to_string(kmer_size)+"mers with banq "+getInput()->getStr(STR_URI_BANK_INPUT)+"\n");
fwrite((message).c_str(), sizeof(char), message.size(), pFile);
string progressMessage("Querying read set "+bank->getId());
ProgressIterator<Sequence> itSeq (*bank, progressMessage.c_str());
ISynchronizer* synchro = System::thread().newSynchronizer();
Dispatcher dispatcher (nbCores, 10000);
dispatcher.iterate (itSeq, FunctorQuery(synchro,pFile, kmer_size,&quasiDico, keep_low_complexity, threshold, windows_size));//, &bv));
delete synchro;
std::string query_filename = bank->getId().substr(bank->getId().find_last_of("/\\") + 1);
// cout<<bv.nb_one()<<" reads in out_"+query_filename+"_in_"+bank_filename+".bv"<<endl;
// bv.print("out_"+query_filename+"_in_"+bank_filename+".bv");
}
fclose (pFile);
}
示例4: LS_OK_ERROR
// millisecs
std::error_code
PollPoller::poll(int timeout,
std::unordered_map<int, Dispatcher *> &active_dispatchers) {
if (fds_.size() == 0) {
::Sleep(timeout);
return LS_OK_ERROR();
}
int num_events = ::WSAPoll(&*fds_.begin(), fds_.size(), timeout);
if (num_events < 0) {
if (SOCK_ERRNO() == CERR(EINTR)) {
return LS_OK_ERROR();
}
} else if (num_events == 0) {
return LS_OK_ERROR();
} else {
for (auto it = fds_.begin(); it != fds_.end() && num_events > 0; ++it) {
if (it->revents > 0) {
--num_events;
Dispatcher *dispatcher = dispatchers_[it->fd];
dispatcher->set_poll_event_data(
it->revents & (POLLIN | POLLPRI), it->revents & POLLOUT,
it->revents & POLLERR,
(it->revents & POLLHUP) && !(it->revents & POLLIN));
active_dispatchers[dispatcher->get_fd()] = dispatcher;
}
}
}
return LS_OK_ERROR();
}
示例5: main
int main(int argc, char *argv[]) {
SetProgramName(argv[0]);
MessageServer server("127.0.0.1", 21118);
Dispatcher dispatcher;
dispatcher.Start();
server.set_dispatcher(&dispatcher);
EchoServerMessageHandlerFactory factory;
server.set_message_handler_factory(&factory);
server.Start();
sigset_t new_mask;
sigfillset(&new_mask);
sigset_t old_mask;
sigset_t wait_mask;
sigemptyset(&wait_mask);
sigaddset(&wait_mask, SIGINT);
sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
int sig = 0;
sigwait(&wait_mask, &sig);
return 0;
}
示例6: TEST
TEST(ContextGroupTests, ConnectionWriteIsThrowingWhenCurrentContextIsInterrupted) {
Dispatcher dispatcher;
bool interrupted = false;
{
Event connected(dispatcher);
ContextGroup cg1(dispatcher);
cg1.spawn([&] {
try {
auto conn = TcpListener(dispatcher, Ipv4Address("0.0.0.0"), 12345).accept();
conn.write(nullptr, 0);
} catch (InterruptedException&) {
}
});
cg1.spawn([&] {
try {
auto conn = TcpConnector(dispatcher).connect(Ipv4Address("127.0.0.1"), 12345);
connected.set();
dispatcher.yield();
conn.write(nullptr, 0);
} catch (InterruptedException&) {
interrupted = true;
}
});
connected.wait();
}
ASSERT_TRUE(interrupted);
}
示例7: shouldBeAbleToGetErrorMessageWithRequest
void shouldBeAbleToGetErrorMessageWithRequest()
{
Dispatcher dispatcher;
dispatcher.registerClass("class1", new ErrorMessageHandler());
QCOMPARE(dispatcher.handleRequest("class1/click/button1"), QString("Unable to find top level object \"button1\""));
}
示例8: main
int main()
{
Dispatcher disp;
Stub<Broker> broker("broker", "unix:the_broker");
disp.addClient(broker);
if (broker.connect())
{
std::vector<ServiceInfo> services;
if (disp.waitForResponse(broker.listServices(), services))
{
std::cout << "Available services: " << std::endl;
std::for_each(services.begin(), services.end(), printServiceInfo);
std::cout << std::endl;
std::vector<std::string> waiters;
if (disp.waitForResponse(broker.listWaiters(), waiters))
{
std::cout << "Waiters waiting for: " << std::endl;
std::for_each(waiters.begin(), waiters.end(), printWaiterInfo);
std::cout << std::endl;
return EXIT_SUCCESS;
}
}
}
return EXIT_FAILURE;
}
示例9: Subscribe
void Subscribe(Receiver<Type>& receiver)
{
// Check if we already have this event type declared.
auto it = m_dispatchers.find(typeid(Type));
if(it == m_dispatchers.end())
{
// Create a dispatcher for this event type.
auto dispatcher = std::make_unique<Dispatcher<Type>>();
// Add dispatcher to the list.
auto pair = DispatcherPair(typeid(Type), std::move(dispatcher));
auto result = m_dispatchers.insert(std::move(pair));
assert(result.second == true);
assert(result.first != m_dispatchers.end());
// Set iterator to the newly inserted element.
it = result.first;
}
// Cast the pointer that we already know is a dispatcher.
Dispatcher<Type>* dispatcher = reinterpret_cast<Dispatcher<Type>*>(it->second.get());
// Subscribe receiver to the dispatcher.
dispatcher->Subscribe(receiver);
}
示例10: main
int main (int argc, char* argv[])
{
// We get the number of cores to be used. If we don't give any number,
// we set to 0 which implies the usage of all available cores
size_t nbCores = (argc >=2 ? atoi(argv[1]) : 0);
// We create an iterator over an integer range
Range<int>::Iterator it (1,20);
// We create a dispatcher configured for 'nbCores' cores.
Dispatcher dispatcher (nbCores);
// We dispatch the range iteration with the dispatcher.
// This will create nbCores threads and each thread will be fed with
// one value of the defined range
// NOTE: we could also use lambda expression (easing the code readability)
// Note: third argument is set to groupSize of 1 instead of 1000 (default),
// to avoid that 1000 tasks are batched in the same thread.
// In practice, when iterating over a large set of elements, set a reasonable
// groupSize value, because a groupSize=1 will incur significant overhead
// if Functor() is a very quick task.
IDispatcher::Status status = dispatcher.iterate (it, Functor(), 1);
// We dump some information about the dispatching
cout << "nbCores=" << status.nbCores << " time=" << status.time << endl;
// IMPORTANT: usage of Dispatcher has sense only if the iterated items
// can be processed independently from each other.
// The point to understand with the Dispatcher is that it can
// iterate any instance of Iterator class. If you have any set of items
// that can be enumerated through an Iterator implementation, then you
// can parallelize the iteration with a Dispatcher instance
}
示例11: shouldBeAbleToUnregisterAClass
void shouldBeAbleToUnregisterAClass()
{
Dispatcher dispatcher;
dispatcher.registerClass("class1", new ReturnNameHandler("class1"));
dispatcher.unRegisterClass("class1");
QCOMPARE(dispatcher.handleRequest("class1/click/button1"), QString(""));
}
示例12:
S2::S2(Context* con): State::State(con){
cout << "S2()" << endl;
// Start listen on Event Transition1 and Event Transmission2
Dispatcher* dsp = Dispatcher::getInstance();
dsp->addListener( this->con_, TRANSITION1);
dsp->addListener( this->con_, TRANSITION2);
}
示例13:
void Dispatcher::Private::on_rem_timeout(DBusTimeout *timeout, void *data)
{
Dispatcher *d = static_cast<Dispatcher *>(data);
Timeout *t = static_cast<Timeout *>(dbus_timeout_get_data(timeout));
d->rem_timeout(t);
}
示例14: getDispatcher
int SvCon::onDisconnected(){
Dispatcher* d = getDispatcher();
d->delConnectServer(m_con_serv_id);
ALogError(m_serv->getConfig().LogName) << "<action:server_disconnect> "
"<event_loop:" << getEventLoop() << "> <conid:"
<< getId() << "> <con_serv_id:" << m_con_serv_id
<< ">";
return 0;
}
示例15: dispatcher_resolve
void*
dispatcher_resolve(dispatcher_t *obj, int sig[], int *count, int allow_unsafe,
int exact_match_required) {
Dispatcher *disp = static_cast<Dispatcher*>(obj);
Type *args = reinterpret_cast<Type*>(sig);
void *callable = disp->resolve(args, *count, (bool) allow_unsafe,
(bool) exact_match_required);
return callable;
}