示例#1
0
文件: main.c 项目: Vild/ImageToMap-X
void add_buffer()
{
  current_buffer = get_buffer_count();
  mdata[current_buffer] = (unsigned char *)malloc(128 * 128);
  mdata_info[current_buffer].xpos = 13371337;
  mdata_info[current_buffer].zpos = -13371337;
  mdata_info[current_buffer].scale = 3;
  mdata_info[current_buffer].dimension = 0;
}
示例#2
0
void remove_buffer(int id)
{
  if(get_buffer_count() == 1)
    return;
  free(mdata[id]);
  memmove(&(mdata[id]), &(mdata[id + 1]), BUFFER_COUNT - id - 2);
  mdata[BUFFER_COUNT - 1] = NULL;
  if(mdata[current_buffer] == NULL)
    current_buffer--;
  set_image();
}
示例#3
0
文件: find.cpp 项目: noj/CodeDB
void find(const bfs::path& cdb_path, const options& opt)
{
    config cfg = load_config(cdb_path / "config");

    const bfs::path cdb_root = cdb_path.parent_path();
    const bfs::path search_root = bfs::initial_path();

    std::size_t prefix_size = 0;
    std::string file_match;
    if(opt.m_options.count("-a") == 0 && search_root != cdb_root)
    {
        file_match = "^" + escape_regex(
            search_root.generic_string().substr(cdb_root.string().size() + 1) + "/") + ".*";
        prefix_size = search_root.string().size() - cdb_root.string().size();
    }

    file_lock lock(cdb_path / "lock");
    lock.lock_sharable();

    const char* find_regex_options =
        opt.m_options.count("-i") ? "i" : "";
    const char* file_regex_options =
        cfg.get_value("nocase-file-match") == "on" ? "i" : "";

    bool trim = cfg.get_value("find-trim-ws") == "on";
    unsigned thread_count = get_thread_count(cfg);
    unsigned buffer_count = get_buffer_count(thread_count);

    for(unsigned i = 0; i != opt.m_args.size(); ++i)
    {
        database_ptr db = open_database(cdb_path / "db");

        std::string pattern = opt.m_args[i];
        if(opt.m_options.count("-v"))
            pattern = escape_regex(pattern);

        mt_search mts(*db, trim, prefix_size, buffer_count);

        auto worker = [&]
        {
            mts.search_db(compile_regex(pattern, 0, find_regex_options),
                          compile_regex(file_match, 0, file_regex_options));
        };

        boost::thread_group workers;
        for(unsigned i = 0; i != thread_count-1; ++i)
            workers.create_thread(worker);

        worker();

        workers.join_all();
    }
}
示例#4
0
static void drop_down_menu_callback(gpointer data)
{
  if(strcmp("drop_down_menu.remove", (char *)data) == 0)
    {
      remove_buffer(drop_down_menu_id);
    }
  else if(strcmp("drop_down_menu.merge_down", (char *)data) == 0)
    {
      if(drop_down_menu_id < get_buffer_count() - 1)
	{
	  merge_buffers(mdata[drop_down_menu_id], mdata[drop_down_menu_id + 1]);
	  remove_buffer(drop_down_menu_id + 1);
	  set_image();
	}
    }
  else if(strcmp("drop_down_menu.move_up", (char *)data) == 0)
    {
      if(drop_down_menu_id > 0)
	{
	  unsigned char * tmpdata = mdata[drop_down_menu_id];
	  mdata[drop_down_menu_id] = mdata[drop_down_menu_id - 1];
	  mdata[drop_down_menu_id - 1] = tmpdata;

	  set_image();
	}
    }
  else if(strcmp("drop_down_menu.move_down", (char *)data) == 0)
    {
      if(drop_down_menu_id < get_buffer_count() - 1)
	{
	  unsigned char * tmpdata = mdata[drop_down_menu_id];
	  mdata[drop_down_menu_id] = mdata[drop_down_menu_id + 1];
	  mdata[drop_down_menu_id + 1] = tmpdata;

	  set_image();
	}
    }
}
示例#5
0
文件: main.c 项目: Vild/ImageToMap-X
void remove_buffer(int id)
{
  if(get_buffer_count() == 1)
    return;
  free(mdata[id]);
  memmove(&(mdata[id]), &(mdata[id + 1]), (BUFFER_COUNT - id - 2) * sizeof(unsigned char *));
  mdata[BUFFER_COUNT - 1] = NULL;
  if(mdata[current_buffer] == NULL)
    current_buffer--;
  
  memmove(&(mdata_info[id]), &(mdata_info[id + 1]), (BUFFER_COUNT - id - 2) * sizeof(map_data_t));
  memset(&(mdata_info[BUFFER_COUNT - 1]), 0, sizeof(map_data_t));
  set_image();
}
void ipaugenblick_main_loop()
{
    struct rte_mbuf *mbuf;
    uint8_t ports_to_poll[1] = { 0 };
    int drv_poll_interval = get_max_drv_poll_interval_in_micros(0);
    app_glue_init_poll_intervals(drv_poll_interval/(2*MAX_PKT_BURST),
                                 100 /*timer_poll_interval*/,
                                 drv_poll_interval/(10*MAX_PKT_BURST),
                                drv_poll_interval/(60*MAX_PKT_BURST));
    
    ipaugenblick_service_api_init(COMMAND_POOL_SIZE,DATA_RINGS_SIZE,DATA_RINGS_SIZE);
    TAILQ_INIT(&buffers_available_notification_socket_list_head);
    TAILQ_INIT(&ipaugenblick_clients_list_head);
    init_systick(rte_lcore_id());
    ipaugenblick_log(IPAUGENBLICK_LOG_INFO,"IPAugenblick service initialized\n");
    while(1) {
        process_commands();
	app_glue_periodic(1,ports_to_poll,1);
        while(!TAILQ_EMPTY(&buffers_available_notification_socket_list_head)) {
            if(get_buffer_count() > 0) {
                struct socket *sock = TAILQ_FIRST(&buffers_available_notification_socket_list_head);
                socket_satelite_data_t *socket_data = get_user_data(sock);
		if(socket_data->socket->type == SOCK_DGRAM)
		   	user_set_socket_tx_space(&g_ipaugenblick_sockets[socket_data->ringset_idx].tx_space,sk_stream_wspace(socket_data->socket->sk));
		//printf("%s %d %d %d %d\n",__FILE__,__LINE__,socket_data->ringset_idx,g_ipaugenblick_sockets[socket_data->ringset_idx].tx_space,sk_stream_wspace(socket_data->socket->sk));
                if(!ipaugenblick_mark_writable(socket_data)) { 
                    sock->buffers_available_notification_queue_present = 0;
                    TAILQ_REMOVE(&buffers_available_notification_socket_list_head,sock,buffers_available_notification_queue_entry); 
                }
                else {
                    break;
                }
            }
            else {
                break;
            }
        }
    }
}
示例#7
0
/*
 * This function may be called to estimate amount of data can be sent .
 * Paramters: a pointer to socket structure
 * Returns: number of bytes the application can send
 *
 */
