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


C++ TCPClient::setEventHandler方法代码示例

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


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

示例1: main

int main(int argc, char **argv) {

#ifdef HAVE_TERMIOS_H
    // Store terminal attributes.
    SaveTerminalAttributes termAttrs;
#endif

    // Sets the environment's default locale.
    setlocale(LC_ALL, "");

    // Register signal handler.
    struct sigaction sa;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    sa.sa_handler = signal_handler;
    if (sigaction(SIGINT, &sa, nullptr)) {
        cout << "Could not register signal handler" << endl;
        exit(1);
    }

    // Parse configuration.
    Configuration configuration;
    GetoptConfigParser parser( argc, argv );
    if( !parser.parse( configuration ) ) {
        exit(1);
    }

    // Register read line implementation.
    ReadLine &rlConsumer = ReadLine::getInstance();

    // Connect to a debugger instance.
    TCPClient *client;
    int error = TCPClient::Connect( configuration.getHost(),
            configuration.getPort(), &client );
    if( error ) {
        cout << strerror( errno ) << endl;
        exit(1);
    }

    // Initialize JS engine.
    DebuggerCtxImpl dbgCtx(rlConsumer, *client);
    JSDebugger dbg(dbgCtx);
    error = dbg.init();
    if( error ) {
        dbg.destroy();
        cout << "Cannot initialize JS engine: " << error << endl;
        exit(1);
    }

    // Information for the client.
    cout << "JavaScript Remote Debugger Client connected to a remote "\
        "debugger.\nWaiting for a list of JavaScript contexts being " \
        "debugged.\nType \"help context\" for more information." << endl;

    ApplicationCtxImpl ctx;

    MainEventHandler mainEventHandler( ctx );

    client->setEventHandler( &mainEventHandler );

    // Prepare FS Events loop.
    std::vector<IFSEventProducer*> producers;
    producers.push_back( client );

    std::vector<IFSEventConsumer*> consumers;
    consumers.push_back(client);

    rlConsumer.registerReadline( &mainEventHandler );
    consumers.push_back( &rlConsumer );

    // The main debugger's loop.
    FSEventLoop eventsLoop(producers, consumers);

    // Initialize the main context.
    ctx.setMainLoop( &eventsLoop );
    ctx.setReadLineEditor( &rlConsumer );
    ctx.setDebuggerEngine( &dbg );

    error = eventsLoop.loop();
    if( error ) {
        cout << "Debugger interrupted with error: " << error << endl;
    }

    client->setEventHandler(nullptr);

    client->disconnect(JDB_ERROR_NO_ERROR);
    delete client;

    dbg.destroy();

    exit(0);
}
开发者ID:swojtasiak,项目名称:jsrdbg,代码行数:92,代码来源:jrdb.cpp


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