|
| 1 | +protocol Prot { |
| 2 | + out m(`int`); |
| 3 | +}; |
| 4 | + |
| 5 | +capsule A { |
| 6 | + service behavior port p1~ : Prot; |
| 7 | + service behavior port p2 : Prot; |
| 8 | + statemachine { |
| 9 | + state WaitingForM; |
| 10 | + initial -> WaitingForM ` |
| 11 | + printf("[%s:A] starting\n", this->getName()); |
| 12 | + `; |
| 13 | + m: WaitingForM -> WaitingForM on p1.m |
| 14 | + ` |
| 15 | + const char * myName = this->getName(); |
| 16 | + int toSend; |
| 17 | + if (myName[1] == '1') |
| 18 | + toSend = 1; |
| 19 | + else if (myName[1] == '2') |
| 20 | + toSend = 2; |
| 21 | + else toSend = 3; |
| 22 | + |
| 23 | + printf("[%s:A] received m(%d) on p1, sending m(%d) on port p2\n", myName, *rtdata, toSend); |
| 24 | + p2.m(toSend).send(); |
| 25 | + `; |
| 26 | + }; |
| 27 | +}; |
| 28 | + |
| 29 | +capsule B { |
| 30 | + [[rt::decl]] |
| 31 | + ` |
| 32 | + public: |
| 33 | + int count = 0; |
| 34 | + int pIndexes = 0; |
| 35 | + ` |
| 36 | + service behavior port p1 : Prot[3]; |
| 37 | + service behavior port p2~ : Prot[3]; |
| 38 | + statemachine { |
| 39 | + state State1; |
| 40 | + initial -> State1 ` |
| 41 | + printf("[%s:B] starting\n", this->getName()); |
| 42 | + printf("[%s:B] sending m(42) on port p1\n", this->getName()); |
| 43 | + p1.m(42).send(); |
| 44 | + `; |
| 45 | + m: State1 -> State1 on p2.m ` |
| 46 | + printf("[%s:B] received m(%d) on port p2[%d]\n", this->getName(), *rtdata, msg->sapIndex0()); |
| 47 | + |
| 48 | + count += *rtdata; |
| 49 | + pIndexes += msg->sapIndex0(); |
| 50 | + if (count == 1 + 2 + 3) { |
| 51 | + ASSERT(pIndexes == 0 + 1 + 2, "Sum of port indexes does not match 0 + 1 + 2"); |
| 52 | + PASS(); |
| 53 | + } |
| 54 | + `; |
| 55 | + }; |
| 56 | +}; |
| 57 | + |
| 58 | +capsule Top { |
| 59 | + part a1 : A; |
| 60 | + part a2 : A; |
| 61 | + part a3 : A; |
| 62 | + part b : B; |
| 63 | + connect b.p1 with a1.p1; |
| 64 | + connect b.p1 with a2.p1; |
| 65 | + connect b.p1 with a3.p1; |
| 66 | + connect a1.p2 with b.p2; |
| 67 | + connect a2.p2 with b.p2; |
| 68 | + connect a3.p2 with b.p2; |
| 69 | + statemachine { |
| 70 | + state State1; |
| 71 | + initial -> State1; |
| 72 | + }; |
| 73 | +}; |
0 commit comments