void handle_subscriber(erlmunk_subscriber *subscriber, element *bodies) { element *el; int count = 0; LL_COUNT(bodies, el, count); // DEBUGF(("# bodies in subscriber bounding box: %d", count)); ETERM **l_array = (ETERM **) malloc(sizeof(ETERM) * count); int nth_body = 0; LL_FOREACH(bodies, el) { cpVect vect = cpBodyGetPosition(el->body); float angle = cpBodyGetAngle(el->body); // cpVect vel = cpBodyGetVelocity(el->body); erlmunk_body_data *data = (erlmunk_body_data *) cpBodyGetUserData(el->body); // DEBUGF(("id: %d, x: %f, y: %f, angle: %f, vel.x: %f, vel.y: %f, data: %p", // data->id, vect.x, vect.y, angle, vel.x, vel.y, data)); ETERM **t_array = (ETERM **) malloc(sizeof(ETERM) * 4); t_array[0] = erl_mk_float(vect.x); t_array[1] = erl_mk_float(vect.y); t_array[2] = erl_mk_float(angle); if (data->term == NULL) t_array[3] = erl_mk_undefined(); else t_array[3] = erl_copy_term(data->term); ETERM *tuple = erl_mk_tuple(t_array, 4); free(t_array); ETERM *prop_value = erl_mk_int_prop_value(data->id, tuple); l_array[nth_body++] = prop_value; }
static err_t _eth_link_output(struct netif *netif, struct pbuf *p) { netdev_t *netdev = (netdev_t *)netif->state; struct pbuf *q; unsigned int count = 0; #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif LL_COUNT(p, q, count); iolist_t iolist[count]; /* make last point to the last entry of iolist[] */ iolist_t *last = &iolist[count]; last--; for (q = p, count = 0; q != NULL; q = q->next, count++) { iolist_t *iol = &iolist[count]; iol->iol_next = (iol == last) ? NULL : &iolist[count + 1]; iol->iol_base = q->payload; iol->iol_len = (size_t)q->len; } #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif return (netdev->driver->send(netdev, iolist) > 0) ? ERR_OK : ERR_BUF; }
static err_t _eth_link_output(struct netif *netif, struct pbuf *p) { netdev2_t *netdev = (netdev2_t *)netif->state; struct pbuf *q; unsigned int count = 0; #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif LL_COUNT(p, q, count); struct iovec pkt[count]; for (q = p, count = 0; q != NULL; q = q->next, count++) { pkt[count].iov_base = q->payload; pkt[count].iov_len = (size_t)q->len; } #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif return (netdev->driver->send(netdev, pkt, count) > 0) ? ERR_OK : ERR_BUF; }
void apply_actions(void **state) { struct flow *fl = flow_new(); struct instruction_set is; instruction_set_init(&is); set_eth_type(fl, 0x800); struct apply_actions aa; struct action_list al; struct action gen_act; action_list_init(&al); action_output(&gen_act, 2); action_list_add(&al, gen_act); action_set_field_u16(&gen_act, SET_IP_PROTO, 6); action_list_add(&al, gen_act); inst_apply_actions(&aa, al); add_apply_actions(&is, aa); flow_add_instructions(fl, is); assert_int_equal(fl->insts.active, INSTRUCTION_APPLY_ACTIONS); int count = 0; struct action_list_elem *elem; LL_COUNT(fl->insts.apply_act.actions.actions, elem, count); assert_int_equal(count, 2); flow_destroy(fl); }
int EventQueue::size(void) { scheduling_s *tmp; int result; LL_COUNT(head, tmp, result); return result; }
void meterd_output(sel_counter* sel_counters, const char* dbname, const char* outfile, const int format, const int additive, const int interval, const char* range_file, const int give_y_range, const long double y_offset, const int give_x_range, int skip_time) { db_res_ctr** results = NULL; db_res_ctr** result_it = NULL; db_res_ctr** result_tmp = NULL; int ctr_count = 0; int i = 0; int iterating = 1; sel_counter* ctr_it = 0; void* db_handle = NULL; int select_from = ((int) time(NULL)) - interval; FILE* out = stdout; long double added = 0.0f; long double max_y = -100000000.0f; long double min_y = 100000000.0f; int min_x = 0x7fffffff; int max_x = 0; if (outfile != NULL) { out = fopen(outfile, "w"); if (out == NULL) { ERROR_MSG("Failed to open %s for writng", outfile); return; } } /* Initialise database handling */ if (meterd_db_init() != MRV_OK) { ERROR_MSG("Failed to initialise database handling, giving up"); if (outfile) { fclose(out); unlink(outfile); } return; } /* Open the database */ if (meterd_db_open(dbname, 1, &db_handle) != MRV_OK) { ERROR_MSG("Failed to open database file %s", dbname); meterd_db_finalize(); if (outfile) { fclose(out); unlink(outfile); } return; } /* Allocate space for results from the database */ LL_COUNT(sel_counters, ctr_it, ctr_count); results = (db_res_ctr**) calloc(ctr_count, sizeof(db_res_ctr*)); result_it = (db_res_ctr**) calloc(ctr_count, sizeof(db_res_ctr*)); result_tmp = (db_res_ctr**) calloc(ctr_count, sizeof(db_res_ctr*)); /* Retrieve results from the database */ i = 0; LL_FOREACH(sel_counters, ctr_it) { if (meterd_db_get_results(db_handle, ctr_it->id, ctr_it->invert, &results[i++], select_from, skip_time) != MRV_OK) { ERROR_MSG("Failed to retrieve results for %s from database %s", ctr_it->id, dbname); if (outfile) { fclose(out); unlink(outfile); } return; } } /* Output the data */ if (format == FORMAT_CSV) { /* Output the heading first */ fprintf(out, "timestamp"); if (additive) { fprintf(out, ","); } i = 0; LL_FOREACH(sel_counters, ctr_it) { if (additive) { fprintf(out, "%s%s", ctr_it->id, (i > 0) ? "+" : ""); } else { fprintf(out, ",%s", ctr_it->id); } i++; } fprintf(out, "\n"); /* Set iterators to start of list */ for (i = 0; i < ctr_count; i++) { result_it[i] = results[i]; } while(iterating) { added = 0.0f; /* Have we reached the end of one of the result lists? */ for (i = 0; i < ctr_count; i++) { if (result_it[i] == NULL) { iterating = 0; break; } } if (!iterating) break; /* Print one result for each result list */ for (i = 0; i < ctr_count; i++) { if (i == 0) { /* * Output the timestamp of the first result list; * because of the way data is written to the database, * timestamps are the same in all tables per row */ fprintf(out, "%d", result_it[i]->timestamp); if (result_it[i]->timestamp < min_x) { min_x = result_it[i]->timestamp; } else if (result_it[i]->timestamp > max_x) { max_x = result_it[i]->timestamp; } } if (!additive) { fprintf(out, ",%0.3Lf", result_it[i]->value); if (result_it[i]->value < min_y) { min_y = result_it[i]->value; } else if (result_it[i]->value > max_y) { max_y = result_it[i]->value; } } else { added += result_it[i]->value; } } if (additive) { fprintf(out, ",%0.3Lf", added); if (added < min_y) { min_y = added; } else if (added > max_y) { max_y = added; } } fprintf(out, "\n"); /* Advance all lists one step and discard processed results */ for (i = 0; i < ctr_count; i++) { result_tmp[i] = result_it[i]; result_it[i] = result_it[i]->next; free(result_tmp[i]->unit); free(result_tmp[i]); } } }