Example #1
0
File: ics.c Project: mocidis/ics
static void on_call_state (pjsua_call_id call_id, pjsip_event *e) {
    ics_t *data;
    pjsua_call_info ci;

    PJ_UNUSED_ARG(e);

    pjsua_call_get_info(call_id, &ci);

    //Handle hold call problem
#if 0
    if ( (strcmp(ci.state_text.ptr,"CALLING") == 0) && (current_call != PJSUA_INVALID_ID) )
        _ics_hold_call(data);
#endif
    current_call = call_id;

    if (strcmp(ci.state_text.ptr,"DISCONNCTD") == 0){
        find_call();
    }

    data = (ics_t *)pjsua_acc_get_user_data(ci.acc_id);
    opool_item_t *p_item = opool_get(&data->opool);
    build_call_state_event((ics_event_t *)p_item->data, call_id,ci.state, ci.state_text.ptr, ci.remote_info.ptr);	
    ics_event_t *event = (ics_event_t *)p_item->data;

    process_event(event);

    opool_free(&data->opool, p_item);
}
Example #2
0
/**
 * \fn on_reg_started(), on_reg_state(), on_incoming_call(), on_call_state(), on_call_transfer_status(), on_call_media_state()
 * \brief cac ham callback
 */
static void on_reg_started(pjsua_acc_id acc_id, pj_bool_t renew) {
	ics_t *data;

	data = (ics_t *)pjsua_acc_get_user_data(acc_id);
	opool_item_t *p_item = opool_get(&data->opool);
	ics_event_t *event = (ics_event_t *)p_item->data;

	build_reg_start_event((ics_event_t *)p_item->data, acc_id);

	process_event(event);
	opool_free(&data->opool, p_item);
}
Example #3
0
static void on_reg_state(pjsua_acc_id acc_id, pjsua_reg_info *info) {
	ics_t *data;

	data = (ics_t *)pjsua_acc_get_user_data(acc_id);
	opool_item_t *p_item = opool_get(&data->opool);
	ics_event_t *event = (ics_event_t *)p_item->data;

	build_reg_state_event((ics_event_t *)p_item->data, acc_id,info->cbparam->expiration, info->cbparam->code, 
			info->cbparam->reason.ptr, info->cbparam->reason.slen);
	process_event(event);

	opool_free(&data->opool, p_item);
}
Example #4
0
int do_test(void *user) {
    int i;
    pj_pool_t *pool = (pj_pool_t *)user;
    opool_init(&opool, 10, strlen(s)+10, pool);
    for (i = 0; i < 100; i++) {
        opool_item_t *p_item = opool_get(&opool);
        pj_memcpy(p_item->data, s, strlen(s));
        printf("%d: %s\n", i, p_item->data);
        pj_thread_sleep(pj_rand()%100);
        opool_free(&opool, p_item);
    }
    return 0;
}
Example #5
0
File: ics.c Project: mocidis/ics
static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata) {
    PJ_UNUSED_ARG(rdata);

    ics_t *data;
    pjsua_call_info ci;


    pjsua_call_get_info(call_id, &ci);
    data = (ics_t *)pjsua_acc_get_user_data(acc_id);

    //_ics_hold_call(data);

    opool_item_t *p_item = opool_get(&data->opool);
    build_incoming_call_event((ics_event_t *)p_item->data, acc_id,call_id, ci.state, ci.remote_info.ptr, ci.local_info.ptr);	
    ics_event_t *event = (ics_event_t *)p_item->data;

    //queue_enqueue(&data->queue, (void *)p_item);
    process_event(event);

    current_call = call_id;

    opool_free(&data->opool, p_item);
}
Example #6
0
File: ics.c Project: mocidis/ics
static void on_call_media_state(pjsua_call_id call_id) {
    ics_t *data;
    pjsua_call_info ci;

    pjsua_call_get_info(call_id, &ci);

    //! Khoi tao mot connect media flow tu app nay sang app khac
    if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) {
        pjsua_conf_connect(ci.conf_slot, 0); // ntt1->quy
        pjsua_conf_connect(0, ci.conf_slot); // quy->ntt1
    }

    pjsua_call_get_info(call_id, &ci);
    data = (ics_t *)pjsua_acc_get_user_data(ci.acc_id);
    opool_item_t *p_item = opool_get(&data->opool);
    build_call_media_state_event((ics_event_t *)p_item->data, call_id, ci.media_status, ci.remote_info.ptr);	
    ics_event_t *event = (ics_event_t *)p_item->data;

    //	queue_enqueue(&data->queue, (void *)p_item);
    process_event(event);

    opool_free(&data->opool, p_item);

}
Example #7
0
File: tnfa.c Project: berkus/moto
TagValueFunction* tnfa_match(TNFA* tnfa, char* input, int anchorStart, int anchorEnd){
	Vector* reach, *reachNext, *tmp;
	TagValueFunction** reachTVFs, **reachNextTVFs, **tmpTVFs;
	int i;
	int leftmostMatchFound = 0;
	TagValueFunction* finalTVF = NULL;
	void** vd;
	TNFAMatcher m;
	
	/* Construct the matcher Object */
	m.tnfa = tnfa;
	m.pos = 0;
	m.counts = ecalloc(tnfa->laststate+1,sizeof(int));
	m.queue = ibqueue_create(tnfa->laststate+1);
	m.priorities = ecalloc(tnfa->laststate+1,sizeof(PriorityList*));
	m.tmp = tvf_create(tnfa->tagcount);
	m.tvfpool = opool_createWithExt((void*(*)(void*))tvf_create,shared_free,NULL,NULL,(void*)tnfa->tagcount,10);
	m.plistpool = opool_createWithExt((void*(*)(void*))plist_create,shared_free,NULL,NULL,(void*)tnfa->maxpath,10);
	
	reach = vec_createDefault();
	reachTVFs = ecalloc(tnfa->laststate+1,sizeof(TagValueFunction*));

	reachNext = vec_createDefault();
	reachNextTVFs = ecalloc(tnfa->laststate+1,sizeof(TagValueFunction*));

	/* Initialize reach to consistentClosure({<s,v0>}); */		
	vec_add(reach,(void*)tnfa->start);
	reachTVFs[tnfa->start] = (TagValueFunction*)opool_grab(m.tvfpool);

	reach = tnfa_close(m,reach,reachTVFs);
	
	/* If this regex matches the empty string then we may already have a possible match :P */
	if(reachTVFs[tnfa->finish]!=NULL && (!anchorEnd || (anchorEnd && !*input)) ){
		leftmostMatchFound = 1;
		finalTVF = (TagValueFunction*)opool_grab(m.tvfpool);
		tvf_copyInto(finalTVF,reachTVFs[tnfa->finish],m.tnfa->tagcount);
	}
		
	/*{int i; 
							printf("{");
		for(i=0;i<vec_size(reach);i++)
			printf("%d,",vec_get(reach,i));
		printf("}");
		printf("{");
		for(i=0;i<m.tnfa->laststate+1;i++){
			int j;int found=0;
			if(reachTVFs[i] != NULL){
				for(j=0;j<vec_size(reach);j++)
					if(vec_get(reach,j) == i) found =1;
				if(found) printf("*,"); else printf("?");
			} else { printf("_,"); }
		}
		printf("}\n");
		}	*/
		
	//printf("\nclosure(s%d) = %s",tnfa->start,match_toString(reach,tnfa));
	/* while pos < |input| */
	while(*input && vec_size(reach) > 0){
		
		/* fetch the next input symbol */
		char c = *input;
		input ++;
		m.pos++;
		
		vec_clear(reachNext);
		memset(reachNextTVFs,'\0',(tnfa->laststate+1) * sizeof(TagValueFunction*));
		

		/* For each item <q,v> in reach */
		
		for(i=vec_size(reach)-1,vd=vec_data(reach);i>=0;i--){
			TFATrans* t;
			TagValueFunction* v;
			int q = (int)vd[i];
			
			v = reachTVFs[q];
			
			/* For each transition on c out of q do */
			t = tnfa->cStates[q];
			while(t != NULL){
				/* add <t->to,v> to reachNext */
				if(t->c == c){
					
					/* WARNING: ... dangerous : I believe that with NFAs constructed
					with the thompson construction there is a 1to1 mapping between
					'from' states and 'to' states on a non-epsilon transition. If that
					were not the case then there might be two different ways to get to
					the same state from reach on c and I would need to add those seperately
					to reachNext prohibiting the use of a hash */
					 
					reachNextTVFs[t->to] = (TagValueFunction*)opool_grab(m.tvfpool);
					tvf_copyInto(reachNextTVFs[t->to],v,m.tnfa->tagcount);
					vec_add(reachNext,(void*)t->to);
				}
				t = t->next;
			}
		}
		
		/* Free reach */
		
		for(i=vec_size(reach)-1,vd=vec_data(reach);i>=0;i--)
			opool_release(m.tvfpool,reachTVFs[(int)vd[i]]);
		
		if(!anchorStart && (!leftmostMatchFound || anchorEnd)){
			if(reachNextTVFs[tnfa->start] == NULL){
				reachNextTVFs[tnfa->start] = (TagValueFunction*)opool_grab(m.tvfpool);
				tvf_initialize(reachNextTVFs[tnfa->start],tnfa->tagcount);
				vec_add(reachNext,(void*)tnfa->start);
			}
		}
		
		reachNext = tnfa_close(m,reachNext,reachNextTVFs);
		
		
		if(reachNextTVFs[tnfa->finish] != NULL){
			leftmostMatchFound = 1;
			if( (!anchorEnd && (finalTVF == NULL || reachNextTVFs[tnfa->finish][0] <= finalTVF[0])) ||
				(anchorEnd && !*input) ){
				if(finalTVF!=NULL) opool_release(m.tvfpool,finalTVF);
				finalTVF = (TagValueFunction*)opool_grab(m.tvfpool);
				tvf_copyInto(finalTVF,reachNextTVFs[tnfa->finish],m.tnfa->tagcount);
				// printf("\tFound potential match: %s\n",match_toString(reachNext,tnfa));
			}
		}
			
		//printf("\nclosure = %s",match_toString(reachNext,tnfa));
		
		// Swap reach and reachNext
		tmp = reach;
		tmpTVFs = reachTVFs;
		
		reach = reachNext;
		reachTVFs = reachNextTVFs;
		
		reachNext = tmp;
		reachNextTVFs = tmpTVFs;
	}
	
	/* Free reach */
	
	for(i=vec_size(reach)-1,vd=vec_data(reach);i>=0;i--)
		opool_release(m.tvfpool,reachTVFs[(int)vd[i]]);
			
	vec_free(reach);
	free(reachTVFs);
		
	vec_free(reachNext);
	free(reachNextTVFs);
	
	free(m.tmp);
	free(m.counts);
	free(m.priorities);
	ibqueue_free(m.queue);
	
	if(finalTVF){
		TagValueFunction* tmp = finalTVF;
		finalTVF = tvf_copyInto(tvf_create(tnfa->tagcount),finalTVF,tnfa->tagcount);
		opool_release(m.tvfpool,tmp);
	} else {
		finalTVF = tvf_create(tnfa->tagcount);
	}
	
	if(anchorEnd && *input) {
		TagValueFunction* tmp = finalTVF;
		finalTVF = tvf_create(tnfa->tagcount);
		free(tmp);
	}
	
	opool_free(m.tvfpool);
	opool_free(m.plistpool);
	
	return finalTVF;
}
Example #8
0
File: env.c Project: berkus/moto
void
moto_freeEnv(MotoEnv *env) {
    Enumeration *e;

    /* Free any outstanding frames */
    while(vec_size(env->frames) > 0) {
        moto_freeFrame(env);
    }

    /* Free all the globals */
    e = stab_getKeys(env->globals);
    while (enum_hasNext(e)) {
        char* n = (char*)enum_next(e);
        MotoVar* var = stab_get(env->globals,n);

        if(env->mode != COMPILER_MODE) {
            moto_freeVal(env,var->vs);
        } else {
            opool_release(env->valpool,var->vs);
        }
        free(var);
    }
    enum_free(e);
    stab_free(env->globals);

    /* free all cached regular expressions */
    e = stab_getKeys(env->rxcache);
    while (enum_hasNext(e)) {
        char *rx = (char *)enum_next(e);
        MDFA *mdfa = (MDFA *)stab_get(env->rxcache, rx);
        if (mdfa != NULL) {
            mdfa_free(mdfa);
        }
    }
    enum_free(e);

    /* free all remaining pointers */
    e = hset_elements(env->ptrs);
    while (enum_hasNext(e)) {
        void *ptr = enum_next(e);
        if (shared_check(ptr)) {
            free(ptr);
        }
    }
    enum_free(e);

    /* free all errors */
    e = sset_elements(env->errs);
    while (enum_hasNext(e)) {
        void *ptr = enum_next(e);
        if (shared_check(ptr)) {
            free(ptr);
        }
    }
    enum_free(e);

    /* free all scopes */
    e = stack_elements(env->scope);
    while (enum_hasNext(e)) {
        free(enum_next(e));
    }
    enum_free(e);

    /* free all cells */
    moto_freeTreeCells(env);

    /* free all class defs */
    stab_free(env->cdefs);

    /* free remainder of env struct */
    hset_free(env->ptrs);
    buf_free(env->out);
    buf_free(env->err);
    stab_free(env->types);
    vec_free(env->frames);

    ftab_free(env->ftable);

    /* Free all the stuff that got put in the mpool ... this includes
    	MotoFunctions and MotoClassDefinitions */
    mpool_free(env->mpool);

    stack_free(env->scope);
    stab_free(env->rxcache);
    //stack_free(env->callstack);
    sset_free(env->errs);
    sset_free(env->uses);
    sset_free(env->includes);
    buf_free(env->fcodebuffer);
    istack_free(env->scopeIDStack);

    htab_free(env->fdefs);
    htab_free(env->adefs);
    buf_free(env->constantPool);
    moto_freeTree(env->tree);

    opool_free(env->valpool);
    opool_free(env->bufpool);
    opool_free(env->stkpool);

    e = stab_getKeys(env->fcache);
    while (enum_hasNext(e))
        free((char *)enum_next(e));
    enum_free(e);
    stab_free(env->fcache);

    free(env);
}