示例#1
0
void
ReplicaController::tao_ft_interception_point (
  PortableInterceptor::ServerRequestInfo_ptr ri,
  CORBA::OctetSeq_out ocs)
{
  FT::FTRequestServiceContext_var ftr (
    extract_context (ri));

  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) Received request from %s with rid %i\n",
              ftr->client_id.in (),
              ftr->retention_id));

  // Check if this request is eligible for replay.

  RecordId rid (ftr->client_id.in (), ftr->retention_id);

  if (log_.contains (rid))
  {
    ACE_DEBUG ((LM_DEBUG,
                "(%P|%t) Replaying reply for %s with rid %i\n",
                ftr->client_id.in (),
                ftr->retention_id));

    CORBA::OctetSeq_var copy (log_.lookup (rid)); // make a copy

    ocs = copy._retn ();
  }

  return;
}
示例#2
0
/* Search the project file for the string 'text' */
void
i7_search_window_search_project(I7SearchWindow *self)
{
	I7_SEARCH_WINDOW_USE_PRIVATE(self, priv);
	GtkTreeIter result;
	GtkTextIter search_from, match_start, match_end;
	GtkTextBuffer *buffer = GTK_TEXT_BUFFER(i7_document_get_buffer(priv->document));
	gtk_text_buffer_get_start_iter(buffer, &search_from);

	start_spinner(self);

	while(find_no_wrap(&search_from, priv->text, TRUE,
		GTK_SOURCE_SEARCH_TEXT_ONLY | (priv->ignore_case? GTK_SOURCE_SEARCH_CASE_INSENSITIVE : 0),
		priv->algorithm, &match_start, &match_end))
	{
		while(gtk_events_pending())
			gtk_main_iteration();

		search_from = match_end;

		/* Get the line number (counted from 0) */
		guint lineno = gtk_text_iter_get_line(&match_start) + 1;

		gchar *context = extract_context(buffer, &match_start, &match_end);

		/* Make a sort string */
		gchar *sort = g_strdup_printf("%04i", lineno);
		/* Put the full path to the project in */
		GFile *file = i7_document_get_file(priv->document);

		gtk_list_store_append(priv->results, &result);
		gtk_list_store_set(priv->results, &result,
			I7_RESULT_CONTEXT_COLUMN, context,
			I7_RESULT_SORT_STRING_COLUMN, sort,
			I7_RESULT_FILE_COLUMN, file,
			I7_RESULT_RESULT_TYPE_COLUMN, I7_RESULT_TYPE_PROJECT,
			I7_RESULT_LINE_NUMBER_COLUMN, lineno,
			-1);
		g_free(context);
		g_free(sort);
		g_object_unref(file);
	}

	stop_spinner(self);
}
示例#3
0
/* Helper function: search one documentation page */
static void
search_documentation(DocText *doctext, I7SearchWindow *self)
{
	I7_SEARCH_WINDOW_USE_PRIVATE(self, priv);
	GtkTreeIter result;
	GtkTextIter search_from, match_start, match_end;
	GtkTextBuffer *buffer = GTK_TEXT_BUFFER(gtk_source_buffer_new(NULL));
	gtk_text_buffer_set_text(buffer, doctext->body, -1);
	gtk_text_buffer_get_start_iter(buffer, &search_from);

	while(find_no_wrap(&search_from, priv->text, TRUE,
		GTK_SOURCE_SEARCH_TEXT_ONLY | (priv->ignore_case? GTK_SOURCE_SEARCH_CASE_INSENSITIVE : 0),
		priv->algorithm, &match_start, &match_end))
	{
		while(gtk_events_pending())
			gtk_main_iteration();

		search_from = match_end;

		gchar *context = extract_context(buffer, &match_start, &match_end);
		gchar *location = g_strconcat(doctext->section, ": ", doctext->title, NULL);

		gtk_list_store_append(priv->results, &result);
		gtk_list_store_set(priv->results, &result,
			I7_RESULT_CONTEXT_COLUMN, context,
			I7_RESULT_SORT_STRING_COLUMN, doctext->sort,
			I7_RESULT_FILE_COLUMN, doctext->file,
			I7_RESULT_ANCHOR_COLUMN, doctext->anchor,
			I7_RESULT_RESULT_TYPE_COLUMN, doctext->is_recipebook?
				I7_RESULT_TYPE_RECIPE_BOOK : I7_RESULT_TYPE_DOCUMENTATION,
			I7_RESULT_LOCATION_COLUMN, location,
			I7_RESULT_EXAMPLE_TITLE_COLUMN, doctext->example_title,
			I7_RESULT_BACKGROUND_COLOR_COLUMN, doctext->is_recipebook?
				"#ffffe0" : "#ffffff",
			-1);
		g_free(context);
		g_free(location);
	}

	g_object_unref(buffer);
}
示例#4
0
static int check_line(genhomedircon_settings_t * s, Ustr *line)
{
	sepol_context_t *ctx_record = NULL;
	const char *ctx_str;
	int result;

	ctx_str = extract_context(line);
	if (!ctx_str)
		return STATUS_ERR;

	result = sepol_context_from_string(s->h_semanage->sepolh,
					   ctx_str, &ctx_record);
	if (result == STATUS_SUCCESS && ctx_record != NULL) {
		sepol_msg_set_callback(s->h_semanage->sepolh, NULL, NULL);
		result = sepol_context_check(s->h_semanage->sepolh,
					     s->policydb, ctx_record);
		sepol_msg_set_callback(s->h_semanage->sepolh,
				       semanage_msg_relay_handler, s->h_semanage);
		sepol_context_free(ctx_record);
	}
	return result;
}
示例#5
0
void* train_thread(void* para) {
    ThreadData *p = static_cast<ThreadData*>(para);
    const TrainPara& train_para(p->train_para);
    const Vocabulary& vocab(*(p->vocab));
    Net& net(*(p->net));
    int iter_cnt = train_para.iter_cnt;

    ifstream infile(p->file.c_str());
    if (!infile) {
        cerr << "can't open: " << p->file << endl;
        pthread_exit((void*) 1);
    }

    Model *model;
    if (train_para.type == CBOW && train_para.algo == NEG_SAMPLING) {
        model = new CBOW_NS(vocab, train_para.neg_sample_cnt, net);
    }
    else if (train_para.type == SKIP_GRAM && train_para.algo == NEG_SAMPLING) {
        model = new SkipGram_NS(vocab, train_para.neg_sample_cnt, net);
    }
    else if (train_para.type == CBOW && train_para.algo == HIER_SOFTMAX) {
        const HuffmanTree& huffman_tree(*(p->huffman_tree));
        model = new CBOW_HS(huffman_tree, net);
    }
    else if (train_para.type == SKIP_GRAM && train_para.algo == HIER_SOFTMAX) {
        const HuffmanTree& huffman_tree(*(p->huffman_tree));
        model = new SkipGram_HS(huffman_tree, net);
    }
    else {
        cerr << "unimplemented model" << endl;
        pthread_exit((void*) 1);
    }


    string line;
    uint64_t word_cnt = 0;
    uint64_t max_word_cnt = vocab.total_cnt() * iter_cnt / train_para.thread_cnt;
    uint64_t update_word_cnt = 0;
    clock_t start_time = clock();
    vector<uint64_t> sentence;
    vector<uint64_t> context;
    unsigned int seed = 37;
    real alpha0 = train_para.alpha;
    real alpha = alpha0;
    while (iter_cnt-- > 0) {
        infile.seekg(p->begin_pos);
        while (getline(infile, line)) {
            sentence.clear();
            update_word_cnt += parse_sentence(line, vocab, train_para.subsample_thres, &seed, &sentence);
            if (update_word_cnt > 10000) {
                word_cnt += 10000;
                update_word_cnt -= 10000;
                alpha = alpha0 * (1 - static_cast<double>(word_cnt) / (max_word_cnt+1));
                if (alpha < alpha0 * 0.0001) {
                    alpha = alpha0 * 0.0001;
                }

                clock_t now_time = clock();
                cerr << "alpha = " << alpha
                     << ", progress = " << static_cast<double>(word_cnt) / max_word_cnt * 100
                     << " %, words/thread/sec = " << word_cnt/ ((double)(now_time - start_time + 1)/(double)CLOCKS_PER_SEC * 1000) * train_para.thread_cnt
                     << " k" << endl;
            }
            for (size_t i = 0; i != sentence.size(); ++i) {
                context.clear();
                extract_context(sentence, i, train_para.window_size, &seed, &context);
                if (context.empty()) {
                    continue;
                }
                model->update(sentence[i], context, alpha);
            }

            if (infile.tellg() >= p->end_pos) {
                break;
            }
        }
    }
    infile.close();
    delete model;
    return NULL;
}
示例#6
0
static void
extension_search_result(GFile *parent, GFileInfo *info, gpointer unused, I7SearchWindow *self)
{
	I7_SEARCH_WINDOW_USE_PRIVATE(self, priv);
	GError *err = NULL;
	const char *basename = g_file_info_get_name(info);
	GFile *file = g_file_get_child(parent, basename);
	char *contents;
	GtkTextBuffer *buffer;
	GtkTreeIter result;
	GtkTextIter search_from, match_start, match_end;

	if(!g_file_load_contents(file, NULL, &contents, NULL, NULL, &err)) {
		char *author_display_name = file_get_display_name(parent);
		const char *ext_display_name = g_file_info_get_display_name(info);

		error_dialog_file_operation(GTK_WINDOW(self), file, err, I7_FILE_ERROR_OTHER,
		  /* TRANSLATORS: Error opening EXTENSION_NAME by AUTHOR_NAME */
		  _("Error opening extension '%s' by '%s':"), author_display_name, ext_display_name);

		g_free(author_display_name);
		g_object_unref(file);
		return;
	}

	buffer = GTK_TEXT_BUFFER(gtk_source_buffer_new(NULL));
	gtk_text_buffer_set_text(buffer, contents, -1);
	g_free(contents);

	gtk_text_buffer_get_start_iter(buffer, &search_from);

	start_spinner(self);

	while(find_no_wrap(&search_from, priv->text, TRUE,
		GTK_SOURCE_SEARCH_TEXT_ONLY | (priv->ignore_case? GTK_SOURCE_SEARCH_CASE_INSENSITIVE : 0),
		priv->algorithm, &match_start, &match_end))
	{
		unsigned lineno;
		char *sort, *context;

		while(gtk_events_pending())
			gtk_main_iteration();

		search_from = match_end;

		/* Get the line number (counted from 0) */
		lineno = gtk_text_iter_get_line(&match_start) + 1;

		context = extract_context(buffer, &match_start, &match_end);

		/* Make a sort string */
		sort = g_strdup_printf("%s %04i", basename, lineno);

		gtk_list_store_append(priv->results, &result);
		gtk_list_store_set(priv->results, &result,
			I7_RESULT_CONTEXT_COLUMN, context,
			I7_RESULT_SORT_STRING_COLUMN, sort,
			I7_RESULT_FILE_COLUMN, file,
			I7_RESULT_RESULT_TYPE_COLUMN, I7_RESULT_TYPE_EXTENSION,
			I7_RESULT_LINE_NUMBER_COLUMN, lineno,
			-1);

		g_free(context);
		g_free(sort);
	}

	stop_spinner(self);

	g_object_unref(buffer);
	g_object_unref(file);
}
示例#7
0
void
ReplicaController::send_reply (
  PortableInterceptor::ServerRequestInfo_ptr ri)
{
  FT::FTRequestServiceContext_var ftr (
    extract_context (ri));


  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) Sending reply for %s with rid %i\n",
              ftr->client_id.in (),
              ftr->retention_id));


  // Prepare reply for logging.

  CORBA::Any_var result =
    ri->result ();

  TAO_OutputCDR cdr;
  result->impl ()->marshal_value (cdr);

  Dynamic::ParameterList_var pl =
    ri->arguments ();

  CORBA::ULong len = pl->length ();

  for (CORBA::ULong index = 0; index != len ; ++index)
  {
    //@@ No chance for PARAM_OUT
    if ((*pl)[index].mode == CORBA::PARAM_INOUT)
    {
      (*pl)[index].argument.impl ()->marshal_value (cdr);
    }
  }

  CORBA::OctetSeq_var reply;

  ACE_NEW (reply.out (), CORBA::OctetSeq (cdr.total_length ()));

  reply->length (cdr.total_length ());

  CORBA::Octet* buf = reply->get_buffer ();

  // @@ What if this throws an exception??  We don't have any way to
  // check whether this succeeded
  for (ACE_Message_Block const* mb = cdr.begin ();
       mb != 0;
       mb = mb->cont ())
  {
    ACE_OS::memcpy (buf, mb->rd_ptr (), mb->length ());
    buf += mb->length ();
  }

  // Logging the reply and state update.
  //

  // First send message to members.
  //
  {
    // Extract state update.

    CORBA::OctetSeq_var oid = ri->object_id ();
    PortableInterceptor::AdapterName_var an = ri->adapter_name ();

    CORBA::Any_var state = ri->get_slot (state_slot_id ());

    CORBA::TypeCode_var tc = state->type ();

    if (tc->kind () == CORBA::tk_null)
    {
      ACE_DEBUG ((LM_DEBUG, "Slot update is void\n"));

      PortableServer::POA_var poa = resolve_poa (an.in ());

      PortableServer::ServantBase_var servant =
        poa->id_to_servant (oid.in ());

      Checkpointable* target =
        dynamic_cast<Checkpointable*> (servant.in ());

      if (target)
      {
        CORBA::Any_var tmp = target->get_state ();

        if (tmp.ptr () != 0) state = tmp._retn ();
      }
    }

    TAO_OutputCDR cdr;

    cdr << oid.in ();
    cdr << an.in ();
    cdr << ftr->client_id.in ();
    cdr << ftr->retention_id;
    cdr << reply.in ();
    cdr << state.in ();

    size_t size = cdr.total_length ();

    CORBA::OctetSeq_var msg;

    ACE_NEW (msg.out (), CORBA::OctetSeq (size));

    msg->length (size);

    {
      CORBA::Octet* buf = msg->get_buffer ();

      for (ACE_Message_Block const* mb = cdr.begin ();
           mb != 0;
           mb = mb->cont ())
      {
        ACE_OS::memcpy (buf, mb->rd_ptr (), mb->length ());
        buf += mb->length ();
      }
    }

    CORBA::Octet* buf = msg->get_buffer ();

    // Crash point 1.
    //
    if (crash_point == 1 && ftr->retention_id > 2) ACE_OS::exit (1);

    try
    {
      while (true)
      {
        try
        {
          group_->send (buf, size);
          ACE_DEBUG ((LM_DEBUG, "Sent log record of length %i\n", size));
          break;
        }
        catch (ACE_TMCast::Group::Aborted const&)
        {
          ACE_DEBUG ((LM_DEBUG, "Retrying to send log record.\n"));
        }
      }
    }
    catch (ACE_TMCast::Group::Failed const&)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Group failure. Perhaps, I am alone in the group.\n"));
    }
  }


  // Now perform local logging.
  //
  RecordId rid (ftr->client_id.in (), ftr->retention_id);

  // This is slow but eh-safe ;-).
  //
  log_.insert (rid, reply);


  // Crash point 2.
  //
  if (crash_point == 2 && ftr->retention_id > 2) ACE_OS::exit (1);
}