int main(int argc, char *argv[]) { mmatic *mm; struct flowcalc *fc; void *h; struct module *mod; char *name, *s; tlist *ls; void *pdata; /* * initialization */ mm = mmatic_create(); fc = mmatic_zalloc(mm, sizeof *fc); fc->mm = mm; fc->modules = tlist_create(NULL, mm); /* read options */ if (parse_argv(fc, argc, argv)) return 1; /* enable all modules found in given directory */ if (tlist_count(fc->modules) == 0) { ls = pjf_ls(fc->dir, mm); tlist_iter_loop(ls, name) { s = strrchr(name, '.'); if (s && streq(s, ".so")) { *s = 0; tlist_push(fc->modules, name); } }
struct spi_ep *ep_new_pkt(struct spi_source *source, spi_epaddr_t epa, const struct timeval *ts, void *data, uint32_t size) { struct spi *spi = source->spi; struct spi_ep *ep; char *key; struct spi_pkt *pkt; mmatic *mm; key = _k(source, epa); ep = thash_get(spi->eps, key); if (!ep) { mm = mmatic_create(); ep = mmatic_zalloc(mm, sizeof *ep); ep->mm = mm; ep->source = source; ep->epa = epa; thash_set(spi->eps, key, ep); source->eps++; dbg(8, "new ep %s\n", spi_epa2a(epa)); } /* make packet */ pkt = mmatic_zalloc(ep->mm, sizeof *pkt); pkt->size = size; pkt->payload = mmatic_zalloc(ep->mm, spi->options.N); memcpy(pkt->payload, data, spi->options.N); memcpy(&pkt->ts, ts, sizeof(struct timeval)); /* update last packet time */ memcpy(&ep->last, ts, sizeof(struct timeval)); /* store packet */ if (!ep->pkts) ep->pkts = tlist_create(mmatic_free, ep->mm); tlist_push(ep->pkts, pkt); /* generate event if pkts big enough */ if (ep->gclock1 == 0 && tlist_count(ep->pkts) >= spi->options.C) { ep->gclock1++; spi_announce(spi, "endpointPacketsReady", 0, ep, false); dbg(7, "ep %s ready\n", spi_epa2a(epa)); } return ep; }