Exemple #1
0
static void _write_to_server_cb(void *pcp) {
    /* //todo: check!!!!!!!!!!!!
    if (OeSession_state_is_set(session, OENET_CLIENT_CLOSING)) {
        _cleanup(session);
        return;
    }
    */

    OE_DLOG(NULL, "OepClient._write_to_server_cb\n");
    ACContext *pc = (ACContext *) pcp;
    assert(pc);
    T _this_ = pc->proto;
    assert(_this_);
    OEK_Context *context = pc->context;
    assert(context);
    assert(context->arena);

    oe_id cid = OekMsg_get_cid(context->cmd_msg);
    _save_context(_this_, cid, pc);

    Oec_IdSet idset = OeNet_get_sessions(_this_->net);
    if (Oec_IdSet_member(idset, pc->sid)) {
        OeSession_decr_task_count(_this_->session);
        OE_DLOG(NULL, "OepClient._write_to_server_cb write_fun\n");
        _this_->write_fun(_this_->session, context->cmd_msg, context->arena);
    } else {
        OE_ERR(NULL, OEP_NO_CONN, cid);
        _send_con_closed(context);
    }
}
Exemple #2
0
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{      
    _save_context();  
 //   TCNT1H=0x00;
//	TCNT1L=0x00;  
    TCNT0=-0x4E;      
    for (_index=0;_index<_task_count;_index++)									//xu ly cac task delay(tick)
    {
    	if (_task_status[_index] & TASK_WAIT_TIME)      						//check task waiting to run 
    	{
    		if (_task_tick_count[_index]) _task_tick_count[_index]--;      		// if timeout then set task to timeout state
    		if (_task_tick_count[_index]==0) _task_status[_index] = (TASK_TIMEOUT|TASK_READY);  
    	}                  
    } 	
    
    _index = 0;
    while (1)
    {
        if (++_current_task >=_task_count) _current_task = 1;					//start finding from task 1 to task n    
        if (_task_status[_current_task] & TASK_READY) break;  					//find a READY task 
        if(++_index > _task_count)                                				 
        {	
        	_current_task = 0;
        	break;	
        }
    }        
    _restore_context();
}           
Exemple #3
0
void _task_switch(void) 
{                        
// register unsigned char _index; 
	#asm("CLI"); 
    _save_context();            
    _index = 0;     															//find a ready task
     while (1)
     {
        if (++_current_task >=_task_count) _current_task = 1;					//start finding from task 1 to task n    
        if (_task_status[_current_task] & TASK_READY) break;  					//find a READY task 
        if(++_index > _task_count)                                				//neu ko thay task nao ready thi chay task idle  
        {	
        	_current_task = 0;
        	break;	
        }
    }        
     
    _restore_context(); 
 	#asm("SEI");       
}         
Exemple #4
0
static void _buffered_on_read(OeSession session) {

    OE_TLOG(NULL, "OepClient._buffered_on_read\n");

    assert(session);
    if (OeSession_state_is_set(session, OENET_CLIENT_CLOSING)) {
        _cleanup(session);
        return;
    }
    OEK_Context *context = NULL;

    T _this_ = OeNet_get_proto(OeSession_get_net(session));
    assert(_this_);

    oe_id cid;
    int rc = _this_->peek_cid_fun(session, &cid);
    if (rc < 0) goto error;
    if (!rc) goto quit;

    ACContext *pc = _restore_context(_this_, cid);
    assert(pc);
    context = pc->context;
    assert(context);
    OE_DLOG(0, OEP_CLIENT_RESTORE_C_SUCCESS, cid);

    OekMsg msg = NULL;
    rc = _this_->read_fun(session, &msg, context->arena);
    if (rc < 0) goto error;
    if (!rc) {
        _save_context(_this_, cid, pc); //not yet
        goto quit;
    }

    OEK_MSG_TYPE mtype = OekMsg_get_type(msg);
    OE_DLOG(0, OEP_CLIENT_READ_TYPE, mtype);
    if (context->write_response_cb) {
        if (mtype == OEK_ERR) {
            context->err_msg = msg;
            context->write_response_cb(context);
        } else if (mtype == GET_RES) {
            _append_res_msg(context, msg);
            GetRes res = OekMsg_get_get_res(msg);
            if (GetRes_get_nresults(res) > Oec_AList_length(context->res_msgs)) {
                _save_context(_this_, cid, pc); //wait until you have all the responses
            } else {
                context->write_response_cb(context);
            }
        } else {
            _append_res_msg(context, msg);
            context->write_response_cb(context);
        }
    } else {
        OE_ERR(0, OEP_CLIENT_CB_NOT_SET, mtype);
    }

    //recurse thru batch of commands
    if (OeNetConn_available(OeSession_get_conn(session)) > 0 ) {
        _buffered_on_read(session);
    }

quit:
    return;

error:
    OE_ERR(-1, OEP_CLIENT_PARSE_ERROR);
    if (context) {
        OekMsg errmsg = OekMsg_new(OEK_ERR, context->arena);
        OekErr err = OekMsg_get_err(errmsg);
        OekErr_set_message(err, (oe_scalar) OEP_CLIENT_PARSE_ERROR);
        context->err_msg = errmsg;
        context->write_response_cb(context);
    }
}