Exemple #1
0
uint32_t calc_prom(mapa_t *mapa, int col, int fil, int radio, uint32_t w, uint32_t h\
               , uint32_t (*prom)(mapa_t *, int, int, int, uint32_t, uint32_t))
{

   return (prom(mapa, col, fil, radio, w, h));

} /*Fin calc_prom*/
static int of_call_prom_ret(const char *service, int nargs, int nret,
			    unsigned int *rets, ...)
{
	int i;
	struct prom_args {
		const char *service;
		int nargs;
		int nret;
		unsigned int args[12];
	} args;
	va_list list;

	args.service = service;
	args.nargs = nargs;
	args.nret = nret;

	va_start(list, rets);
	for (i = 0; i < nargs; i++)
		args.args[i] = va_arg(list, unsigned int);
	va_end(list);

	for (i = 0; i < nret; i++)
		args.args[nargs+i] = 0;

	if (prom(&args) < 0)
		return -1;

	if (rets != (void *) 0)
		for (i = 1; i < nret; ++i)
			rets[i-1] = args.args[nargs+i];

	return (nret > 0)? args.args[nargs]: 0;
}
int of_call_prom(const char *service, int nargs, int nret, ...)
{
	int i;
	struct prom_args {
		const char *service;
		int nargs;
		int nret;
		unsigned int args[12];
	} args;
	va_list list;

	args.service = service;
	args.nargs = nargs;
	args.nret = nret;

	va_start(list, nret);
	for (i = 0; i < nargs; i++)
		args.args[i] = va_arg(list, unsigned int);
	va_end(list);

	for (i = 0; i < nret; i++)
		args.args[nargs+i] = 0;

	if (prom(&args) < 0)
		return -1;

	return (nret > 0)? args.args[nargs]: 0;
}
Exemple #4
0
  qi::Future<SignalLink> RemoteObject::metaConnect(unsigned int event, const SignalSubscriber& sub)
  {
    qi::Promise<SignalLink> prom(qi::FutureCallbackType_Sync);

    // Bind the subscriber locally.
    SignalLink uid = DynamicObject::metaConnect(event, sub);

    boost::recursive_mutex::scoped_lock _lock(_localToRemoteSignalLinkMutex);
    // maintain a map of localsignal -> remotesignal
    //(we only use one remotesignal, for many locals)
    LocalToRemoteSignalLinkMap::iterator it;
    RemoteSignalLinks& rsl = _localToRemoteSignalLink[event];
    rsl.localSignalLink.push_back(uid);

    if (rsl.remoteSignalLink == qi::SignalBase::invalidSignalLink)
    {
      /* Try to handle struct versionning.
      * Hypothesis: Everything in this address space uses the same struct
      * version. It makes sense since typesystem does not handle conflicting
      * definitions for the same type name (due to global typeid->typeinterface factory).
      *
      * So we use the very first subscriber to try to detect a version mismatch
      * between what the callback expects, and what the signal advertises.
      * If so we inform the remote end to try to convert for us.
      */
      Signature subSignature = sub.signature();
      float score = 1;
      if (subSignature.isValid())
      {
        const MetaSignal* ms = metaObject().signal(event);
        if (!ms)
          return makeFutureError<SignalLink>("Signal not found");
        score = ms->parametersSignature().isConvertibleTo(subSignature);
        qiLogDebug() << "Conversion score " << score << " " << ms->parametersSignature().toString() << " -> "
                     << subSignature.toString();
        if (!score)
        {
          std::ostringstream ss;
          ss << "Subscriber not compatible to signal signature: cannot convert " << ms->parametersSignature().toString()
             << " to " << subSignature.toString();
          return makeFutureError<SignalLink>(ss.str());
        }
      }
      rsl.remoteSignalLink = uid;
      qiLogDebug() << "connect() to " << event << " gave " << uid << " (new remote connection)";
      if (score >= 0.2)
        rsl.future = _self.async<SignalLink>("registerEvent", _service, event, uid);
      else // we might or might not be capable to convert, ask the remote end to try also
        rsl.future =
            _self.async<SignalLink>("registerEventWithSignature", _service, event, uid, subSignature.toString());
    }
    else
    {
      qiLogDebug() << "connect() to " << event << " gave " << uid << " (reusing remote connection)";
    }

    rsl.future.connect(boost::bind<void>(&onEventConnected, this, _1, prom, uid));
    return prom.future();
  }
Exemple #5
0
 fc::variant network_broadcast_api::broadcast_transaction_synchronous(const signed_transaction& trx)
 {
    promise<fc::variant>::ptr prom( new fc::promise<fc::variant>() );
    broadcast_transaction_with_callback( [=]( const fc::variant& v ){ 
       prom->set_value(v);
    }, trx );
    return future<fc::variant>(prom).wait();
 }
Exemple #6
0
 //retrieve the metaObject from the network
 qi::Future<void> RemoteObject::fetchMetaObject() {
   qiLogVerbose() << "Requesting metaobject";
   qi::Promise<void> prom(qi::FutureCallbackType_Sync);
   qi::Future<qi::MetaObject> fut =
     _self.async<qi::MetaObject>("metaObject", 0U);
   fut.connect(boost::bind<void>(&RemoteObject::onMetaObject, this, _1, prom));
   return prom.future();
 }
