Exemplo n.º 1
0
/*
 * Substitutes variables if there are any
 * active subtituitons (this is the case if an existentially
 * quantified variable appears in a leaf.)
 */
CNode* UniversalInstantiator::process_eq_leaf(EqLeaf* l,map<int,int>& var_subs,
			QuantifiedLeaf* ql)
{

	Term* lhs = l->get_lhs();
	Term *new_lhs = process_term(lhs, var_subs , -1, -1, ql);
	if(new_lhs == NULL)
		return NULL;
	Term *rhs = l->get_rhs();
	Term* new_rhs = process_term(rhs, var_subs, -1, -1, ql);
	if(new_rhs == NULL)
		return NULL;

	return EqLeaf::make(new_lhs, new_rhs);

}
Exemplo n.º 2
0
void zmq::object_t::process_command (command_t &cmd_)
{
    switch (cmd_.type) {

    case command_t::revive:
        process_revive ();
        break;

    case command_t::stop:
        process_stop ();
        break;

    case command_t::plug:
        process_plug ();
        process_seqnum ();
        return;

    case command_t::own:
        process_own (cmd_.args.own.object);
        return;

    case command_t::attach:
        process_attach (cmd_.args.attach.engine);
        process_seqnum ();
        return;

    case command_t::bind:
        process_bind (cmd_.args.bind.in_pipe, cmd_.args.bind.out_pipe);
        process_seqnum ();
        return;

    case command_t::pipe_term:
        process_pipe_term ();
        return;

    case command_t::pipe_term_ack:
        process_pipe_term_ack ();
        return;

    case command_t::term_req:
        process_term_req (cmd_.args.term_req.object);
        return;

    case command_t::term:
        process_term ();
        return;

    case command_t::term_ack:
        process_term_ack ();
        return;

    default:
        zmq_assert (false);
    }
}
Exemplo n.º 3
0
void zmq::own_t::terminate ()
{
    //  If termination is already underway, there's no point
    //  in starting it anew.
    if (terminating)
        return;

    //  As for the root of the ownership tree, there's noone to terminate it,
    //  so it has to terminate itself.
    if (!owner) {
        process_term (options.linger);
        return;
    }

    //  If I am an owned object, I'll ask my owner to terminate me.
    send_term_req (owner, this);
}
Exemplo n.º 4
0
/*
 * Applies existential substitutions if any are active.
 */
CNode* UniversalInstantiator::process_ilp_leaf(ILPLeaf*l,
		map<int,int> & var_subs, QuantifiedLeaf* ql)
{
	if(var_subs.size() == 0) return l;
	map<Term*, long int >::const_iterator it = l->get_elems().begin();
	map<Term*, long int > elems;
	bool changed = false;
	for(; it != l->get_elems().end(); it++)
	{
		Term* t = it->first;
		long int c = it->second;
		Term* new_t = process_term(t, var_subs, -1, -1, ql);
		if(new_t == NULL) return NULL;

		if(new_t != t) {
			changed = true;
		}
		elems[new_t]= c;
	}
	if(!changed) return l;
	return ILPLeaf::make(l->get_operator(), elems, l->get_constant());
}
Exemplo n.º 5
0
//
// 如何处理各种Command呢?
// 一般用于不同对象之间的通信,包括cross thread的通信
// 各种相关的函数实现已经定义好
//
void zmq::object_t::process_command(command_t &cmd_) {
    switch (cmd_.type) {

        case command_t::activate_read:
            process_activate_read();
            break;

        case command_t::activate_write:
            process_activate_write(cmd_.args.activate_write.msgs_read);
            break;

        case command_t::stop:
            process_stop();
            break;

        case command_t::plug:
            process_plug();
            process_seqnum();
            break;

        case command_t::own:
            process_own(cmd_.args.own.object);
            process_seqnum();
            break;

        case command_t::attach:
            process_attach(cmd_.args.attach.engine);
            process_seqnum();
            break;

        case command_t::bind:
            process_bind(cmd_.args.bind.pipe);
            process_seqnum();
            break;

        case command_t::hiccup:
            process_hiccup(cmd_.args.hiccup.pipe);
            break;

        case command_t::pipe_term:
            process_pipe_term();
            break;

        case command_t::pipe_term_ack:
            process_pipe_term_ack();
            break;

        case command_t::term_req:
            process_term_req(cmd_.args.term_req.object);
            break;

        case command_t::term:
            process_term(cmd_.args.term.linger);
            break;

        case command_t::term_ack:
            process_term_ack();
            break;

        case command_t::reap:
            process_reap(cmd_.args.reap.socket);
            break;

        case command_t::reaped:
            process_reaped();
            break;

        case command_t::inproc_connected:
            process_seqnum();
            break;

        case command_t::done:
        default:
            zmq_assert (false);
    }
}
Exemplo n.º 6
0
void zmq::object_t::process_command (command_t &cmd_)
{
    switch (cmd_.type) {

    case command_t::revive:
        process_revive ();
        break;

    case command_t::stop:
        process_stop ();
        break;

    case command_t::plug:
        process_plug ();
        process_seqnum ();
        return;

    case command_t::own:
        process_own (cmd_.args.own.object);
        process_seqnum ();
        break;

    case command_t::attach:
        process_attach (cmd_.args.attach.engine,
            blob_t (cmd_.args.attach.peer_identity,
            cmd_.args.attach.peer_identity_size));
        process_seqnum ();
        break;

    case command_t::bind:
        process_bind (cmd_.args.bind.in_pipe, cmd_.args.bind.out_pipe,
            cmd_.args.bind.peer_identity ? blob_t (cmd_.args.bind.peer_identity,
            cmd_.args.bind.peer_identity_size) : blob_t ());
        process_seqnum ();
        break;

    case command_t::reader_info:
        process_reader_info (cmd_.args.reader_info.msgs_read);
        break;

    case command_t::pipe_term:
        process_pipe_term ();
        return;

    case command_t::pipe_term_ack:
        process_pipe_term_ack ();
        break;

    case command_t::term_req:
        process_term_req (cmd_.args.term_req.object);
        break;
    
    case command_t::term:
        process_term ();
        break;

    case command_t::term_ack:
        process_term_ack ();
        break;

    default:
        zmq_assert (false);
    }

    //  The assumption here is that each command is processed once only,
    //  so deallocating it after processing is all right.
    deallocate_command (&cmd_);
}
Exemplo n.º 7
0
void zmq::object_t::process_command (command_t &cmd_)
{
    switch (cmd_.type) {

    case command_t::activate_read:
        process_activate_read ();
        break;

    case command_t::activate_write:
        process_activate_write (cmd_.args.activate_write.msgs_read);
        break;

    case command_t::stop:
        process_stop ();
        break;

    case command_t::plug:
        process_plug ();
        process_seqnum ();
        break;

    case command_t::own:
        process_own (cmd_.args.own.object);
        process_seqnum ();
        break;

    case command_t::attach:
        process_attach (cmd_.args.attach.engine,
            cmd_.args.attach.peer_identity ?
            blob_t (cmd_.args.attach.peer_identity,
            cmd_.args.attach.peer_identity_size) : blob_t ());
        process_seqnum ();
        break;

    case command_t::bind:
        process_bind (cmd_.args.bind.pipe, cmd_.args.bind.peer_identity ?
            blob_t (cmd_.args.bind.peer_identity,
            cmd_.args.bind.peer_identity_size) : blob_t ());
        process_seqnum ();
        break;

    case command_t::hiccup:
        process_hiccup (cmd_.args.hiccup.pipe);
        break;

    case command_t::pipe_term:
        process_pipe_term ();
        break;

    case command_t::pipe_term_ack:
        process_pipe_term_ack ();
        break;

    case command_t::term_req:
        process_term_req (cmd_.args.term_req.object);
        break;
    
    case command_t::term:
        process_term (cmd_.args.term.linger);
        break;

    case command_t::term_ack:
        process_term_ack ();
        break;

    case command_t::reap:
        process_reap (cmd_.args.reap.socket);
        break;

    case command_t::reaped:
        process_reaped ();
        break;

    default:
        zmq_assert (false);
    }

    //  The assumption here is that each command is processed once only,
    //  so deallocating it after processing is all right.
    deallocate_command (&cmd_);
}
Exemplo n.º 8
0
/*
 * Substitutes variables if there are any
 * active subtituitons & byuilds the fun_arg_universal
 * and reverse_fun_arg universal maps. This is
 * recursive since we need to cdr down
 * nested function terms.
 */
