// Join a group. //////////////// void CTitlePage::OnDblclkGroups(NMHDR* pNMHDR, LRESULT* pResult) { NMHEADER * header = (NMHEADER *)pNMHDR; // If something was double-clicked, join it. //////////////////////////////////////////// if(header->iItem != -1) JoinGroup(header->iItem); *pResult = 0; }
LRESULT CTitlePage::OnWizardNext() { // Update vars. /////////////// UpdateData(); // Make sure something was selected. //////////////////////////////////// int nIndex = m_groups.GetSelectionMark(); if(nIndex == -1) { MessageBox("You must have a group selected."); return -1; } // Join the group. ////////////////// JoinGroup(nIndex); return (LRESULT)GROUP_PAGE; }
void McastEventHandler(NodeState * sv, tw_bf * cv, EventMsg * em, tw_lp * lp) { uint32 gid, ref = 0; int nid; MapUnitType * portMap; uint32 dstAddr; Packet * p; Agent * a; MapUnitType hiu; nid = lp->id; switch (em->type_) { case GROUP_OP: gid = em->content_.grpOp_.group_; switch (em->content_.grpOp_.op_) { case CREATE: AddGroup (gid, nid); break; case JOIN: JoinGroup (nid, gid); break; case LEAVE: LeaveGroup (nid, gid); break; default: printf ("Group operation error: Unknown group op type <%d> on lp %d.\n", (int) em->content_.grpOp_.op_, (int) nid); tw_exit (-1); } break; case DATA_PKT: dstAddr = em->content_.pkt_.dstAddr_; p = &(em->content_.pkt_); /* * Check whether this node is the destination. If not, forward it only. * If yes, hand it to upper layer and forward it if necessary */ if (IsMcastAddr (dstAddr)) { /* Multicast address */ if (p->id_) { ref = GetExtPktRef (p->srcAddr_, p->srcAgent_, p->id_); -- ref; } if ((portMap = GetFwdPortMap (lp->id, dstAddr)) != NULL) { if ((hiu = portMap[PORT_MAP_SIZE - 1]) & HIGHEST_BIT_TEST) { PassPktToUpperLayer (lp, p); } /* Forward it if necessary */ portMap[PORT_MAP_SIZE - 1] &= ~(HIGHEST_BIT_TEST); if (! IsEmptyMap (portMap)) { ref += ForwardMulticastPkt (lp, p, portMap); } portMap[PORT_MAP_SIZE - 1] = hiu; } if (p->id_) { if (ref == 0) { DelExtPkt (p->srcAddr_, p->srcAgent_, p->id_); } else { SetExtPktRef (p->srcAddr_, p->srcAgent_, p->id_, ref); } } break; } /* Unicast address */ if (dstAddr == _nodeTable[nid].addr_) { PassPktToUpperLayer (lp, p); if (p->id_) DelExtPkt (p->srcAddr_, p->srcAgent_, p->id_); } else { ForwardUnicastPkt (lp, p); } break; case START_AGENT: a = em->content_.agent_; a->startf_ (a); break; case STOP_AGENT: a = em->content_.agent_; a->stopf_ (a); break; case AGENT_TIMER: a = em->content_.timeOut_.agent_; a->timerf_ (a, em->content_.timeOut_.timerId_, em->content_.timeOut_.serial_); break; default: printf ("Unknown event message type %d.\n", em->type_); tw_exit (-1); } }
/* * NOTE: group address is modified here by turning on the highest bit. */ void ReadGroupOp (char * fileName) { int fd, n; char buf[MAX_LINE_LEN]; double t; int nid, act; uint32 gid; tw_lp * lp; tw_event * e; EventMsg * em; GroupOp * gop; /* * Read group operation of joining/leaving. Do it only once (at init of lp 0). */ if ((fd = open (fileName, O_RDONLY)) < 0) { printf ("Failed to open the group operation file <%s>\n", fileName); exit (-1); } while (ReadLine (fd, buf) > 0) { if ((n = sscanf (buf, "%lf %d %d %d", &t, (int *) &nid, (int *) &gid, (int *) &act)) <= 0) { continue; } if (n != 4) { printf ("Group operation error: Wrong format. Line: <%s>\n", buf); exit (-1); } if (t < 0 || nid < 0 || gid < 0) { printf ("Group operation error: Invalid content. Line: <%s>\n", buf); exit (-1); } if (t >= g_tw_ts_end) continue; SetGrpAddr4Prog (gid); if (t <= 0) { /* Process the operation now */ switch (act) { case CREATE: AddGroup (gid, nid); break; case JOIN: JoinGroup (nid, gid); break; case LEAVE: LeaveGroup (nid, gid); break; default: printf ("Group operation error: Unknown group op type. Line: <%s>\n", buf); exit (-1); } continue; } /* * Future events */ if ((lp = tw_getlp (nid)) == NULL) { printf ("Group operation error: Unable to get lp for node. Line: <%s>\n", buf); exit (-1); } if ((e = tw_event_new (lp, t, lp)) == NULL) { printf ("Group operation error: Unable to create event. Line: <%s>\n", buf); exit (-1); } em = (EventMsg *) tw_event_data (e); em->type_ = GROUP_OP; gop = &(em->content_.grpOp_); gop->group_ = gid; gop->op_ = act; tw_event_send (e); } close (fd); }