Exemple #7
0
static int
etherctl(Ether *e, Conn *c, char *buf)
{
	uint8_t addr[Eaddrlen];
	int t;

	deprint(2, "%s: etherctl: %s\n", argv0, buf);
	if(strncmp(buf, "connect ", 8) == 0){
		t = atoi(buf+8);
		qlock(e);
		if(typeinuse(e, t)){
			werrstr("type already in use");
			qunlock(e);
			return -1;
		}
		c->type = atoi(buf+8);
		qunlock(e);
		return 0;
	}
	if(strncmp(buf, "nonblocking", 11) == 0){
		if(buf[11] == '\n' || buf[11] == 0)
			e->nblock = 1;
		else
			e->nblock = atoi(buf + 12);
		deprint(2, "%s: nblock %d\n", argv0, e->nblock);
		return 0;
	}
	if(strncmp(buf, "promiscuous", 11) == 0){
		if(c->prom == 0)
			incref(&e->prom);
		c->prom = 1;
		return prom(e, 1);
	}
	if(strncmp(buf, "headersonly", 11) == 0){
		c->headersonly = 1;
		return 0;
	}
	if(strncmp(buf, "addmulti ", 9) == 0 || strncmp(buf, "remmulti ", 9) == 0){
		if(parseaddr(addr, buf+9) < 0){
			werrstr("bad address");
			return -1;
		}
		if(e->multicast == nil)
			return 0;
		if(strncmp(buf, "add", 3) == 0){
			e->nmcasts++;
			return e->multicast(e, addr, 1);
		}else{
			e->nmcasts--;
			return e->multicast(e, addr, 0);
		}
	}

	if(e->ctl != nil)
		return e->ctl(e, buf);
	werrstr(Ebadctl);
	return -1;
}
void CrazyhouseBoard::restorePieces(Piece piece, const QVarLengthArray<int>& squares)
{
	if (!piece.isValid() || squares.isEmpty())
		return;

	Piece prom(piece.side(), promotedPieceType(piece.type()));
	for (int i = 0; i < squares.size(); i++)
		setSquare(squares[i], prom);
}
int main()
{
    nodo *lista1;
    nodo *lista2;

    lista1 = (nodo*)malloc(sizeof(nodo*));
    lista2 = (nodo*)malloc(sizeof(nodo*));

    cargar(lista1);
    mostrar(lista1);
    //creo segunda lista
    prom(lista1, lista2);
    printf("\nMostrando lista b");
    mostrar(lista2);
    lista1 = eliminar(lista1);
    mostrar(lista1);
    return 0;
}
Exemple #10
0
TEST(TestStrand, FutureThenActorCancel)
{
  callcount = 0;
  {
    boost::shared_ptr<MyActor> obj(new MyActor);
    qi::AnyObject aobj(obj);

    qi::Promise<void> finished;

    qi::Promise<int> prom(qi::PromiseNoop<int>);
    qi::Future<int> masterFut = prom.future().thenR<int>(&MyActor::f, obj, _1, finished);
    masterFut.cancel();
    ASSERT_TRUE(prom.isCancelRequested());
    prom.setValue(0);
    ASSERT_EQ(42, masterFut.value());
    ASSERT_NO_THROW(finished.future().value());
  }
}
void CrazyhouseBoard::normalizePieces(Piece piece, QVarLengthArray<int>& squares)
{
	if (!piece.isValid())
		return;

	Piece prom(piece.side(), promotedPieceType(piece.type()));
	Piece base(piece.side(), normalPieceType(piece.type()));
	if (base == prom)
		return;

	const int size = arraySize();
	for (int i = 0; i < size; i++)
	{
		if (pieceAt(i) == prom)
		{
			squares.append(i);
			setSquare(i, base);
		}
	}
}
Exemple #12
0
int main(int argc, char *argv[]) {
    boost::asio::io_service ioService;
    std::unique_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(ioService));
    std::thread ioThread([&] () {
        ioService.run();
    });
    

    for (int i=0; i<1000; i++) {
        std::shared_ptr<std::promise<bool>> prom(new std::promise<bool>());
        std::future<bool> fut = prom->get_future();
        ioService.post([prom]() {
            prom->set_value(true);
        });

        assert(fut.get());
    }

    work.reset();
    ioThread.join();
}
Exemple #13
0
static void
fsclunk(Usbfs *fs, Fid *fid)
{
	int qt;
	int64_t qid;
	Buf *bp;
	Conn *c;
	Ether *e;

	e = fs->aux;
	qid = fid->qid.path & ~fs->qid;
	qt = qtype(qid);
	switch(qt){
	case Qndata:
	case Qnctl:
	case Qnifstats:
	case Qnstats:
	case Qntype:
		if(fid->omode != ONONE){
			c = getconn(e, qnum(qid), 0);
			if(c == nil)
				sysfatal("usb: ether: fsopen bug");
			if(decref(c) == 0){
				while((bp = nbrecvp(c->rc)) != nil)
					freebuf(e, bp);
				qlock(e);
				if(c->prom != 0)
					if(decref(&e->prom) == 0)
						prom(e, 0);
				c->prom = c->type = 0;
				qunlock(e);
			}
		}
		break;
	}
	etherdump(e);
}
Exemple #14
0
 cmt::future<datavec> connection_base::raw_call( std::string&& mid, datavec&& param ) {
   mace::cmt::promise<datavec>::ptr prom(new mace::cmt::promise<datavec>() );
   detail::pending_result::ptr pr( new detail::raw_pending_result(prom) );
   raw_call( std::move(mid), std::move(param), pr );
   return prom;
 }