本文整理汇总了C++中Consumer类的典型用法代码示例。如果您正苦于以下问题:C++ Consumer类的具体用法?C++ Consumer怎么用?C++ Consumer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Consumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QMainWindow
progressDialog::progressDialog(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags){
ui.setupUi(this);
Consumer *c = new Consumer();
Producer *p = new Producer();
Thread *t1 = new Thread(0);
Thread *t2 = new Thread(0);
connect(this,SIGNAL(begin(bool)),c,SLOT(startReceiving(bool)));
connect(c,SIGNAL(initiate(bool)),p,SLOT(produce(bool)));
connect(p,SIGNAL(sendPacket(const QByteArray,bool)),c,SLOT(receiveFrame(const QByteArray,bool)));
connect(ui.pushButton,SIGNAL(clicked(bool)),this,SLOT(_begin(bool)));
connect(p,SIGNAL(halt(bool)),c,SLOT(startReceiving(bool)));
connect(c,SIGNAL(blockDone()),p,SLOT(frameData()));
connect(c,SIGNAL(measure(bool)),p,SLOT(measurement(bool)),Qt::DirectConnection);
connect(c,SIGNAL(openDialog()),this,SLOT(startDlg()));
connect(c,SIGNAL(closeDialog()),this,SLOT(closeDlg()));
connect(p,SIGNAL(setDlgMax(int)),this,SLOT(setMaxVal(int)));
connect(p,SIGNAL(setDlgVal(int)),this,SLOT(setVal(int)));
connect(p,SIGNAL(setSeconds(int)),this,SLOT(setSecondsRemaining(int)));
c->moveToThread(t1);
p->moveToThread(t2);
t1->start();
t2->start();
}
示例2: start_consumer
static void*
start_consumer(void* data)
{
Consumer* consumer = (Consumer*)data;
int* x;
int has_item = 0;
while ((has_item = consumer->f_get_item(consumer->queue, &x)) != -1)
{
if (has_item == 1)
{
int i = *x;
cx_free(x);
consumer->processed++;
XFLOG("Consumer[%d] - received %d", consumer->id, i);
/* simulate processing delay */
#ifdef PROCESSING_DELAY_MAX_MSEC
usleep((rand() % PROCESSING_DELAY_MAX_MSEC) * 1000);
#endif
// queue is destroyed on the last request
if (i == (NITERATATIONS - 1))
{
XFDBG("Consumer[%d] I'm processing the last request", consumer->id);
Queue_destroy(consumer->queue);
}
}
}
XFDBG("Consumer[%d] Leaving inactive queue", consumer->id);
pthread_exit(NULL);
}
示例3: main
int
main (int argc, char** argv)
{
print_highlight ("PCL OpenNI Recorder for saving buffered PCD (binary compressed to disk). See %s -h for options.\n", argv[0]);
int buff_size = BUFFER_SIZE;
if (find_switch (argc, argv, "-h") || find_switch (argc, argv, "--help"))
{
print_info ("Options are: \n"
" -xyz = save only XYZ data, even if the device is RGB capable\n"
" -shift = use OpenNI shift values rather than 12-bit depth\n"
" -buf X = use a buffer size of X frames (default: ");
print_value ("%d", buff_size); print_info (")\n");
return (0);
}
bool just_xyz = find_switch (argc, argv, "-xyz");
openni_wrapper::OpenNIDevice::DepthMode depth_mode = openni_wrapper::OpenNIDevice::OpenNI_12_bit_depth;
if (find_switch (argc, argv, "-shift"))
depth_mode = openni_wrapper::OpenNIDevice::OpenNI_shift_values;
if (parse_argument (argc, argv, "-buf", buff_size) != -1)
print_highlight ("Setting buffer size to %d frames.\n", buff_size);
else
print_highlight ("Using default buffer size of %d frames.\n", buff_size);
print_highlight ("Starting the producer and consumer threads... Press Cltr+C to end\n");
OpenNIGrabber grabber ("");
if (grabber.providesCallback<OpenNIGrabber::sig_cb_openni_point_cloud_rgba> () &&
!just_xyz)
{
print_highlight ("PointXYZRGBA enabled.\n");
PCDBuffer<PointXYZRGBA> buf;
buf.setCapacity (buff_size);
Producer<PointXYZRGBA> producer (buf, depth_mode);
boost::this_thread::sleep (boost::posix_time::seconds (2));
Consumer<PointXYZRGBA> consumer (buf);
signal (SIGINT, ctrlC);
producer.stop ();
consumer.stop ();
}
else
{
print_highlight ("PointXYZ enabled.\n");
PCDBuffer<PointXYZ> buf;
buf.setCapacity (buff_size);
Producer<PointXYZ> producer (buf, depth_mode);
boost::this_thread::sleep (boost::posix_time::seconds (2));
Consumer<PointXYZ> consumer (buf);
signal (SIGINT, ctrlC);
producer.stop ();
consumer.stop ();
}
return (0);
}
示例4: lock
int galera::ist::Receiver::recv(TrxHandle** trx)
{
Consumer cons;
gu::Lock lock(mutex_);
if (running_ == false)
{
if (error_code_ != 0)
{
gu_throw_error(error_code_) << "IST receiver reported error";
}
return EINTR;
}
consumers_.push(&cons);
cond_.signal();
lock.wait(cons.cond());
if (cons.trx() == 0)
{
if (error_code_ != 0)
{
gu_throw_error(error_code_) << "IST receiver reported error";
}
return EINTR;
}
*trx = cons.trx();
return 0;
}
示例5: producer
/// producer function produces user defined messages.
ACE_THR_FUNC_RETURN producer (void *arg)
{
Consumer* c = static_cast<Consumer*> (arg);
ACE_ASSERT(c!=0);
if (c==0)
{
ACE_ERROR((LM_ERROR,
ACE_TEXT("producer Error casting to consumer\n")));
return (ACE_THR_FUNC_RETURN)-1;
}
for (int i=0;i!=NUMBER_OF_MSGS;++i)
{
User_Defined_Msg* pMsg=0;
ACE_NEW_NORETURN(pMsg, User_Defined_Msg(i));
if (pMsg==0)
{
ACE_ERROR((LM_ERROR,
ACE_TEXT("producer Error allocating data %p\n"),
"err="));
return (ACE_THR_FUNC_RETURN)-1;
}
if(c->putq (pMsg)==-1)
{
ACE_ERROR((LM_ERROR,
ACE_TEXT("producer Error putq data %p\n"),
"err="));
return (ACE_THR_FUNC_RETURN)-1;
}
}
return 0;
}
示例6: ACE_TMAIN
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
Consumer consumer;
return consumer.run (argc, argv);
}
示例7: send
static void send(std::string message)
{
// on first call to this method, the consumer is launched
static Consumer client;
// send the message to the consumer
client.send(message);
}
示例8:
void *start_Consuming(void* param) {
Consumer* con = (Consumer*) param;
con->Consuming();
pthread_exit((void *) NULL);
}
示例9: producerConsumer
void tst_QSemaphore::producerConsumer()
{
Producer producer;
Consumer consumer;
producer.start();
consumer.start();
producer.wait();
consumer.wait();
}
示例10: main
int main(int argc, char * argv[])
{
Consumer* consumer = new Consumer;
Producer* producer = new Producer(consumer);
producer->open(0);
consumer->open(0);
//Wait for all the tasks to exit.
ACE_Thread_Manager::instance()->wait();
return 0;
}
示例11: main
//! [5]
int main(int argc, char *argv[])
//! [5] //! [6]
{
QCoreApplication app(argc, argv);
Producer producer;
Consumer consumer;
producer.start();
consumer.start();
producer.wait();
consumer.wait();
return 0;
}
示例12: main
int main()
{
usedSpace += BufferSize;
Producer producer;
Consumer consumer;
producer.start();
consumer.start();
producer.wait();
consumer.wait();
return 0;
}
示例13: processPayload
void
processPayload(Consumer& c, const uint8_t* buffer, size_t bufferSize)
{
std::string content1((char*)buffer, bufferSize);
Name prefix;
c.getContextOption(PREFIX, prefix);
Name suffix;
c.getContextOption(SUFFIX, suffix);
std::cout << "CONTENT for " << prefix << suffix << std::endl;
}
示例14: GetOperator
inline void Type_::GiveElements(
TheFrontPushOperation & theFrontPushOperation,
Consumer & theConsumer
) {
theConsumer.TakeElement(
GetOperator()
);
if (
!theFrontPushOperation.thisProgram.IsEmpty()
) {
theConsumer.TakeQuotedElements(theFrontPushOperation.thisProgram);
}
}
示例15: GetOperator
inline void Type_::GiveElements(
ThePairOperation & thePairOperation,
Consumer & theConsumer
) {
theConsumer.TakeElement(
GetOperator()
);
if (
!thePairOperation.thisExpression.IsEmpty()
) {
theConsumer.TakeQuotedElements(thePairOperation.thisExpression);
}
}