Example #1
0
// FIXME: replace bool by enum : SEND_SCREEN_TO_UI
bool notify_buffer_changes(event * msg, codepoint_info_s * start_cpi, bool send_screen)
{
	bool notify = false;

	if (ui_change_flag(msg->editor_buffer_id, msg->byte_buffer_id, msg->view_id) ==  true) {
		notify = true;
	}

	if (buffer_changed_flag(msg->editor_buffer_id, msg->byte_buffer_id, msg->view_id) ==  true) {
		notify = true;
	}


	if (notify == true) {

		auto old_scr = get_last_screen(msg->view_id);
		screen_release(old_scr);
		set_last_screen(msg->view_id, nullptr);

		/* this screen will be used by next events, screen moves,  etc */
		auto last_screen = get_new_screen_by_id(msg->view_id);
		assert(last_screen);

		build_screen_layout(msg, start_cpi, last_screen);
		set_last_screen(msg->view_id, last_screen);

		if (send_screen == true) {
			auto new_screen = screen_clone(last_screen);
			send_new_layout_event_to_ui(msg, new_screen);
		}
	}

	return true;
}
Example #2
0
int
wins_wrefresh (WINDOW *win)
{
  int rc;

  if (!win || !screen_acquire ())
    return ERR;
  rc = wrefresh (win);
  screen_release ();

  return rc;
}
Example #3
0
int
wins_refresh (void)
{
  int rc;

  if (!screen_acquire ())
    return ERR;
  rc = refresh ();
  screen_release ();

  return rc;
}
Example #4
0
int
wins_doupdate (void)
{
  int rc;

  if (!screen_acquire ())
    return ERR;
  rc = doupdate ();
  screen_release ();

  return rc;
}
Example #5
0
/******************************************************************************
 * Function name - user_activity_smooth
 *
 * Description - Simulates user-activities using SMOOTH-MODE
 * Input -       *cctx_array - array of client contexts (related to a certain
 *                             batch of clients)
 * Return Code/Output - On Success - 0, on Error -1
 *******************************************************************************/
int user_activity_smooth (client_context* cctx_array)
{
        batch_context* bctx = cctx_array->bctx;

        if (!bctx)
        {
                fprintf (stderr, "%s - error: bctx is a NULL pointer.\n", __func__);
                return -1;
        }

        if (alloc_init_timer_waiting_queue (bctx->client_num_max + PERIODIC_TIMERS_NUMBER + 1,
                                            &bctx->waiting_queue) == -1)
        {
                fprintf (stderr,
                         "%s - error: failed to alloc or init timer waiting queue.\n",
                         __func__);
                return -1;
        }

        const unsigned long now_time = get_tick_count ();

        if (init_timers_and_add_initial_clients_to_load (bctx, now_time) == -1)
        {
                fprintf (stderr,
                         "%s - error: init_timers_and_add_initial_clients_to_load () failed.\n",
                         __func__);
                return -1;
        }

        if (is_batch_group_leader (bctx))
        {
                dump_snapshot_interval (bctx, now_time);
        }

        /*
           ========= Run the loading machinery ================
         */
        while ((pending_active_and_waiting_clients_num (bctx)) ||
               bctx->do_client_num_gradual_increase)
        {
                if (mget_url_smooth (bctx) == -1)
                {
                        fprintf (stderr, "%s error: mget_url () failed.\n", __func__);
                        return -1;
                }
        }

        dump_final_statistics (cctx_array);
        screen_release ();

        /*
           ======= Release resources =========================
         */
        if (bctx->waiting_queue)
        {
                /* Cancel periodic timers */
                cancel_periodic_timers (bctx);

                tq_release (bctx->waiting_queue);
                free (bctx->waiting_queue);
                bctx->waiting_queue = 0;
        }

        return 0;
}
Example #6
0
	~screen_cache()
	{
		screen_release(last_screen);
	}