int app_glue_calc_size_of_data_to_send(void *sock)
{
	int bufs_count1,bufs_count2,bufs_count3,stream_space,bufs_min;
	struct sock *sk = ((struct socket *)sock)->sk;
	if(!sk_stream_is_writeable(sk)) {
		return 0;
	}
	bufs_count1 = kmem_cache_get_free(get_fclone_cache());
	bufs_count2 = kmem_cache_get_free(get_header_cache());
	bufs_count3 = get_buffer_count();
	if(bufs_count1 > 2) {
		bufs_count1 -= 2;
	}
	if(bufs_count2 > 2) {
		bufs_count2 -= 2;
	}
	bufs_min = min(bufs_count1,bufs_count2);
	bufs_min = min(bufs_min,bufs_count3);
	if(bufs_min <= 0) {
		return 0;
	}
	stream_space = sk_stream_wspace(((struct socket *)sock)->sk);
	return min(bufs_min << 10,stream_space);
}
示例#8
0
void add_buffer()
{
  current_buffer = get_buffer_count();
  mdata[current_buffer] = (unsigned char *)malloc(128 * 128);
}
示例#9
0
文件: main.c 项目: Vild/ImageToMap-X
static void drop_down_menu_callback(gpointer data)
{
  if(strcmp("drop_down_menu.remove", (char *)data) == 0)
    {
      remove_buffer(drop_down_menu_id);
    }
  else if(strcmp("drop_down_menu.merge_down", (char *)data) == 0)
    {
      if(drop_down_menu_id < get_buffer_count() - 1)
	{
	  merge_buffers(mdata[drop_down_menu_id], mdata[drop_down_menu_id + 1]);
	  remove_buffer(drop_down_menu_id + 1);
	  set_image();
	}
    }
  else if(strcmp("drop_down_menu.move_up", (char *)data) == 0)
    {
      if(drop_down_menu_id > 0)
	{
	  unsigned char * tmpdata = mdata[drop_down_menu_id];
	  mdata[drop_down_menu_id] = mdata[drop_down_menu_id - 1];
	  mdata[drop_down_menu_id - 1] = tmpdata;

	  set_image();
	}
    }
  else if(strcmp("drop_down_menu.move_down", (char *)data) == 0)
    {
      if(drop_down_menu_id < get_buffer_count() - 1)
	{
	  unsigned char * tmpdata = mdata[drop_down_menu_id];
	  mdata[drop_down_menu_id] = mdata[drop_down_menu_id + 1];
	  mdata[drop_down_menu_id + 1] = tmpdata;

	  set_image();
	}
    }
  else if(strcmp("drop_down_menu.edit_map_data", (char *)data) == 0)
    {
      char buffer[256];
      GtkWidget * dialog = gtk_dialog_new_with_buttons("Edit Map Data",
						       GTK_WINDOW(window),
						       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
						       _("_OK"),
						       GTK_RESPONSE_ACCEPT,
						       _("_Cancel"),
						       GTK_RESPONSE_REJECT, NULL);


      GtkWidget * content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
      
      sprintf(buffer, "%i", mdata_info[drop_down_menu_id].scale);
      GtkWidget * scale_entry = gtk_entry_new();
      gtk_entry_set_text(GTK_ENTRY(scale_entry), buffer);
      gtk_container_add(GTK_CONTAINER(content_area), scale_entry);

      sprintf(buffer, "%i", mdata_info[drop_down_menu_id].xpos);
      GtkWidget * xpos_entry = gtk_entry_new();
      gtk_entry_set_text(GTK_ENTRY(xpos_entry), buffer);
      gtk_container_add(GTK_CONTAINER(content_area), xpos_entry);

      sprintf(buffer, "%i", mdata_info[drop_down_menu_id].zpos);
      GtkWidget * zpos_entry = gtk_entry_new();
      gtk_entry_set_text(GTK_ENTRY(zpos_entry), buffer);
      gtk_container_add(GTK_CONTAINER(content_area), zpos_entry);

      sprintf(buffer, "%i", mdata_info[drop_down_menu_id].dimension);
      GtkWidget * dimension_entry = gtk_entry_new();
      gtk_entry_set_text(GTK_ENTRY(dimension_entry), buffer);
      gtk_container_add(GTK_CONTAINER(content_area), dimension_entry);

      gtk_widget_show_all(dialog);

      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  mdata_info[drop_down_menu_id].scale = atoi((char *)gtk_entry_get_text(GTK_ENTRY(scale_entry)));
	  mdata_info[drop_down_menu_id].xpos = atoi((char *)gtk_entry_get_text(GTK_ENTRY(xpos_entry)));
	  mdata_info[drop_down_menu_id].zpos = atoi((char *)gtk_entry_get_text(GTK_ENTRY(zpos_entry)));
	  mdata_info[drop_down_menu_id].dimension = atoi((char *)gtk_entry_get_text(GTK_ENTRY(dimension_entry)));
	}
      gtk_widget_destroy(dialog);
    }
}