本文整理汇总了C++中CEventServer::sendEvent方法的典型用法代码示例。如果您正苦于以下问题:C++ CEventServer::sendEvent方法的具体用法?C++ CEventServer::sendEvent怎么用?C++ CEventServer::sendEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CEventServer
的用法示例。
在下文中一共展示了CEventServer::sendEvent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RecordThread
//.........这里部分代码省略.........
{
lt_info("%s: read failed: %m\n", __func__);
exit_flag = RECORD_FAILED_READ;
state = REC_STATUS_OVERFLOW;
break;
}
}
else
{
overflow = false;
buf_pos += s;
}
}
else
{
if (!overflow)
overflow_count = 0;
overflow = true;
if (!(overflow_count % 10))
lt_info("%s: buffer full! Overflow? (%d)\n", __func__, ++overflow_count);
state = REC_STATUS_SLOW;
}
r = aio_error(&a);
if (r == EINPROGRESS)
{
lt_debug("%s: aio in progress, free: %d\n", __func__, bufsize - buf_pos);
continue;
}
// not calling aio_return causes a memory leak --martii
r = aio_return(&a);
if (r < 0)
{
exit_flag = RECORD_FAILED_FILE;
lt_debug("%s: aio_return = %d (%m)\n", __func__, r);
break;
}
else
lt_debug("%s: aio_return = %d, free: %d\n", __func__, r, bufsize - buf_pos);
if (posix_fadvise(file_fd, 0, 0, POSIX_FADV_DONTNEED))
perror("posix_fadvise");
if (queued)
{
memmove(buf, buf + queued, buf_pos - queued);
buf_pos -= queued;
}
queued = buf_pos;
a.aio_buf = buf;
a.aio_nbytes = queued;
r = aio_write(&a);
if (r)
{
lt_info("%s: aio_write %d (%m)\n", __func__, r);
exit_flag = RECORD_FAILED_FILE;
break;
}
}
dmx->Stop();
while (true) /* write out the unwritten buffer content */
{
lt_debug("%s: run-out write, buf_pos %d\n", __func__, buf_pos);
r = aio_error(&a);
if (r == EINPROGRESS)
{
usleep(50000);
continue;
}
r = aio_return(&a);
if (r < 0)
{
exit_flag = RECORD_FAILED_FILE;
lt_info("%s: aio_result: %d (%m)\n", __func__, r);
break;
}
if (!queued)
break;
memmove(buf, buf + queued, buf_pos - queued);
buf_pos -= queued;
queued = buf_pos;
a.aio_buf = buf;
a.aio_nbytes = queued;
r = aio_write(&a);
}
#if 0
// TODO: do we need to notify neutrino about failing recording?
CEventServer eventServer;
eventServer.registerEvent2(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, "/tmp/neutrino.sock");
stream2file_status2_t s;
s.status = exit_flag;
strncpy(s.filename,basename(myfilename),512);
s.filename[511] = '\0';
strncpy(s.dir,dirname(myfilename),100);
s.dir[99] = '\0';
eventServer.sendEvent(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, &s, sizeof(s));
printf("[stream2file]: pthreads exit code: %i, dir: '%s', filename: '%s' myfilename: '%s'\n", exit_flag, s.dir, s.filename, myfilename);
#endif
lt_info("%s: end\n", __func__);
pthread_exit(NULL);
}
示例2: RecordThread
void cRecord::RecordThread()
{
lt_info("%s: begin\n", __func__);
#define BUFSIZE (1 << 19) /* 512 kB */
ssize_t r = 0;
int buf_pos = 0;
uint8_t *buf;
buf = (uint8_t *)malloc(BUFSIZE);
if (!buf)
{
exit_flag = RECORD_FAILED_MEMORY;
lt_info("%s: unable to allocate buffer! (out of memory)\n", __func__);
}
dmx->Start();
while (exit_flag == RECORD_RUNNING)
{
if (buf_pos < BUFSIZE)
{
r = dmx->Read(buf + buf_pos, BUFSIZE - 1 - buf_pos, 100);
lt_debug("%s: buf_pos %6d r %6d / %6d\n", __func__,
buf_pos, (int)r, BUFSIZE - 1 - buf_pos);
if (r < 0)
{
if (errno != EAGAIN)
{
lt_info("%s: read failed: %m\n", __func__);
exit_flag = RECORD_FAILED_READ;
break;
}
lt_info("%s: EAGAIN\n", __func__);
}
else
buf_pos += r;
}
else
lt_info("%s: buffer full! Overflow?\n", __func__);
if (buf_pos > (BUFSIZE / 3)) /* start writeout */
{
size_t towrite = BUFSIZE / 2;
if (buf_pos < BUFSIZE / 2)
towrite = buf_pos;
r = write(file_fd, buf, towrite);
if (r < 0)
{
exit_flag = RECORD_FAILED_FILE;
lt_info("%s: write error: %m\n", __func__);
break;
}
buf_pos -= r;
memmove(buf, buf + r, buf_pos);
lt_debug("%s: buf_pos %6d w %6d / %6d\n", __func__, buf_pos, (int)r, (int)towrite);
#if 0
if (fdatasync(file_fd))
perror("cRecord::FileThread() fdatasync");
#endif
if (posix_fadvise(file_fd, 0, 0, POSIX_FADV_DONTNEED))
perror("posix_fadvise");
}
}
dmx->Stop();
while (buf_pos > 0) /* write out the unwritten buffer content */
{
r = write(file_fd, buf, buf_pos);
if (r < 0)
{
exit_flag = RECORD_FAILED_FILE;
lt_info("%s: write error: %m\n", __func__);
break;
}
buf_pos -= r;
memmove(buf, buf + r, buf_pos);
}
free(buf);
#if 0
// TODO: do we need to notify neutrino about failing recording?
CEventServer eventServer;
eventServer.registerEvent2(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, "/tmp/neutrino.sock");
stream2file_status2_t s;
s.status = exit_flag;
strncpy(s.filename,basename(myfilename),512);
s.filename[511] = '\0';
strncpy(s.dir,dirname(myfilename),100);
s.dir[99] = '\0';
eventServer.sendEvent(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, &s, sizeof(s));
printf("[stream2file]: pthreads exit code: %i, dir: '%s', filename: '%s' myfilename: '%s'\n", exit_flag, s.dir, s.filename, myfilename);
#endif
lt_info("%s: end", __func__);
pthread_exit(NULL);
}
示例3: if
//.........这里部分代码省略.........
}
}
else
offset = 0;
written = ringbuffer_write(ringbuf, (char *)&(buf[offset]), r - offset);
// TODO: Retry
if (written != r - offset) {
printf("PANIC: wrote less than requested to ringbuffer, written %d, requested %d\n", written, r - offset);
exit_flag = STREAM2FILE_STATUS_BUFFER_OVERFLOW;
}
todo = IN_SIZE - (r - offset);
/* IN_SIZE > TS_SIZE => todo > 0 */
while (exit_flag == STREAM2FILE_STATUS_RUNNING)
{
ringbuffer_get_write_vector(ringbuf, &(vec[0]));
todo2 = todo - vec[0].len;
if (todo2 < 0)
{
todo2 = 0;
}
else
{
if (((size_t)todo2) > vec[1].len)
{
printf("PANIC: not enough space in ringbuffer, available %d, needed %d\n", vec[0].len + vec[1].len, todo + todo2);
exit_flag = STREAM2FILE_STATUS_BUFFER_OVERFLOW;
}
todo = vec[0].len;
}
while (exit_flag == STREAM2FILE_STATUS_RUNNING)
{
if ((pres=poll (&pfd, 1, 15000))>0)
{
if (!(pfd.revents&POLLIN))
{
printf ("PANIC: error reading from demux, bailing out\n");
exit_flag = STREAM2FILE_STATUS_READ_FAILURE;
}
r = read(*(int *)v_arg, vec[0].buf, todo);
if (r > 0)
{
ringbuffer_write_advance(ringbuf, r);
if (todo == r)
{
if (todo2 == 0)
goto next;
todo = todo2;
todo2 = 0;
vec[0].buf = vec[1].buf;
}
else
{
vec[0].buf += r;
todo -= r;
}
}
}
else if (!pres){
printf ("[stream2file]: timeout reading from demux\n");
goto next;
}
}
next:
todo = IN_SIZE;
}
if (v_arg == &dvrfd)
close(*(int *)v_arg);
else
unsetPesFilter(*(int *)v_arg);
pthread_join(file_thread, NULL);
ringbuffer_free(ringbuf);
if (v_arg == &dvrfd)
while (demuxfd_count > 0)
unsetPesFilter(demuxfd[--demuxfd_count]);
DEC_BUSY_COUNT;
if ((v_arg == &dvrfd) || (v_arg == (&(demuxfd[0]))))
{
CEventServer eventServer;
eventServer.registerEvent2(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, "/tmp/neutrino.sock");
stream2file_status2_t s;
s.status = exit_flag;
strncpy(s.dir,dirname(myfilename),100);
eventServer.sendEvent(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, &s, sizeof(s));
printf("[stream2file] pthreads exit code: %u\n", exit_flag);
}
pthread_exit(NULL);
}
示例4: DMXThread
//.........这里部分代码省略.........
}
}
if (exit_flag == STREAM2FILE_STATUS_RUNNING)
{
written = ringbuffer_write(ringbuf, (char *)&(buf[offset]), r - offset);
// TODO: Retry
if (written != r - offset) {
fprintf(stderr, "PANIC: wrote less than requested to ringbuffer, written %d, requested %d\n", written, r - offset);
exit_flag = STREAM2FILE_STATUS_BUFFER_OVERFLOW;
}
todo = IN_SIZE - (r - offset);
}
/* IN_SIZE > TS_SIZE => todo > 0 */
while (exit_flag == STREAM2FILE_STATUS_RUNNING)
{
ringbuffer_get_write_vector(ringbuf, &(vec[0]));
todo2 = todo - vec[0].len;
if (todo2 < 0)
{
todo2 = 0;
}
else
{
if (((size_t)todo2) > vec[1].len)
{
fprintf(stderr, "PANIC: not enough space in ringbuffer, available %d, needed %d\n", vec[0].len + vec[1].len, todo + todo2);
exit_flag = STREAM2FILE_STATUS_BUFFER_OVERFLOW;
}
todo = vec[0].len;
}
while (exit_flag == STREAM2FILE_STATUS_RUNNING)
{
if ((pres=poll (&pfd, 1, 5000))>0)
{
if (!(pfd.revents&POLLIN))
{
fprintf(stderr, "PANIC: error reading from demux, bailing out\n");
exit_flag = STREAM2FILE_STATUS_READ_FAILURE;
}
r = read(dvrfd, vec[0].buf, todo);
if (r > 0)
{
ringbuffer_write_advance(ringbuf, r);
if (todo == r)
{
if (todo2 == 0)
goto next;
todo = todo2;
todo2 = 0;
vec[0].buf = vec[1].buf;
}
else
{
vec[0].buf += r;
todo -= r;
}
}
}
else if (!pres){
fprintf(stderr, "[stream2file]: timeout reading from demux\n");
exit_flag = STREAM2FILE_STATUS_READ_FAILURE;
}
}
next:
todo = IN_SIZE;
}
close(dvrfd);
pthread_join(file_thread, NULL);
if (ringbuf)
ringbuffer_free(ringbuf);
while (demuxfd_count > 0)
unsetPesFilter(demuxfd[--demuxfd_count]);
#ifdef needed
//fixme: do we need it?
CEventServer eventServer;
eventServer.registerEvent2(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, "/tmp/neutrino.sock");
stream2file_status2_t s;
s.status = exit_flag;
strncpy(s.filename,basename(myfilename),512);
s.filename[511] = '\0';
strncpy(s.dir,dirname(myfilename),100);
s.dir[99] = '\0';
eventServer.sendEvent(NeutrinoMessages::EVT_RECORDING_ENDED, CEventServer::INITID_NEUTRINO, &s, sizeof(s));
fprintf(stderr, "[stream2file]: pthreads exit code: %i, dir: '%s', filename: '%s' myfilename: '%s'\n", exit_flag, s.dir, s.filename, myfilename);
#endif
fprintf(stderr, "%s:%s <\n", __FILE__, __FUNCTION__);
pthread_exit(NULL);
}