//.............................................................................. // // This file is part of the Jancy toolkit. // // Jancy is distributed under the MIT license. // For details see accompanying license.txt file, // the public copy of which is also available at: // http://tibbo.com/downloads/archive/jancy/license.txt // //.............................................................................. // When it comes to describing what has to be done in response to a property // change the expressions are not always sufficient. For example, it may be // necessary to run a for-loop cycle or execute a sequence of statements. // In addition, tracking changes of ALL bindable properties referenced from // an expression within a reactor can sometimes be too much. The developer may // need to have more control over what bindable properties or events to track. // The 'onevent' statement in the reactor block gives the developer // fine-grained control over dependencies and at the same time frees him from // the routine task of manually subscribing to events. //.............................................................................. bool bindable g_useDhcp; uint32_t bindable g_ip4; uint32_t bindable g_routerIp4; event g_onApplyIpSettings (); // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . reactor g_ipReactor () { onevent bindingof (g_useDhcp) () { if (g_useDhcp) printf ("using DHCP, disable IP-edit\n"); else printf ("using manual IP configuration\n"); } // it's OK to specify multiple events to subscribe to onevent (bindingof (g_ip4), bindingof (g_routerIp4)) () { printf ("IP or router IP has changed\n"); g_useDhcp = false; } // the 'onevent' statement allows subscribing to any events, not just // bindable ones onevent g_onApplyIpSettings () { for (int i = 0; i < 100; i += 10) printf ("applying %d%%...\n", i); printf ("done!\n"); } } //.............................................................................. // entry point int main () { printf ("main ()\n"); g_ipReactor.start (); printf ("turning DHCP on...\n"); g_useDhcp = true; printf ("changing IP...\n"); g_ip4 = 0xc0a80148; printf ("changing router IP...\n"); g_ip4 = 0xc0a80101; printf ("applying IP settings...\n"); g_onApplyIpSettings (); return 0; } //..............................................................................