1 string[] messages; 2 string[] human_readed; 3 string[] robot_readed; 4 string[] cliend_okdas; 5 6 class Postal : ExternalMemoryManager 7 { 8 mixin EMM; 9 Signal!string onMessage; 10 this() { onMessage = newEMM!(Signal!string); } 11 void message( string msg ) 12 { 13 messages ~= msg; 14 onMessage( msg ); 15 } 16 } 17 18 class Client : SlotHandler, ExternalMemoryManager 19 { 20 mixin EMM; 21 22 SlotController sc; 23 Slot!string read_slot; 24 Slot!string okda_slot; 25 26 this() 27 { 28 sc = newEMM!SlotController; 29 read_slot = newEMM!(Slot!string)(this,&read); 30 okda_slot = newEMM!(Slot!string)(this,&okda); 31 } 32 33 SlotController slotController() @property { return sc; } 34 35 abstract void read( string msg ); 36 37 void okda( string msg ) { cliend_okdas ~= msg; } 38 } 39 40 auto human = new class Client 41 { override void read( string msg ) { human_readed ~= msg; } }; 42 43 auto robot = new class Client 44 { override void read( string msg ) { robot_readed ~= msg; } }; 45 46 auto postal = new Postal; 47 48 postal.message( "test" ); 49 assert( messages.length == 1 ); 50 assert( messages[0] == "test" ); 51 assert( human_readed.length == 0 ); 52 assert( robot_readed.length == 0 ); 53 assert( cliend_okdas.length == 0 ); 54 55 postal.onMessage.connect( human.read_slot ); 56 postal.onMessage.connect( human.read_slot ); 57 postal.onMessage.connect( human.okda_slot ); 58 59 postal.message( "hello" ); 60 assert( messages.length == 2 ); 61 assert( human_readed.length == 1 ); 62 assert( human_readed[0] == "hello" ); 63 assert( robot_readed.length == 0 ); 64 assert( cliend_okdas.length == 1 ); 65 66 postal.onMessage.connect( robot.read_slot ); 67 68 postal.message( "tech" ); 69 assert( messages.length == 3 ); 70 assert( human_readed.length == 2 ); 71 assert( robot_readed.length == 1 ); 72 assert( robot_readed[0] == "tech" ); 73 assert( cliend_okdas.length == 2 ); 74 75 postal.onMessage.disconnect( human ); 76 77 postal.message( "tech2" ); 78 assert( messages.length == 4 ); 79 assert( human_readed.length == 2 ); 80 assert( robot_readed.length == 2 ); 81 assert( cliend_okdas.length == 2 ); 82 83 human.read( "ok" ); 84 assert( human_readed.length == 3 ); 85 86 robot.destroy(); 87 88 postal.message( "tech3" ); 89 90 assert( messages.length == 5 ); 91 assert( human_readed.length == 3 ); 92 assert( robot_readed.length == 2 ); 93 assert( cliend_okdas.length == 2 ); 94 95 postal.onMessage.connect( human.read_slot ); 96 postal.onMessage.connect( human.okda_slot ); 97 98 postal.message( "bb" ); 99 assert( messages.length == 6 ); 100 assert( human_readed.length == 4 ); 101 assert( robot_readed.length == 2 ); 102 assert( cliend_okdas.length == 3 ); 103 104 postal.onMessage.disconnect( human.okda_slot ); 105 106 postal.message( "fbb" ); 107 assert( messages.length == 7 ); 108 assert( human_readed.length == 5 ); 109 assert( robot_readed.length == 2 ); 110 assert( cliend_okdas.length == 3 );