Пример #1
0
sip_call_t *
call_create(char *callid, char *xcallid)
{
    sip_call_t *call;

    // Initialize a new call structure
    if (!(call = sng_malloc(sizeof(sip_call_t))))
        return NULL;

    // Create a vector to store call messages
    call->msgs = vector_create(2, 2);
    vector_set_destroyer(call->msgs, msg_destroyer);

    // Create an empty vector to store rtp packets
    if (setting_enabled(SETTING_CAPTURE_RTP)) {
        call->rtp_packets = vector_create(0, 40);
        vector_set_destroyer(call->rtp_packets, packet_destroyer);
    }

    // Create an empty vector to strore stream data
    call->streams = vector_create(0, 2);
    vector_set_destroyer(call->streams, vector_generic_destroyer);

    // Create an empty vector to store x-calls
    call->xcalls = vector_create(0, 1);

    // Initialize call filter status
    call->filtered = -1;

    // Set message callid
    call->callid = strdup(callid);
    call->xcallid = strdup(xcallid);

    return call;
}
Пример #2
0
void liquid_wave_get_normal_z(map_liquid_type *liq,int div,float *wave_y,int top_add,d3vct *normal)
{
	int				top,top_prev,top_next,
					y,y_prev,y_next;
	d3vct			p10,p20,n1,n2;

	top=liq->top+(top_add*div);
	y=(int)wave_y[div&0x3];

	top_prev=top-top_add;
	y_prev=(int)wave_y[(div-1)&0x3];

	top_next=top+top_add;
	y_next=(int)wave_y[(div+1)&0x3];

		// get previous and next
		// polygon normals

	vector_create(&p10,liq->rgt,y_prev,top_prev,liq->lft,y_prev,top_prev);
	vector_create(&p20,liq->lft,y,top,liq->lft,y_prev,top_prev);
	vector_cross_product(&n1,&p10,&p20);
	vector_normalize(&n1);

	vector_create(&p10,liq->rgt,y,top,liq->lft,y,top);
	vector_create(&p20,liq->lft,y_next,top_next,liq->lft,y,top);
	vector_cross_product(&n2,&p10,&p20);
	vector_normalize(&n2);

		// average for normal

	normal->x=(n1.x+n2.x)*0.5f;
	normal->y=(n1.y+n2.y)*0.5f;
	normal->z=(n1.z+n2.z)*0.5f;
	vector_normalize(normal);
}
Пример #3
0
void animation_create(animation *ani, void *src, int id) {
    sd_animation *sdani = (sd_animation*)src;

    // Copy simple stuff
    ani->id = id;
    ani->start_pos = vec2i_create(sdani->start_x, sdani->start_y);
    str_create_from_cstr(&ani->animation_string, sdani->anim_string);

    // Copy collision coordinates
    vector_create(&ani->collision_coords, sizeof(collision_coord));
    collision_coord tmp_coord;
    for(int i = 0; i < sdani->col_coord_count; i++) {
        tmp_coord.pos = vec2i_create(sdani->col_coord_table[i].x, sdani->col_coord_table[i].y);
        tmp_coord.frame_index = sdani->col_coord_table[i].y_ext;
        vector_append(&ani->collision_coords, &tmp_coord);
    }

    // Copy extra strings
    vector_create(&ani->extra_strings, sizeof(str));
    str tmp_string;
    for(int i = 0; i < sdani->extra_string_count; i++) {
        str_create_from_cstr(&tmp_string, sdani->extra_strings[i]);
        vector_append(&ani->extra_strings, &tmp_string);
        // don't str_free tmp_str here because it will free the pointers
        // inside it, which vector_append does not copy
    }

    // Handle sprites
    vector_create(&ani->sprites, sizeof(sprite));
    sprite tmp_sprite;
    for(int i = 0; i < sdani->frame_count; i++) {
        sprite_create(&tmp_sprite, (void*)sdani->sprites[i], i);
        vector_append(&ani->sprites, &tmp_sprite);
    }
}
Пример #4
0
void
capture_init(size_t limit, bool rtp_capture)
{
    capture_cfg.limit = limit;
    capture_cfg.rtp_capture = rtp_capture;
    capture_cfg.sources = vector_create(1, 1);
    capture_cfg.tcp_reasm = vector_create(0, 10);
    capture_cfg.ip_reasm = vector_create(0, 10);

    // Fixme
    if (setting_has_value(SETTING_CAPTURE_STORAGE, "none")) {
        capture_cfg.storage = CAPTURE_STORAGE_NONE;
    } else if (setting_has_value(SETTING_CAPTURE_STORAGE, "memory")) {
        capture_cfg.storage = CAPTURE_STORAGE_MEMORY;
    } else if (setting_has_value(SETTING_CAPTURE_STORAGE, "disk")) {
        capture_cfg.storage = CAPTURE_STORAGE_DISK;
    }

    // Initialize calls lock
    pthread_mutexattr_t attr;
    pthread_mutexattr_init(&attr);
#if defined(PTHREAD_MUTEX_RECURSIVE) || defined(__FreeBSD__) || defined(BSD) || defined (__OpenBSD__) || defined(__DragonFly__)
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
#else
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
#endif
    pthread_mutex_init(&capture_cfg.lock, &attr);

}
Пример #5
0
int
main(int argc, char **argv)
{
  const int n = 3;

  // init our vectors of size n
  struct vector *x = vector_create(n);
  struct vector *y = vector_create(n);
  struct vector *z = vector_create(n);
  struct vector *z_ref = vector_create(n);

  // initialize values for testing
  for (int i = 0; i < n; i++) {
    VEC(x, i) = i + 1.f;
    VEC(y, i) = i + 2.f;
    VEC(z_ref, i) = 2*i + 3.f;
  }

  // test the vector_add()
  vector_add(x, y, z);

  // and make sure it equals the reference result
  assert(vector_is_equal(z, z_ref));

  // clean up
  vector_destroy(x);
  vector_destroy(y);
  vector_destroy(z);
  vector_destroy(z_ref);

  return 0;
}
Пример #6
0
animation* create_animation_from_single(sprite *sp, vec2i pos) {
    animation *a = malloc(sizeof(animation));
    a->start_pos = pos;
    a->id = -1;
    str_create_from_cstr(&a->animation_string, "A9999999999");
    vector_create(&a->collision_coords, sizeof(collision_coord));
    vector_create(&a->extra_strings, sizeof(str));
    vector_create(&a->sprites, sizeof(sprite));
    vector_append(&a->sprites, sp);
    free(sp);
    return a;
}
Пример #7
0
int main(int argc, char * argv[])
{
    int n, n_threads = 0;
    matrix_t * A,
             * A_orig;
    vector_t * b,
             * b_orig,
             * x,
             * check_res_mat;
             
    double t_start, t_end;
    
    
    get_input_params(argc, argv, &n);
    initialize_global_state();
    
    /* initialize data */
    A_orig          = matrix_create_rand(n, n),
    A               = matrix_clone(A_orig),
    b_orig          = vector_create_rand(n),
    b               = vector_clone(b_orig),
    x               = vector_create(n),
    check_res_mat   = vector_create(n);
    
    t_start = get_time_in_sec();
    
    perform_gaussian_elimination_on_matrix(A, b);
    perform_back_substitution(A, x, b);
    
    t_end  = get_time_in_sec();
    
    /* calculate Ax - b and find it's l2norm to test for correctness */
    matrix_mult_vector(A_orig, x, check_res_mat);
    
    vector_subtract(check_res_mat, check_res_mat, b_orig); /* c = c - b */
    
    printf("num-procs   = %d\n", omp_get_num_procs());

#pragma omp parallel num_threads(num_threads)
#pragma omp single
    n_threads = omp_get_num_threads();

    printf("num-threads = %d\n", n_threads);

    printf("Performed Gaussian Elimination in %.12lfs\n", t_end - t_start);
    printf("Ax-b l2norm = %.6le\n", vector_l2norm(check_res_mat));
    
    puts("done");   
    return 0;
}
Пример #8
0
void test_vector_remove_empty_array() {
    array* arr = vector_create();

    ASSERT(vector_remove(arr, 0) == false);
    ASSERT(arr->size == 0);
    vector_free(arr);
}
Пример #9
0
void test_vector_create() {
    array *arr = vector_create();
    ASSERT(arr->capacity == init_capacity);
    ASSERT(arr->size == 0);

    vector_free(arr);
}
Пример #10
0
int
main(int argc, char **argv)
{
  MPI_Init(&argc, &argv);
  libmrc_params_init(argc, argv);

  struct vector *vec = vector_create(MPI_COMM_WORLD);
  vector_set_from_options(vec);
  vector_setup(vec);
  vector_view(vec);

  int nr_elements;
  vector_get_param_int(vec, "nr_elements", &nr_elements);

  for (int i = 0; i < nr_elements; i++) {
    vector_set_element(vec, i, 2. * i);
  }

  for (int i = 0; i < nr_elements; i++) {
    assert(vector_get_element(vec, i) == 2. * i);
  }

  vector_destroy(vec);

  MPI_Finalize();
}
Пример #11
0
void bk_create(bk *b, void *src) {
    sd_bk_file *sdbk = (sd_bk_file*)src;

    // File ID
    b->file_id = sdbk->file_id;

    // Copy VGA image
    surface_create_from_data(
        &b->background,
        SURFACE_TYPE_PALETTE,
        sdbk->background->w,
        sdbk->background->h,
        sdbk->background->data);

    // Copy sound translation table
    memcpy(b->sound_translation_table, sdbk->soundtable, 30);

    // Copy palettes
    vector_create(&b->palettes, sizeof(palette));
    for(int i = 0; i < sdbk->palette_count; i++) {
        vector_append(&b->palettes, (palette*)sdbk->palettes[i]);
    }

    // Copy info structs
    hashmap_create(&b->infos, 7);
    bk_info tmp_bk_info;
    for(int i = 0; i < 50; i++) {
        if(sdbk->anims[i] != NULL) {
            bk_info_create(&tmp_bk_info, (void*)sdbk->anims[i], i);
            hashmap_iput(&b->infos, i, &tmp_bk_info, sizeof(bk_info));
        }
    }
}
Пример #12
0
void light_map_ray_trace_diffuse(int mesh_idx,int poly_idx,d3pnt *rpt,d3pnt *lit_pnt,d3col *col)
{
	float				diffuse;
	d3vct				diffuse_vct;
	map_mesh_poly_type	*poly;

	if ((mesh_idx==-1) || (poly_idx==-1)) return;

	poly=&map.mesh.meshes[mesh_idx].polys[poly_idx];

		// create the diffuse factor

	vector_create(&diffuse_vct,lit_pnt->x,lit_pnt->y,lit_pnt->z,rpt->x,rpt->y,rpt->z);
	diffuse=(diffuse_vct.x*poly->tangent_space.normal.x)+(diffuse_vct.y*poly->tangent_space.normal.y)+(diffuse_vct.z*poly->tangent_space.normal.z);
	diffuse=((diffuse+1.0f)*0.5f)+map.light_map.diffuse_boost;

	if (diffuse>=1.0f) return;
	if (diffuse<0.0f) diffuse=0.0f;
	
		// calculate the color
		
	col->r*=diffuse;
	col->g*=diffuse;
	col->b*=diffuse;
}
Пример #13
0
/*
 * Returns a new absolute value vector.
 */