Term* UniversalInstantiator::process_term(Term* t, map<int,int> & var_subs,
		int fun_id, int arg_num, QuantifiedLeaf* ql)
{
	if(t->get_term_type() == CONSTANT_TERM) return t;

	if(t->get_term_type() == VARIABLE_TERM){
		VariableTerm* vt = (VariableTerm*)t;
		int var_id = vt->get_var_id();
		if(var_subs.count(var_id)>0){
			Term* new_vt = VariableTerm::make(var_subs[var_id]);
			return new_vt;
		}
		else if(fun_id != -1 && ql!= NULL &&
				ql->get_quantified_vars().count(var_id) >0)
		{
			assert(arg_num != -1);
			qvar qv;

			//qv.orig_id = ql->get_orig_id();
			qv.id = (long int) ql;
			qv.var_id = var_id;

			map<int, int> *fun_map = NULL;
			if(fun_arg_universal.count(qv)>0) {
				fun_map = fun_arg_universal[qv];
			}
			else
			{
				fun_map = new map<int, int>();
				fun_arg_universal[qv] = fun_map;
			}
			if(fun_map->count(fun_id) == 0){
				(*fun_map)[fun_id] = arg_num;
				pair<int, int> key(fun_id, arg_num);
				set<qvar>* val = reverse_fun_arg_universal[key];
				if(val == NULL){
					val = new set<qvar>();
					reverse_fun_arg_universal[key] = val;

				}
				val->insert(qv);
			}
			else {
				if((*fun_map)[fun_id] != arg_num)
					return NULL;
			}
		}
		return t;
	}
	if(t->get_term_type() == FUNCTION_TERM)
	{
		FunctionTerm* ft = (FunctionTerm*)t;
		vector<Term*> new_args;
		for(unsigned int i=0; i < ft->get_args().size(); i++)
		{
			Term* cur_arg = process_term(ft->get_args()[i], var_subs,
					ft->get_id(), i, ql);
			if(cur_arg == NULL){
				return NULL;
			}
			new_args.push_back(cur_arg);
		}
		Term* new_ft = FunctionTerm::make(ft->get_id(), new_args,
				ft->is_invertible());
		return new_ft;
	}
	else {
		assert(t->get_term_type() == ARITHMETIC_TERM);
		ArithmeticTerm* at = (ArithmeticTerm*) t;
		bool changed = false;
		map<Term*, long int> new_elems;
		map<Term*, long int>::const_iterator it = at->get_elems().begin();
		for(; it!= at->get_elems().end(); it++){
			Term* new_t = process_term(it->first, var_subs, -1, -1, ql);
			if(new_t == NULL) return NULL;
			new_elems[new_t] = it->second;
		}
		if(!changed) return at;
		Term* new_at = ArithmeticTerm::make(new_elems, at->get_constant());
		return new_at;
	}


}