Exemplo n.º 1
0
/*********************************************************
*Function:    module_net_connect
*Description: js native addon for NET.connect
*Called by:   js api
*Input:       NET.connect(options),options is a object like this 
				{ addr: 'tcp://127.0.0.1:1234',	
				  onconnect: function(conn) {},	
				  ondata: function(conn, data){},
				  onclose: function(conn) {}, 
				  onerror: function(err) {}, 
				}
*Output: 0 try connect ok ,other try connect fail 
*********************************************************/
static be_jse_symbol_t* module_net_connect()
{
	be_jse_symbol_t *arg0 = NULL;
	int ret = -1;

	be_jse_handle_function(0, &arg0,NULL,NULL,NULL);
	if ( (arg0 == NULL) || !symbol_is_object(arg0) ){
		be_error(JS_NET_TAG,"module_net_connect param invalid");
		goto done;
	}

	be_jse_symbol_t* addrNetSymbol = unlock_symbol_value(lookup_named_child_symbol(get_symbol_node_id(arg0),"addr", false));
	be_jse_symbol_t* onConnNetSymbol = unlock_symbol_value(lookup_named_child_symbol(get_symbol_node_id(arg0), "onconnect", false));
	be_jse_symbol_t* onDataNetSymbol = unlock_symbol_value(lookup_named_child_symbol(get_symbol_node_id(arg0), "ondata", false));
	be_jse_symbol_t* onCloseNetSymbol = unlock_symbol_value(lookup_named_child_symbol(get_symbol_node_id(arg0), "onclose", false));
	be_jse_symbol_t* onErrorNetSymbol = unlock_symbol_value(lookup_named_child_symbol(get_symbol_node_id(arg0), "onerror", false));


	if ( addrNetSymbol == NULL || onConnNetSymbol == NULL ){
		be_error(JS_NET_TAG,"module_net_connect param invalid");
		goto done;
	}

	net_options_t *p_net_options = calloc(1,sizeof(net_options_t));
	p_net_options->addr = calloc(1,symbol_str_len(addrNetSymbol) + 1);

	if (!p_net_options || p_net_options->addr == NULL) goto done;

	/*because be_jse_async_event_cb will auto DEC_SYMBL_REF func,so need INC_SYMBL_REF before*/
	symbol_to_str(addrNetSymbol, p_net_options->addr, symbol_str_len(addrNetSymbol));
	symbol_unlock(addrNetSymbol);
	if(onConnNetSymbol && symbol_is_function(onConnNetSymbol)){  
			p_net_options->onconn_cb = (onconnect)onConnNetSymbol;
			INC_SYMBL_REF(onConnNetSymbol);
	}
	if(onDataNetSymbol && symbol_is_function(onDataNetSymbol)){  
			p_net_options->ondata_cb = (ondata)onDataNetSymbol;
			INC_SYMBL_REF(onDataNetSymbol);
	}
	if(onCloseNetSymbol && symbol_is_function(onCloseNetSymbol)){  
			p_net_options->onclose_cb = (onclose)onCloseNetSymbol;
			INC_SYMBL_REF(onCloseNetSymbol);
	}
	if(onErrorNetSymbol && symbol_is_function(onErrorNetSymbol)){ 
			p_net_options->onerror_cb = (onerror)onErrorNetSymbol;
			INC_SYMBL_REF(onErrorNetSymbol);
	}
	
	ret = be_osal_new_task("net_connect",task_net_connect_fun,p_net_options,4096,NULL);
	
	done:
	symbol_unlock(arg0);
	return new_int_symbol(ret);
}
Exemplo n.º 2
0
static be_jse_symbol_t* on()
{
    be_jse_int_t ret = -1;
    be_jse_symbol_t* arg0 = NULL;
    be_jse_symbol_t* arg1 = NULL;
    be_jse_handle_function(0, &arg0, &arg1, NULL, NULL);
    if (arg0 == NULL || arg1 == NULL || !symbol_is_string(arg0) || !symbol_is_function(arg1)) {
        ret = -1;
        symbol_unlock(arg1);
        goto end;
    }

    char name[32] = {0};
    symbol_to_str(arg0, name, symbol_str_len(arg0));

    /*
        若有多次调用on
        需要释放上一次的 on_xxx_func
    */
    if (strcmp(name, "message") == 0) {
        symbol_unlock(on_message_func);
        on_message_func = arg1;
    } else if (strcmp(name, "connect") == 0) {
        symbol_unlock(on_connect_func);
        on_connect_func = arg1;
    } else if (strcmp(name, "error") == 0) {
        symbol_unlock(on_error_func);
        on_error_func = arg1;
    }
end:
    symbol_unlock(arg0);
    return new_int_symbol(ret);
}
Exemplo n.º 3
0
static void pki_globals_callback(SYMBOL *sym, void *data)
{
  FILE *out = (FILE *) data;
  if (symbol_is_function(sym))
    return;
  fprintf(out, "L%i:\tds %i\n", symbol_address(sym), symbol_sizeof(sym));
}
Exemplo n.º 4
0
static void uart_handle(void * data){
	
	uart_module_t * module = (uart_module_t *)data;
	if(NULL == module){
		return;
	}
	uint8_t raw_buff[UART_BUFF_SIZE] = {0x00};
	uint32_t recvsize = 0;
	int8_t ret = -1;
	uint32_t i = 0;
	be_jse_symbol_t * fun_symbol = (be_jse_symbol_t*)module->fun_symbol;
	
	if(NULL == fun_symbol || !symbol_is_function(fun_symbol)){
		return;
	}
	uart_dev_t *dev = (uart_dev_t*)module->uart;
	
	ret = hal_uart_recv_II(dev, &raw_buff[0], 1,&recvsize,module->loop_time);
	if(recvsize <= 0){
		be_osal_post_delayed_action(module->loop_time,uart_handle,module);
		return;
	}
	ret = hal_uart_recv_II(dev, &raw_buff[1], UART_BUFF_SIZE-1,&recvsize,module->loop_time*2);
	if(recvsize <= 0){
		be_osal_schedule_call(uart_handle,module);
		return;
	}
#if 0  /*todo?*/
	be_jse_symbol_t * arg[2];
	be_jse_symbol_t * arr = new_symbol(BE_SYM_ARRAY);
	for (i=0; i<recvsize;++i) {
		be_jse_symbol_t *val = new_int_symbol(raw_buff[i]);
		be_jse_symbol_t *idx = new_named_symbol(new_int_symbol(i), val);
		symbol_unlock(val);
		add_symbol_node(arr, idx);
		symbol_unlock(idx);
	}
	arg[0] = arr;
	arg[1] = new_int_symbol(recvsize);
	be_jse_execute_func(bone_engine_get_executor(),fun_symbol, 2, arg);
#else
	be_jse_symbol_t * arg[1];
	for (i=0; i<recvsize+1;++i) {
		arg[0] = new_int_symbol(raw_buff[i]);
		be_jse_execute_func(bone_engine_get_executor(),fun_symbol, 1, arg);
	}
#endif
	be_osal_schedule_call(uart_handle,module);
}
Exemplo n.º 5
0
static be_jse_symbol_t * uart_watch(void){
	int32_t len = -1;
	char * data = NULL;
	int8_t ret = -1;
	int8_t result = -1;
	item_handle_t uart_handle;
	uart_handle.handle = 0xFFFFFFFF;
	be_jse_symbol_t * arg0 = NULL;
	be_jse_symbol_t * arg1 = NULL;
	uart_dev_t * uart_device = NULL;
	
	be_jse_handle_function(0,&arg0,&arg1,NULL,NULL);
	if(!arg0 || !symbol_is_int(arg0)){
		goto out;
	}
	uart_handle.handle = get_symbol_value_int(arg0);
	uart_device = board_get_node_by_handle(MODULE_UART,&uart_handle);
	if(NULL == uart_device){
		be_error("uart","board_get_node_by_handle fail!\n");
		goto out;
	}
	if(NULL != uart_get_module(uart_handle.handle)){
		be_error("uart","uart_get_module fail!\n");
		goto out;
	}	
	if(!arg1 || !symbol_is_function(arg1)){
		goto out;
	}
	ret = uart_add_recv(uart_device,uart_handle.handle,arg1);
	if(ret < 0){
		be_error("uart","uart_add_recv fail!\n");
		goto out;
	}
	result = 0;
out:

	symbol_unlock(arg0);
	if(0 != result){
		symbol_unlock(arg1);
	}
	
	return new_int_symbol(result);

}
Exemplo n.º 6
0
static void
tree_output()
{
     Symbol **symbols, *main_sym;
     size_t i, num;
     cflow_depmap_t depmap;
     
     /* Collect functions and assign them ordinal numbers */
     num = collect_functions(&symbols);
     for (i = 0; i < num; i++)
	  symbols[i]->ord = i;
     
     /* Create a dependency matrix */
     depmap = depmap_alloc(num);
     for (i = 0; i < num; i++) {
	  if (symbols[i]->callee) {
	       struct linked_list_entry *p;
	       
	       for (p = linked_list_head(symbols[i]->callee); p;
		    p = p->next) {
		    Symbol *s = (Symbol*) p->data;
		    if (symbol_is_function(s))
			 depmap_set(depmap, i, ((Symbol*)p->data)->ord);
	       }		    
	  }
     }
     
     depmap_tc(depmap);

     /* Mark recursive calls */
     for (i = 0; i < num; i++)
	  if (depmap_isset(depmap, i, i))
	       symbols[i]->recursive = 1;
     free(depmap);
     free(symbols);
     
     /* Collect and sort all symbols */
     num = collect_symbols(&symbols, is_var, 0);
     qsort(symbols, num, sizeof(*symbols), compare);
	       
     /* Produce output */
     begin();
    
     if (reverse_tree) {
	  for (i = 0; i < num; i++) {
	       inverted_tree(0, 0, symbols[i]);
	       separator();
	  }
     } else {
	  main_sym = lookup(start_name);
	  if (main_sym) {
	       direct_tree(0, 0, main_sym);
	       separator();
	  } else {
	       for (i = 0; i < num; i++) {
		    if (symbols[i]->callee == NULL)
			 continue;
		    direct_tree(0, 0, symbols[i]);
		    separator();
	       }
	  }
     }
     
     end();
     
     free(symbols);
}