void Pane_ghost_connectivity:: 
build_pconn(){

  // Determine the total node ordering
  get_node_total_order();
  
  vector< pane_i_vector > gelem_lists;
  pane_i_vector comm_sizes;
  vector<vector<map<pair<int,int>,int> > > nodes_to_send;
  vector<vector<deque<int> > > elems_to_send;

  get_ents_to_send(gelem_lists,
		   nodes_to_send,
		   elems_to_send,
		   comm_sizes);  
  
  // Communicate calculated ghost information
  vector<pane_i_vector> recv_info;  
  send_gelem_lists(gelem_lists,
			recv_info,
			comm_sizes);
  
  vector<vector<int> > elem_renumbering;
  vector<vector<map<pair<int,int>,int> > > nodes_to_recv;
  process_received_data(recv_info,
			elem_renumbering,
			nodes_to_recv);
  
  finalize_pconn( nodes_to_send,
		  nodes_to_recv,
		  elems_to_send,
		  elem_renumbering,
		  recv_info);
}
示例#2
0
//------------------------------------------------------------------------------
static void *
received_data_processing_thread_func(void * arg)
{
	railCorePlugin * plugin;
	struct wait_obj * listobj[2];
	int numobj;

	plugin = (railCorePlugin *) arg;

	plugin->thread_status = 1;
	LLOGLN(10, ("rail_core_plugin:received_data_processing_thread_func: in"));
	while (1)
	{
		listobj[0] = plugin->term_event;
		listobj[1] = plugin->data_in_event;
		numobj = 2;
		wait_obj_select(listobj, numobj, NULL, 0, 500);

		if (wait_obj_is_set(plugin->term_event))
		{
			break;
		}
		if (wait_obj_is_set(plugin->data_in_event))
		{
			wait_obj_clear(plugin->data_in_event);

			/* process data in */
			process_received_data(plugin);
		}
	}
	LLOGLN(10, ("rail_core_plugin:received_data_processing_thread_func: out"));
	plugin->thread_status = -1;
	return 0;
}
示例#3
0
static int do_transfer(struct psh_ext_if* psh_if_info,
                       void* lp_send, int send_size,
                       int* lp_is_received_data)
{
    int ret_value;
    int received_size = 0;
    u64 current_ts_ns;

    /*let's run SPI!! */
    INIT_SPI_IO_CONTEXT(&psh_if_info->send_data_list.low_spi_io_context);

    GET_TIMESTAMP_NANO(current_ts_ns);

    //dev_info(&psh_if_info->pshc->dev,"+++++++++++do_io_transaction++++++++++\n");

    ret_value = do_io_transaction(psh_if_info->pshc, 
                                  &psh_if_info->send_data_list.low_spi_io_context,
                                  lp_send, send_size,
                                  psh_if_info->psh_frame, sizeof(psh_if_info->psh_frame),
                                  &received_size);
    //dev_info(&psh_if_info->pshc->dev,"-----------do_io_transaction----------\n");

    /*
      by yy:
      below part should move to high level component...just workaround here
     */
#if 0
	if (ch == 0 && cmd->cmd_id == CMD_RESET) 
    {
        /*wait to let psh reset*/
        dev_err(&psh_if_info->pshc->dev,"Send CMD_RESET\n");
		msleep(1000);
	} 
    else if (ch == 0 && cmd->cmd_id == CMD_FW_UPDATE) 
    {
        /*wait to let psh reset*/
        dev_err(&psh_if_info->pshc->dev,"Send CMD_FW_UPDATE\n");
		msleep(1000);
	} 
#endif

    lp_is_received_data ? *lp_is_received_data = FALSE : 0;
    if (IS_SUCCESS(ret_value))
    {
        /*received something, let's check it*/
        if (0 != received_size)
        {
            process_received_data(psh_if_info,
                                  psh_if_info->psh_frame, received_size,
                                  current_ts_ns);

            lp_is_received_data ? *lp_is_received_data = TRUE : 0;
        }
    }

    return ret_value;
}
示例#4
0
/**
 * Function to process post requests.
 * @param server_struct is the main structure for the server.
 * @param connection is the connection in MHD
 * @param url is the requested url
 * @param con_cls is a pointer used to know if this is the first call or not
 * @param upload_data is a char * pointer to the data being uploaded at this call
 * @param upload_size is a pointer to an size_t value that says how many data
 *        is ti be copied from upload_data string.
 * @returns an int that is either MHD_NO or MHD_YES upon failure or not.
 */