Example #7
0
/****************************************************************************************
* Function name - dump_snapshot_interval_and_advance_total_statistics
*
* Description - Dumps snapshot_interval statistics for the latest loading time 
*               period and adds this statistics to the total loading counters. 
*
* Input -       *bctx    - pointer to batch context
*               now_time - current time in msec since the epoch
*
* Return Code/Output - None
****************************************************************************************/
void dump_snapshot_interval_and_advance_total_statistics (batch_context* bctx,
                                                          unsigned long now_time,
                                                          int clients_total_num)
{
  int i;
  const unsigned long delta_t = now_time - bctx->last_measure; 
  const unsigned long delta_time = delta_t ? delta_t : 1;

  if (stop_loading)
    {
      dump_final_statistics (bctx->cctx_array);
      screen_release ();

      if (create_ip_addrs (bctx, 1, 0) == -1)
      {
          fprintf (stderr, "%s - error: create_ip_addrs () remove secondary ip addresses failed. \n", __func__);
      }

      exit (1); 
    }

  fprintf(stdout,"============  loading batch is: %-10.10s ===================="
          "==================\n",
          bctx->batch_name);

  /*Collect the operational statistics*/

  for (i = 0; i <= threads_subbatches_num; i++)
    {
      if (i)
        {
          op_stat_point_add (&bctx->op_delta, &(bctx + i)->op_delta );

          /* Other threads operational statistics - reset just after collecting */
          op_stat_point_reset (&(bctx + i)->op_delta);
        }
    }

  op_stat_point_add (&bctx->op_total, &bctx->op_delta );

  print_operational_statistics (bctx->opstats_file,
                                &bctx->op_delta,
                                &bctx->op_total, 
                                bctx->url_ctx_array);


  fprintf(stdout,"--------------------------------------------------------------------------------\n");

  fprintf(stdout,"Interval stats (latest:%ld sec, clients:%d, CAPS-curr:%ld):\n",
          (unsigned long ) delta_time/1000, clients_total_num,
          bctx->op_delta.call_init_count* 1000/delta_time);

  op_stat_point_reset (&bctx->op_delta);


  for (i = 0; i <= threads_subbatches_num; i++)
    {
      if (i)
        {
          stat_point_add (&bctx->http_delta, &(bctx + i)->http_delta);
          stat_point_add (&bctx->https_delta, &(bctx + i)->https_delta);

          /* Other threads statistics - reset just after collecting */
          stat_point_reset (&(bctx + i)->http_delta); 
          stat_point_reset (&(bctx + i)->https_delta);
        }
    }

  stat_point_add (&bctx->http_total, &bctx->http_delta);
  stat_point_add (&bctx->https_total, &bctx->https_delta);

  print_snapshot_interval_statistics(delta_time, 
                                     &bctx->http_delta,  
                                     &bctx->https_delta);

  if (bctx->statistics_file)
    {
      const unsigned long timestamp_sec =  (now_time - bctx->start_time) / 1000;

      print_statistics_data_to_file (bctx->statistics_file,
                                     timestamp_sec,
                                     UNSECURE_APPL_STR,
                                     clients_total_num,
                                     &bctx->http_delta,
                                     delta_time);
    
      print_statistics_data_to_file (bctx->statistics_file, 
                                     timestamp_sec,
                                     SECURE_APPL_STR, 
                                     clients_total_num,
                                     &bctx->https_delta,
                                     delta_time);
    }

  stat_point_reset (&bctx->http_delta); 
  stat_point_reset (&bctx->https_delta);
        
  bctx->last_measure = now_time;
}
Example #8
0
bool build_screen_line_list(editor_buffer_id_t ed_buffer,
			    editor_view_id_t ed_view,
			    const u64 start_offset_, const u64 until_offset_on_screen,
			    const u32 hints,
			    const screen_dimension_t & scr_dim,
			    std::vector<std::pair<uint64_t,uint64_t>> & screen_line_list)
{
	assert(start_offset_ <= until_offset_on_screen);

	// check buffer limits
	u64 start_offset = start_offset_;
	u64 until_offset   = until_offset_on_screen;
	view_clip_offset(ed_buffer, ed_view, until_offset);

	app_log << __FUNCTION__ << " : start_offset = " << start_offset << "\n";
	app_log << __FUNCTION__ << " : until_offset = " << until_offset << "\n";

	assert(start_offset <= until_offset);

	editor_view_set_start_offset(ed_view, start_offset);

	// rewind / sync
	const u32 screen_max_cp = (scr_dim.l * scr_dim.c) * 1; // 4 is codec->max_codepoint_size(); in utf8
	u64 rewind_off = start_offset;
	if (build_screen_no_hints != 0) {
		rewind_and_resync_screen(ed_buffer, ed_view, screen_max_cp, hints, start_offset, &rewind_off);
	}

	editor_view_set_start_offset(ed_view, rewind_off);

	assert(rewind_off <= start_offset);
	assert(rewind_off <= until_offset);

	app_log << __FUNCTION__ << " : after resync rdr_begin     = " << rewind_off << "\n";
	app_log << __FUNCTION__ << " : after resync target_offset = " << until_offset << "\n";

	app_log << "    -----------------\n";

	int count = 0;
	int found = 0;
	u64 restart_offset = 0;

	codepoint_info_s start_cpi;
	start_cpi.offset = rewind_off;
	start_cpi.used   = true;

	screen_t * tmp_scr = nullptr;
	screen_alloc_with_dimension(&tmp_scr, __FUNCTION__, &scr_dim);
	codec_io_ctx_s io_ctx {
		ed_buffer,
		editor_buffer_get_byte_buffer_id(ed_buffer),
		editor_view_get_codec_id(ed_view),
		0
	};

	app_log << " Build screen line list (looking for offset("<< until_offset<<"))\n";
	do {
		app_log << " XXX Build screen list loop("<<count<<") offset(" << editor_view_get_start_offset( ed_view ) <<")\n";

		build_screen_layout(&io_ctx, ed_view, &start_cpi,tmp_scr);

		const codepoint_info_s * first_cpinfo = nullptr;

		screen_get_first_cpinfo(tmp_scr, &first_cpinfo);
		u64 first_off = first_cpinfo->offset;

		const codepoint_info_s * last_cpinfo  = nullptr;
		screen_get_last_cpinfo(tmp_scr, &last_cpinfo);

		// u64 last_off  = last_cpinfo->offset;
		// app_log <<  " screen.start off = " <<  first_off << "\n";
		// app_log <<  " target offset    = " <<  until_offset << "\n";
		// app_log <<  " screen.end_off   = " <<  last_off <<  "\n";
		// app_log <<  " nb used lines    = " <<  screen_get_number_of_used_lines(tmp_scr) <<  "\n";

		app_log <<  "   ----------------\n";

		for (size_t li = 0; li != screen_get_number_of_used_lines(tmp_scr); ++li) {
			const screen_line_t * l = nullptr;
			screen_get_line(tmp_scr, li, &l);
			size_t col_index;
			const codepoint_info_t * cpi_first = nullptr;
			const codepoint_info_t * cpi_last  = nullptr;

			screen_line_get_first_cpinfo(l, &cpi_first, &col_index);
			screen_line_get_last_cpinfo(l, &cpi_last, &col_index);

			// app_log << __FUNCTION__ << " : PUSH " << screen_line_list.size() << " " << cpi_first->offset << " , " << cpi_last->offset << "\n";
			screen_line_list.emplace_back(cpi_first->offset, cpi_last->offset);
		}

		// compute  restart offset
		const screen_line_t * l = nullptr;
		size_t scr_line_index;
		size_t scr_col_index;

		assert(until_offset >= first_off);

		found = screen_get_line_by_offset(tmp_scr, until_offset, &l, &scr_line_index, &scr_col_index); // return EQ , GT, LT ?
		if (found == 1) {
			assert(l);
			const codepoint_info_s * cpi = nullptr;

			screen_line_get_cpinfo(l, 0, &cpi, screen_line_hint_no_column_fix);
			restart_offset = cpi->offset;
			editor_view_set_start_offset(ed_view, cpi->offset);

			app_log << " found restart_offset(" << restart_offset << ") on screen count "<< count << "\n";
			app_log << " scr_line_index = "<< scr_line_index << "\n";
			app_log << " scr_col_index   = "<< scr_col_index << "\n";

			break;

		} else {
			app_log << " start offset (" << restart_offset << ") NOT FOUND\n";
		}

		if (screen_contains_offset(tmp_scr, until_offset) == true) {
			assert(0);
		}


		// set rdr_begin to first cp offset of LAST LINE of the current screen
		const codepoint_info_t * next_start_cpi = nullptr;
		bool ret = fast_page_down(ed_buffer, ed_view, tmp_scr, &next_start_cpi);
		if (ret == false) {
			// EOB
		}
		start_cpi = *next_start_cpi;

		count++;
	} while (true);

	screen_release(tmp_scr);

	return true;
}