当前位置: 首页>>代码示例>>C++>>正文


C++ Daemon::sendCommand方法代码示例

本文整理汇总了C++中Daemon::sendCommand方法的典型用法代码示例。如果您正苦于以下问题:C++ Daemon::sendCommand方法的具体用法?C++ Daemon::sendCommand怎么用?C++ Daemon::sendCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Daemon的用法示例。


在下文中一共展示了Daemon::sendCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv) {
    openni::Device &device = __device;
    openni::VideoStream &depth = __depth, &color = __color;
    openni::Status rc;

    char *prefix = strrchr(argv[0], '/')+1;
    char *cfgfile = new char[prefix-argv[0]+strlen(rgbdsend::config_file_name)+1];

    strncpy(cfgfile, argv[0], prefix-argv[0]+1);
    strcpy(cfgfile+(prefix-argv[0]), rgbdsend::config_file_name);

    Config conf;
    if(conf.read(cfgfile) != 1) {
        printf("Config: Falling back to builtin presets.\n");
        conf.setDefaults();
    }

    delete[] cfgfile;

    CURL *curl = init_curl();

    Daemon daemon;
    daemon.init(conf.daemon_port, conf.daemon_timeout);

    atexit(atexit_handler);

    init_openni(&device, &depth, &color, conf);

    int dw, dh, cw, ch;
    int tmp1, tmp2;

    if(!depth.getCropping(&tmp1, &tmp2, &dw, &dh)) {
        dw = depth.getVideoMode().getResolutionX();
        dh = depth.getVideoMode().getResolutionY();
    }

    if(!color.getCropping(&tmp1, &tmp2, &cw, &ch)) {
        cw = color.getVideoMode().getResolutionX();
        ch = color.getVideoMode().getResolutionY();
    }

    printf("Resolution:\nDepth: %dx%d @ %d fps\nColor: %dx%d @ %d fps\n",
           dw, dh, depth.getVideoMode().getFps(),
           cw, ch, color.getVideoMode().getFps());

    std::queue<char *> onilist;

    Command cmd;
    while(1) {
        timeval t;
        t.tv_sec = conf.daemon_timeout;
        t.tv_usec = 0;

        fd_set fds;
        FD_ZERO(&fds);
        FD_SET(daemon.sock, &fds);
        FD_SET(daemon.csock, &fds);

        int in = select((daemon.csock > daemon.sock ? daemon.csock : daemon.sock)+1, &fds, 0, 0, &t);

        if(FD_ISSET(daemon.sock, &fds))
            daemon.acceptConnection();

        if(FD_ISSET(daemon.csock, &fds)) {
            char b[5];
            int r = daemon.receiveCommand(&cmd);

            if(r == 0) {
                printf("Daemon Error: Could not receive command.\n");

                daemon.closeConnection();
                continue;
            }

            if(r == 2) // keep alive
                continue;

            if(strncmp(cmd.header, "capt", 4) == 0) {
                printf("Received capture command.\n");

                char *newfile = new char[rgbdsend::filename_bufsize];
                if(record_oni(newfile, rgbdsend::filename_bufsize, depth, color, conf) == true) {
                    onilist.push(newfile);
                } else {
                    delete[] newfile;
                }
                daemon.sendCommand("okay", 0, 0);
            } else if(strncmp(cmd.header, "thmb", 4) == 0) {
                printf("Received thumbnail command.\n");
                unsigned char *thumbbuf = NULL;
                long unsigned int size = 0;
                capture_thumbnail(&thumbbuf, &size, color);
                printf("Captured thumbnail. %ld bytes\n", size);

                daemon.sendCommand("stmb", thumbbuf, size);

//				delete[] thumbbuf; seems like libjpeg handles this. but I'm not sure.
            } else if(strncmp(cmd.header, "quit", 4) == 0) {
                daemon.closeConnection();
            } else {
//.........这里部分代码省略.........
开发者ID:holtfox,项目名称:rgbdsend,代码行数:101,代码来源:rgbdsend.cpp


注:本文中的Daemon::sendCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。