/*     boost connection에 관한 부분     */

boost::signal< void() > sig01;
// signal 이 아니고 signals 임. 주의. 게다가 connection 대문자로 쓰면 다른 의미의 컨넥션이 됨.
boost::signals::connection c01;

// connect 함수의 리턴값이 바로 컨넥션
c01 = sig01.connect( Func() );

// 연결 여부를 리턴하는 함수
if( c01.connected() ) {
    sig01();
}

/*
* boost::connection 헤더에 정의된 모냥
*  // Returns true if the signal and slot are connected
*  bool connected() const { return con.get() && con->signal_disconnect; }
*/

c01.disconnect();      // 연결 끊기

c01.block();              // 임시로 블럭.
c01.unblock();          // 블럭해제

{
    int a02 = 10;
// sig01.connect( Func() );
    boost::signals::scoped_connection c02 = sig01.connect( Func() );
    sig01();
}
// scoped_connection으로 연결했던 signal 이라면 실행되지 않는다.
// 단, scoped 가 아니면 지역변수로 만들었더라도 실행이 된다.
sig01();
cout << a02 << endl;           // 물론 컴파일 에러. a02를 못 찾는다.



ps. 만약 signal 생성시 리턴값이 있는 signal을 만들면
disconnection 이나 block 이후 시그널 호출시 오류가 남.
ex) boost::signal< int() > sig01;
boost::signals::connection c01 = sig01.connect( Func() );

c01.disconnect();   or      c01.block();
sig01();           -- 에러 발생

'Programming > Boost' 카테고리의 다른 글

asio -- 1  (0) 2009.12.01
Bind 공부중인거 정리. < 01 >  (0) 2009.08.20
Signal 공부중인거 정리. < 03 >  (0) 2009.08.20
Signal 공부중인거 정리. < 02 > - 1  (0) 2009.08.19
Signal 공부중인거 정리. < 02 >  (0) 2009.08.19