static int process_post_request(server_struct_t *server_struct, struct MHD_Connection *connection, const char *url, void **con_cls, const char *upload_data, size_t *upload_data_size)
{
    int success = MHD_NO;
    upload_t *pp = (upload_t *) *con_cls;
    guint64 len = 0;

    /* print_debug("%ld, %s, %p\n", *upload_data_size, url, pp); */ /* This is for early debug only ! */

    if (pp == NULL)
        {
            /* print_headers(connection); */ /* Used for debugging */
            /* Initialzing the structure at first connection       */
            len = get_content_length(connection);
            pp = (upload_t *) g_malloc(sizeof(upload_t));
            pp->pos = 0;
            pp->buffer = g_malloc(sizeof(gchar) * (len + 1));  /* not using g_malloc0 here because it's 1000 times slower */
            pp->number = 0;
            *con_cls = pp;

            success = MHD_YES;
        }
    else if (*upload_data_size != 0)
        {
            /* Getting data whatever they are */
            memcpy(pp->buffer + pp->pos, upload_data, *upload_data_size);
            pp->pos = pp->pos + *upload_data_size;

            pp->number = pp->number + 1;

            *con_cls = pp;
            *upload_data_size = 0;

            success = MHD_YES;
        }
    else
        {
            /* reset when done */
            *con_cls = NULL;
            pp->buffer[pp->pos] = '\0';

            /* Do something with received_data */
            success = process_received_data(server_struct, connection, url, pp->buffer);

            free_variable(pp->buffer);
            free_variable(pp);
        }

    return success;
}
/**
* AT Command receiving thread. ( ** AT Command Server ** )
* This thread keeps calling a callback function stored
* in 'func_ptrs.read' to fetch data, accumulates these data until
* a full AT command has been received, and then call the AT decoder.
* */
DEFINE_THREAD_ROUTINE_STACK(ATcodec_Commands_Server,data,ATCODEC_STACK_SIZE)
{
  ATcodec_Tree_t *tree = &default_tree;
  AT_CODEC_ERROR_CODE res;
  int32_t v_loop, v_read, len, nb_cmd = 0;
  char buffer[INTERNAL_BUFFER_SIZE]; // user-defined
  char global_buffer[INTERNAL_BUFFER_SIZE];
  char safety[16];  // Absorbs data overflowing from global_buffer.
  int global_len=0;
	
  v_continue = 1;
  PRINT("Thread AT Commands Server Start\n");
	
  while(!atcodec_lib_init_ok)
  {
    vp_os_thread_yield();
  }
	
  while(v_continue)
  {
    vp_os_memset(buffer,0,sizeof(buffer));
    vp_os_memset(global_buffer,0,sizeof(global_buffer));global_len=0;
    vp_os_memset(safety,0,sizeof(safety));

    // open and init
		  if((res = func_ptrs.open()) != AT_CODEC_OPEN_OK){
      v_continue = 0;
    }
		
    for ( v_loop = 1 ; v_loop && func_ptrs.enable() == AT_CODEC_ENABLE_OK; )
    {
      v_read = 1;
      do
      {
        // wait so that thread can give the hand : delay user-defined / OS-dependent
        //vp_os_thread_yield();

        // -> we do a blocking read few lines after, thus
        // other threads will be able to run during the I/O

        /* In case of reading from packets, we clear the incoming buffer.
         * Splitting AT commands into several packets would be a bad idea since packet order in not guaranteed in UDP.
         */
		if (at_codec_reading_mode==ATCODEC_READ_FROM_PACKETS){
          vp_os_memset(global_buffer,0,sizeof(global_buffer));
          global_len=0;
        }

        /*
         * Read some bytes; this function blocks until some data are made
         * available by the VP_COM thread.
         */
        len = sizeof(buffer); //INTERNAL_BUFFER_SIZE/*/2*/; // user-defined
        res = func_ptrs.read((uint8_t*)&buffer[0], (int32_t*)&len);

        if(res == AT_CODEC_READ_OK)
        {
          if(len > 0)
          {
            // process characters and update v_read
            // \todo Do not use nb_cmd ?

            /* Data are accumulated in the global buffer until at least one '\r' is found. */
            if((nb_cmd = append_reception(&buffer[0], len, &global_buffer[0], &global_len,sizeof(global_buffer))) > 0)
            {
              v_read = 0;
            }
            else if(nb_cmd == -1) /* no \r found in the global_buffer*/
            {
              // a buffer overflow occurs
              switch(at_codec_reading_mode)
              {
                case ATCODEC_READ_FROM_STREAM:
                  PRINT("AT Codec buffer was filled before a full AT commands was received.");
                  break;
                case ATCODEC_READ_FROM_PACKETS:
                  PRINT("AT Codec received a packet with no complete AT command or buffer was too small to store the whole packet.");
                  break;
              }
              //ATCODEC_PRINT("Overflow\n");

              /* In case of overflow, a TCP connection should be reinitialized in order to resynchronize
               * the client and the server. Otherwise there is no way to find the beginning of the next AT Command.
               * For a UDP connection, we assume all packets begin with an AT Command, and we just wait
               * for the next packet to arrive.
               */
              if (at_codec_reading_mode==ATCODEC_READ_FROM_STREAM) { v_loop = 0; }
            }
            else
            {
              v_read = 1;
            }
          }
          else
          {
            if(len < 0)
            {
              ATCODEC_PRINT("read returns a neg length\n");
              v_loop = 0;
            }
          }
        }
        else /* if (res == AT_CODEC_READ_OK) */
        {
          // an error occurred
          ATCODEC_PRINT("an error occurs\n");
          v_loop = 0;
        }
      }
      while (v_read && v_loop);

      // process what has been received if no error occurs
      if(v_loop)
      {
        // ...
        if(process_received_data(tree, nb_cmd, &global_buffer[0], &global_len) != ATCODEC_TRUE)
        {
          ATCODEC_PRINT("process_received returns false\n");
          v_loop = 0;
        }
      }
    } /*for*/
		
    // close and un-init : user-defined
    if((res = func_ptrs.close()) != AT_CODEC_CLOSE_OK)
      v_continue = 0;

  }/* while */
	
  if ((res = func_ptrs.shutdown()) != AT_CODEC_SHUTDOWN_OK)
  {
    ATCODEC_PRINT("ATcodec Shutdown error\n");
  }
	
  return((THREAD_RET)0);
}