• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Focus on ACE

            訂閱 ace-china
            電子郵件:
            瀏覽存于 groups.google.com 上的所有帖子

            C++博客 首頁 新隨筆 聯(lián)系 聚合 管理
              64 Posts :: 3 Stories :: 22 Comments :: 0 Trackbacks

            將ACE事件循環(huán)與MFC UI集成的一種實現(xiàn)



            將ACE事件循環(huán)與MFC UI集成的一種實現(xiàn)

            有很多種方式可以使界面與ACE事件循環(huán)集成在一起。本文件試圖提供一種“更好”的集成。
            這里的“更好”是指:
            1. 使用簡單
            2. 面向對象,不破壞已有系統(tǒng)的結構
            3. 盡量解除ACE與界面之間的耦合

            本文也僅用作拋磚引玉的“磚”,如果你有更好的方式,歡迎告訴我。


            從全局變量theApp開始
            MFC應有一個全局變量theApp,我們的集成也從這里開始。

            //@file: ACEBaseApp.h

            ?

            ?1 // @file:?ACEBaseApp.h
            ?2 // ???????把ACE集成到MFC帶界面程序的框架
            ?3 // @author:?jiangtao
            ?4 // @resvion?history;
            ?5 // @?version?0.1?2006-3-21?創(chuàng)建
            ?6 #ifndef?ACEBASE_APP_H
            ?7 #define ?ACEBASE_APP_H
            ?8 #pragma?once
            ?9 #include? " ace/ace.h "
            10 #include? " ace/Reactor.h "
            11 #include? " ace/Log_Msg.h "
            12 #ifndef?_DEBUG
            13 #pragma?comment(lib, " ace.lib " )
            14 #else
            15 #pragma?comment(lib, " aced.lib " )
            16 #endif
            17 class ?ACEBaseApp_T
            18 {
            19 ?? enum
            20 ?? {
            21 ????DEFAULT_ENENT_THREAD_NUM? = ? 4 ,
            22 ??}
            ;
            23 public :
            24 ??ACEBaseApp_T( void );
            25 ?? virtual ? ~ ACEBaseApp_T( void );
            26 public :
            27 ?? // 初始/結束ace框架
            28 ?? virtual ? int ?init();
            29 ?? virtual ? int ?fini();
            30 public :
            31 ?? // 啟動/結束事件循環(huán)
            32 ?? virtual ? int ?startEventLoop();
            33 ?? virtual ? int ?endEventLoop();
            34
            35 ?? // 與界面通訊的接口
            36 ?? virtual ?CWnd * ?hostWnd();
            37 ?? virtual ? void ?hostWnd(CWnd * ?wnd);
            38
            39 ?? // 找回反應器
            40 ??ACE_Reactor * ?reactor( void );
            41 ?? // 重新設置反應器
            42 ?? void ?reactor(ACE_Reactor * ?r);
            43
            44 ?? // 執(zhí)行事件循環(huán)的線程池
            45 ?? static ?ACE_THR_FUNC_RETURN??eventLoop( void * );
            46 private :
            47 ??ACE_Reactor * ??reactor_;
            48 ?? int ?eventThreadNum_;
            49 ?? int ?dynamicCreate_;?
            50 ??CWnd * ??hostWnd_;
            51 }
            ;
            52 #endif


            //@file: ACEBaseApp.cpp

            ?

            ??1 // @file:?ACEBaseApp.h
            ??2 // ???????把ACE集成到MFC帶界面程序的框架
            ??3 // @author:?jiangtao
            ??4 // @resvion?history;
            ??5 // @?version?0.1?2006-3-21?創(chuàng)建
            ??6
            ??7 #include? " StdAfx.h "
            ??8 #include? " ace/thread_manager.h "
            ??9 #include? " .\acebaseapp.h "
            ?10 #include? " ace/Tp_Reactor.h "
            ?11 ACE_THR_FUNC_RETURN?ACEBaseApp_T::?eventLoop?( void ? * arg)?
            ?12 {
            ?13 ??ACE_Reactor? * reactor? = ?static_cast < ACE_Reactor? *> ?(arg);
            ?14
            ?15 ??reactor -> owner?(ACE_OS::thr_self?());
            ?16 ??reactor -> run_reactor_event_loop?();
            ?17 ?? return ? 0 ;
            ?18 }

            ?19
            ?20 ACEBaseApp_T::ACEBaseApp_T( void )
            ?21 :reactor_( 0 ),eventThreadNum_(DEFAULT_ENENT_THREAD_NUM),dynamicCreate_( 0 )
            ?22 {
            ?23 ???
            ?24 }

            ?25
            ?26 ACEBaseApp_T:: ~ ACEBaseApp_T( void )
            ?27 {
            ?28 ?? if (dynamicCreate_)
            ?29 ?? {
            ?30 ????TRACE( " 釋放動態(tài)創(chuàng)建的TP?Reactor\n " );
            ?31
            ?32 ????delete?reactor_;
            ?33 ????reactor_? = ? 0 ;
            ?34 ??}

            ?35 }

            ?36
            ?37 int ?ACEBaseApp_T::init()
            ?38 {
            ?39 ?? return ??ace::init();
            ?40 }

            ?41 int ?ACEBaseApp_T::fini()
            ?42 {
            ?43 ?? return ?ace::fini();
            ?44 }

            ?45
            ?46 void ?ACEBaseApp_T::reactor(ACE_Reactor * ?r)
            ?47 {?
            ?48 ?? if (dynamicCreate_)
            ?49 ?? {
            ?50 ????delete?reactor_;
            ?51 ????dynamicCreate_? = ? 0 ;
            ?52 ??}

            ?53 ??reactor_? = ?r;
            ?54 }

            ?55
            ?56 ACE_Reactor * ?ACEBaseApp_T::reactor( void )
            ?57 {
            ?58 ?? if (reactor_? == ? 0 )
            ?59 ?? {
            ?60 ????TRACE( " 動態(tài)創(chuàng)建TP?Reactor\n " );
            ?61 ????ACE_TP_Reactor? * ?tp_reactor? = ? new ?ACE_TP_Reactor;
            ?62 ????ACE_Reactor? * ?my_reactor? = ? new ?ACE_Reactor(tp_reactor,? 1 );
            ?63 ????reactor(my_reactor);
            ?64 ????dynamicCreate_? = ? 1 ;
            ?65 ??}

            ?66
            ?67 ?? return ?reactor_;
            ?68 }

            ?69
            ?70 int ?ACEBaseApp_T::startEventLoop()
            ?71 {
            ?72 ??ACE_Thread_Manager::instance?() -> spawn_n
            ?73 ????(eventThreadNum_,?eventLoop,? this -> reactor());
            ?74
            ?75 ? return ? 0 ;
            ?76
            ?77 }

            ?78
            ?79 int ?ACEBaseApp_T::endEventLoop()
            ?80 {
            ?81
            ?82 ?? this -> reactor() -> end_reactor_event_loop();?
            ?83 ?? return ?ACE_Thread_Manager::instance?() -> wait?();
            ?84 }

            ?85
            ?86 void ?ACEBaseApp_T::hostWnd(CWnd * ?wnd)
            ?87 {
            ?88 ??hostWnd_? = ?wnd;
            ?89 }

            ?90
            ?91 CWnd * ?ACEBaseApp_T::hostWnd()
            ?92 {
            ?93 ?? if (hostWnd_? == ? 0 )
            ?94 ???? return ? 0 ;
            ?95 ?? if (::IsWindow(hostWnd_ -> m_hWnd))
            ?96 ?? {
            ?97 ???? return ?hostWnd_;
            ?98 ??}

            ?99 ?? else
            100 ???? return ? 0 ;
            101 }


            使用說明
            修改CACEAppApp類的基類

            1 #include? " ACEBaseApp.h "
            2 class ?CACEAppApp?:? public ?CWinApp,
            3 ??????????????????? public ?ACEBaseApp_T
            4 {
            5 public :
            6 ????CACEAppApp();
            7 // 略去無關的
            8 }
            ;


            1. 初始化

            ?1 BOOL?CACEAppApp::InitInstance()
            ?2 {
            ?3 // ?略去無關的
            ?4 ????CWinApp::InitInstance();
            ?5 ??ACEBaseApp_T::init();??
            ?6 #if ?1
            ?7 ??ACE_TP_Reactor? * ?tp_reactor? = ? new ?ACE_TP_Reactor;
            ?8 ??ACE_Reactor? * ?my_reactor? = ? new ?ACE_Reactor(tp_reactor,? 1 );
            ?9 ??ACE_Reactor::instance(my_reactor,? 1 );
            10 #endif
            11 ??ACEBaseApp_T::reactor(ACE_Reactor::instance());
            12 ??ACEBaseApp_T::startEventLoop();
            13 // ?略去無關的????
            14 ???? return ?FALSE;
            15 }

            ?

            2. 結束

            ?

            1 int ?CACEAppApp::ExitInstance()
            2 {
            3 ?? // ?TODO:?Add?your?specialized?code?here?and/or?call?the?base?class
            4 ??ACEBaseApp_T::fini();
            5
            6 ?? return ?CWinApp::ExitInstance();
            7 }


            3. 注冊事件

            1 ????te_? = ? new ?TimerEvent_T();
            2 ????ACE_Reactor * ?r? = ?theApp.reactor();
            3 ????ACE_Time_Value?t1( 1 );
            4 ????ACE_Time_Value?t2( 2 );
            5 ????r -> schedule_timer(te_, 0 ,t1,t2);

            ?

            4. 與界面通訊

            ? theApp.hostWnd(this);

            1 ??CACEAppDlg * ?dlg? = ?(CACEAppDlg * )?theApp.hostWnd();
            2 ??ASSERT(dlg? != ? 0 );
            3
            4 ??dlg -> log( " time?out " );
            posted on 2006-03-21 17:14 Stone Jiang 閱讀(2675) 評論(3)  編輯 收藏 引用 所屬分類: ACE

            Feedback

            # re: 將ACE事件循環(huán)與MFC UI集成的一種實現(xiàn) 2006-04-08 16:20 aa
            感謝  回復  更多評論
              

            # re: 將ACE事件循環(huán)與MFC UI集成的一種實現(xiàn) 2006-04-11 14:45 ACEBULL
            注冊事件
            與界面通訊
            在那里調用啊?  回復  更多評論
              

            # re: 將ACE事件循環(huán)與MFC UI集成的一種實現(xiàn) 2006-04-11 14:49 ace
            @ACEBULL
            需要完整例子給我發(fā)郵件吧.  回復  更多評論
              

            99精品国产免费久久久久久下载| 四虎亚洲国产成人久久精品| 欧美va久久久噜噜噜久久| 久久精品中文字幕大胸| 日产精品99久久久久久| 精品免费tv久久久久久久| 岛国搬运www久久| 色妞色综合久久夜夜| 久久免费视频观看| 久久综合久久美利坚合众国| 久久精品国产99国产精品澳门| 亚洲狠狠久久综合一区77777| 国产精品久久久久久久久久影院| 久久精品国产精品亚洲毛片| 久久久久无码国产精品不卡| 久久99精品国产麻豆| 精品久久久久成人码免费动漫| 久久久中文字幕| 久久中文骚妇内射| 久久无码国产专区精品| 久久精品国产72国产精福利| 久久精品无码一区二区无码| 久久成人小视频| 久久综合狠狠色综合伊人| 伊人久久大香线焦AV综合影院| 久久国产精品偷99| 国产999精品久久久久久| 久久久久亚洲精品无码蜜桃| 色天使久久综合网天天| 热久久国产欧美一区二区精品| 国产一区二区精品久久凹凸| 88久久精品无码一区二区毛片| 久久精品国产亚洲AV无码娇色| 久久精品日日躁夜夜躁欧美| 亚洲精品成人久久久| 久久综合伊人77777| 亚洲精品第一综合99久久| 一本综合久久国产二区| 亚洲国产成人精品91久久久 | 久久精品一区二区影院| 狠狠色噜噜狠狠狠狠狠色综合久久 |