vector_t *vabs(vector_t *vector) {
	vector_t *vector2 = vector_create(vector->x, vector->y);
	vector2->x = abs(vector2->x);
	vector2->y = abs(vector2->y);

	return vector2;
}
Пример #14
0
static HANDLE_FUNC (handle_listen)
{
        char *arg = get_string_arg (line, &match[2]);

        if (arg == NULL) {
                return -1;
        }

        if (conf->listen_addrs == NULL) {
               conf->listen_addrs = vector_create();
               if (conf->listen_addrs == NULL) {
                       log_message(LOG_WARNING, "Could not create a list "
                                   "of listen addresses.");
                       safefree(arg);
                       return -1;
               }
        }

        vector_append (conf->listen_addrs, arg, strlen(arg) + 1);

        log_message(LOG_INFO, "Added address [%s] to listen addresses.", arg);

        safefree (arg);

        return 0;
}
Пример #15
0
int main(int argc, char **argv)
{
	vector *c = NULL;
	int v1 = 4;
	int v2 = 1;
	int v3 = 3;
	int v4 = 2;
	int v5 = 16;
	int v6 = 9;
	int v7 = 10;
	int v8 = 14;
	int v9 = 8;
	int v10 = 7;
	c = vector_create();	

	c->push(c, (void *)(&v1 ));
	c->push(c, (void *)(&v2 ));
	c->push(c, (void *)(&v3 ));
	c->push(c, (void *)(&v4 ));
	c->push(c, (void *)(&v5 ));
	c->push(c, (void *)(&v6 ));
	c->push(c, (void *)(&v7 ));
	c->push(c, (void *)(&v8 ));
	c->push(c, (void *)(&v9 ));
	c->push(c, (void *)(&v10));
	Print(c, visit);
	make_heap(c, compare);
	Print(c, visit);
	printf("\n===============================\n");
	heap_sort(c, compare);
	Print(c, visit);
	vector_destroy(&c, NULL);
	return 0;
}
options_t * options_create(bool (* collision_callback)(option_t * option1, const option_t * option2))
{
    options_t * options;

    if (!(options = malloc(sizeof(options_t)))) {
        goto ERR_MALLOC;
    }

    if (!(options->optspecs = vector_create(
        sizeof(option_t),
        (ELEMENT_FREE) option_free,
        (ELEMENT_DUMP) option_dump
    ))) {
        goto ERR_VECTOR_CREATE;
    }

    options->collision_callback = collision_callback;
    options->optspecs->cells = (option_t *) options->optspecs->cells;
    return options;

ERR_VECTOR_CREATE:
    free(options);
ERR_MALLOC:
    return NULL;
}
Пример #17
0
void expand_word_state(search_prefix_t *search, prefix_fifo_t * prefix_info,
                       const struct words_state_t *word_state,
                       const symbol_t *ip, const symbol_t *op, float bo)
{
  prefix_fifo_key_t key = { word_state->state_next, ip, op };
  prefix_fifo_t *pf = (prefix_fifo_t *)hash_search((void *)&key, sizeof(prefix_fifo_key_t), search->hash);
  if (pf == NULL) {
    pf = (prefix_fifo_t *) malloc(sizeof(prefix_fifo_t));
    pf->base_state = word_state->state_next;
    pf->input = ip;
    pf->output = op;

    pf->state = state_grammar_create();
    pf->state->name = (symbol_t*) realloc(pf->state->name, sizeof(symbol_t) * (symlen(pf->base_state->name) + 1));
    symcpy(pf->state->name, pf->base_state->name);
    pf->initial_prob = LOG_ZERO;
    pf->is_accesible = false;
    pf->incoming = vector_create();

    vector_append(search->fifo, pf);
    hash_insert((void *)&key, sizeof(prefix_fifo_key_t), pf, search->hash);
  }

  incoming_t *incoming = (incoming_t *) malloc(sizeof(incoming_t));
  MEMTEST(incoming);
  incoming->prev_pf = prefix_info;
  incoming->word_idx = state_grammar_append(prefix_info->state, word_state->word, word_state->prob + bo, pf->state);
  vector_append(pf->incoming, incoming);
}
Пример #18
0
bool fionpoll_create(struct fionobj * const obj)
{
    bool ret = false;

    if (UTILDEBUG_VERIFY((obj != NULL) && (vector_getsize(&obj->fds) == 0)))
    {
        obj->ops.fion_create    = fionpoll_create;
        obj->ops.fion_destroy   = fionpoll_destroy;
        obj->ops.fion_insertfd  = fionpoll_insertfd;
        obj->ops.fion_deletefd  = fionpoll_deletefd;
        obj->ops.fion_setflags  = fionpoll_setflags;
        obj->ops.fion_poll      = fionpoll_poll;
        obj->ops.fion_getevents = fionpoll_getevents;
        obj->timeoutms          = 0;
        obj->pevents            = 0;
        obj->revents            = 0;

        if (!vector_create(&obj->fds, 0, sizeof(struct pollfd)))
        {
            logger_printf(LOGGER_LEVEL_ERROR,
                          "%s: vector allocation failed (%d)\n",
                          __FUNCTION__,
                          errno);
        }
        else
        {
            ret = true;
        }
    }

    return ret;
}
Пример #19
0
Vector *vector_cross(Vector *a, Vector *b, Vector *write)
{
	if(!write) write = vector_create(0,0,0);
	write->x = (a->y * b->z) - (a->z * b->y);
	write->y = (a->z * b->x) - (a->x * b->z);
	write->z = (a->x * b->y) - (a->y * b->x);
	return write;
}
Пример #20
0
Vector *vector_mul(Vector *a, double d, Vector *write)
{
	if(!write) write = vector_create(0,0,0);
	write->x = a->x * d;
	write->y = a->y * d;
	write->z = a->z * d;
	return write;
}
Пример #21
0
Vector *vector_div(Vector *a, double d, Vector *write)
{
	if(!write) write = vector_create(0,0,0);
	write->x = a->x / d;
	write->y = a->y / d;
	write->z = a->z / d;
	return write;
}
Пример #22
0
Vector *vector_sub(Vector *a, Vector *b, Vector *write)
{
	if(!write) write = vector_create(0,0,0);
	write->x = a->x - b-> x;
	write->y = a->y - b-> y;
	write->z = a->z - b-> z;
	return write;
}
Пример #23
0
Vector *vector_shorten_in_cube(Vector *a, Vector *write){
	if(!write)write = vector_create(0,0,0);
	*write = *a;
	if(write->x > 0.5)write->x -= 1;
	if(write->y > 0.5)write->y -= 1;
	if(write->z > 0.5)write->z -= 1;
	return write;
}
Пример #24
0
void test_vector_append() {
    array *arr = vector_create();
    vector_append(arr, 5);
    ASSERT(arr->array[0] == 5);
    ASSERT(arr->size == 1);

    vector_free(arr);
}
Пример #25
0
Vector *vector_add(Vector *a, Vector *b, Vector *write)
{
	if(!write) write = vector_create(0,0,0);
	write->x = a->x + b-> x;
	write->y = a->y + b-> y;
	write->z = a->z + b-> z;
 	return write;
}
Пример #26
0
/* Open new pptp_connection.  Returns NULL on failure. */
PPTP_CONN * pptp_conn_open(int inet_sock, int isclient, pptp_conn_cb callback)
{
    PPTP_CONN *conn;
    /* Allocate structure */
    if ((conn = malloc(sizeof(*conn))) == NULL) return NULL;
    if ((conn->call = vector_create()) == NULL) { free(conn); return NULL; }
    /* Initialize */
    conn->inet_sock = inet_sock;
    conn->conn_state = CONN_IDLE;
    conn->ka_state  = KA_NONE;
    conn->ka_id     = 1;
    conn->call_serial_number = 0;
    conn->callback  = callback;
    /* Create I/O buffers */
    conn->read_size = conn->write_size = 0;
    conn->read_alloc = conn->write_alloc = INITIAL_BUFSIZE;
    conn->read_buffer =
        malloc(sizeof(*(conn->read_buffer)) * conn->read_alloc);
    conn->write_buffer =
        malloc(sizeof(*(conn->write_buffer)) * conn->write_alloc);
    if (conn->read_buffer == NULL || conn->write_buffer == NULL) {
        if (conn->read_buffer  != NULL) free(conn->read_buffer);
        if (conn->write_buffer != NULL) free(conn->write_buffer);
        vector_destroy(conn->call); free(conn); return NULL;
    }
    /* Make this socket non-blocking. */
    fcntl(conn->inet_sock, F_SETFL, O_NONBLOCK);
    /* Request connection from server, if this is a client */
    if (isclient) {
        struct pptp_start_ctrl_conn packet = {
            PPTP_HEADER_CTRL(PPTP_START_CTRL_CONN_RQST),
            hton16(PPTP_VERSION), 0, 0, 
            hton32(PPTP_FRAME_CAP), hton32(PPTP_BEARER_CAP),
            hton16(PPTP_MAX_CHANNELS), hton16(PPTP_FIRMWARE_VERSION), 
            PPTP_HOSTNAME, PPTP_VENDOR
        };
        /* fix this packet, if necessary */
        int idx, rc;
        idx = get_quirk_index();
        if (idx != -1 && pptp_fixups[idx].start_ctrl_conn) {
            if ((rc = pptp_fixups[idx].start_ctrl_conn(&packet)))
                warn("calling the start_ctrl_conn hook failed (%d)", rc);
        }
        if (pptp_send_ctrl_packet(conn, &packet, sizeof(packet)))
            conn->conn_state = CONN_WAIT_CTL_REPLY;
        else
            return NULL; /* could not send initial start request. */
    }
    /* Set up interval/keep-alive timer */
    /*   First, register handler for SIGALRM */
    sigpipe_create();
    sigpipe_assign(SIGALRM);
    global.conn = conn;
    /* Reset event timer */
    pptp_reset_timer();
    /* all done. */
    return conn;
}
Пример #27
0
TEST(VectorTest, CreateRelease) {
	status_t err = NO_ERROR;
	vector_handle_t vector = NULL;

	err = vector_create(1, 1, &vector);
	ASSERT_EQ(err, NO_ERROR);
	ASSERT_TRUE(vector != NULL);
	vector_release(vector);
}
Пример #28
0
void menu_create(menu *menu, int x, int y, int w, int h) {
    vector_create(&menu->objs, sizeof(component*));
    menu->x = x;
    menu->y = y;
    menu->w = w;
    menu->h = h;
    menu_background_create(&menu->sur, w, h);
    menu->selected = 0;
}
Пример #29
0
PerceptronModel create_PerceptronModel(size_t transformed_embedding_length, IntegerIndexedFeatures iif) {

    PerceptronModel model = (PerceptronModel) malloc(sizeof (struct PerceptronModel));
    check_mem(model);

    model->embedding_w = NULL;
    model->discrete_w = NULL;

    model->c = 1;

    //FeatureMatrix mat = training->feature_matrix_singleton;

    if (transformed_embedding_length > 0) {
        model->embedding_w = vector_create(transformed_embedding_length);
        model->embedding_w_avg = vector_create(transformed_embedding_length);
        model->embedding_w_temp = vector_create(transformed_embedding_length);
        model->embedding_w_best = vector_create(transformed_embedding_length);

        log_info("Embedding features of %ld dimension", model->embedding_w->n);
    } else {
        model->embedding_w = NULL;
        model->embedding_w_avg = NULL;
        model->embedding_w_temp = NULL;
    }

    /*
    if (training->disrete_patterns_parts) {
        model->discrete_w = vector_create(iif->feature_id);
        model->discrete_w_avg = vector_create(iif->feature_id);
        model->discrete_w_temp = vector_create(iif->feature_id);

        log_info("Discrete features of %ld dimension", model->discrete_w->n);
    } else {
        model->discrete_w = NULL;
        model->discrete_w_avg = NULL;
        model->discrete_w_temp = NULL;

    }
     */

    return model;
error:
    exit(1);
}
Пример #30
0
bool shadow_get_volume(d3pnt *pnt,int high,int *px,int *py,int *pz)
{
	int							n;
	float						f_dist;
	bool						hits[8];
	d3pnt						spt[8],ept[8],hpt[8],*sp,*ep;
	d3vct						ray_move;
	view_light_spot_type		*lspot;
	ray_trace_contact_type		base_contact;

		// get light and draw distance

	lspot=shadow_get_light_spot(pnt,high);
	f_dist=(float)lspot->intensity;

		// ray trace bounding box
		
	sp=spt;
	ep=ept;

	for (n=0;n!=8;n++) {
		sp->x=px[n];
		sp->y=py[n];
		sp->z=pz[n];

		vector_create(&ray_move,lspot->pnt.x,lspot->pnt.y,lspot->pnt.z,sp->x,sp->y,sp->z);
				
		ep->x=sp->x-(int)(ray_move.x*f_dist);
		ep->y=sp->y-(int)(ray_move.y*f_dist);
		ep->z=sp->z-(int)(ray_move.z*f_dist);
		
		sp++;
		ep++;
	}

	base_contact.obj.on=FALSE;
	base_contact.obj.ignore_uid=-1;

	base_contact.proj.on=FALSE;
	base_contact.proj.ignore_uid=-1;

	base_contact.hit_mode=poly_ray_trace_hit_mode_all;
	base_contact.origin=poly_ray_trace_origin_object;

	ray_trace_map_by_point_array_no_contact(8,spt,ept,hpt,hits,&base_contact);

		// set the volume

	for (n=0;n!=8;n++) {
		px[n]=hpt[n].x;
		py[n]=hpt[n].y;
		pz[n]=hpt[n].z;
	}

	return(TRUE);
}