Sample 2: Simple GUI Events Handling By Connecting Two Local Channels


This sample is based on sample 1 with changes to demonstrate connecting two local channels.

Also we use the following POD struct (defined in linear_id_trait.hpp) as message id/names:
    struct struct_id {
      message_family family;
      int type;
      ......
    };

The changes are inside main() function:
int main(int, char **) {
First we create 2 channels
  evt_chan chan1;
  evt_chan chan2;
Then we connect these 2 channels
  connect(chan1, chan2);
Bind event source to channel 1
  gui_window window(chan1);
create handler object and bind it to channel 1
  window_handler hdlr(chan1);
create more event sinks and bind the global function to channel 2.
  evt_chan::in window_down_in(chan2, win_but_down_id, evt_handler);
  evt_chan::in window_up_in(chan2, win_but_up_id, evt_handler);
  evt_chan::in shut_down_in(chan2, win_close_id, evt_handler);
Now we fire some event for testing.
  window.up("..Hi there [mouse-left-up] ..");
  window.down(".. a simple window test [mouse-right-down] ..");
  window.close(".. simple window wiered [window-closed] ..");
Last exit
  cout << "... exit ...\n";
  return 0;
}

From testing, we should see events propagate to both channel 1 and channel 2 and events get printed out by callbacks at both channels.
Complete source listing...