Ejemplo n.º 1
0
Archivo: tube.c Proyecto: EarlGray/ling
static void tube_int(uint32_t port, void *data)
{
	outlet_t *ol = (outlet_t *)data;
	assert(ol != 0);
	tube_t *tube = ol->tube;
	assert(tube != 0);
	if (tube->accepting)
		incoming(&tube->page->tx, tube->tx_buffers, tube->evtchn_tx, ol);
	else
		incoming(&tube->page->rx, tube->rx_buffers, tube->evtchn_rx, ol);
}
Ejemplo n.º 2
0
void ZC_JR_Post_Migrate_Fn(void *data, int num_gid_entries, int num_lid_entries,
			   int num_import, ZOLTAN_ID_PTR import_glob_id, 
			   ZOLTAN_ID_PTR import_local_id, int *import_procs, 
			   int num_export, ZOLTAN_ID_PTR export_glob_id, 
			   ZOLTAN_ID_PTR export_local_id, int *export_procs,
			  int *ierr)
{
  ::ZoltanSpace::EntityListImpl outgoing(num_export), incoming(num_import) ;
  
  incoming.create_gid_list(num_import*num_gid_entries, import_glob_id) ;
  incoming.create_lid_list(num_import*num_lid_entries, import_local_id) ;
  incoming.create_proc_list(num_import, import_procs) ;

  outgoing.create_gid_list(num_export*num_gid_entries, export_glob_id) ;
  outgoing.create_lid_list(num_export*num_lid_entries, export_local_id) ;
  outgoing.create_proc_list(num_export, export_procs) ;

  incoming.addRef() ; outgoing.addRef() ;
  int res = ::ZoltanSpace::Globals::pDataMigPort->PostUnpackingProcessing( 
		      dynamic_cast< ::LoadPartitionerSpace::EntityList *> (&outgoing),	
		      dynamic_cast< ::LoadPartitionerSpace::EntityList *> (&incoming) ) ;

  *ierr = (res < 0 ) ? ZOLTAN_FATAL : ZOLTAN_OK ;

  return ;
}
Ejemplo n.º 3
0
int
main (void)
{
  struct client *bob = (struct client *) malloc (sizeof (struct client));
  bob->name = "bob";
  bob->privateKey = "key-bob";
  struct userPublicKeyPair *userPublicKeyPairRjh =
    (struct userPublicKeyPair *) malloc (sizeof (struct userPublicKeyPair));
  userPublicKeyPairRjh->user = "******";
  userPublicKeyPairRjh->publicKey = "key-rjh";
  NODE *userPublicKeyPairsBob = list_create (userPublicKeyPairRjh);
  bob->userPublicKeyPairs = userPublicKeyPairsBob;

  struct client *rjh = (struct client *) malloc (sizeof (struct client));
  rjh->name = "rjh";
  rjh->privateKey = "key-rjh";
  struct userPublicKeyPair *userPublicKeyPairBob =
    (struct userPublicKeyPair *) malloc (sizeof (struct userPublicKeyPair));
  userPublicKeyPairBob->user = "******";
  userPublicKeyPairBob->publicKey = "key-bob";
  NODE *userPublicKeyPairsRjh = list_create (userPublicKeyPairBob);
  rjh->userPublicKeyPairs = userPublicKeyPairsRjh;
  rjh->forwardReceiver = "chucknorris";

  struct email *mail = (struct email *) malloc (sizeof (struct email));
  mail->to = "rjh";
  mail->subject = "<some subject>";
  mail->body = "<some body>";

  outgoing (bob, mail);
  incoming (rjh, mail);

  return 0;
}
Ejemplo n.º 4
0
/*!
    Resumes the AT chat process after a suspension.  Any data that
    is currently in the buffer will be processed for unsolicited
    notifications.

    \sa suspend()
*/
void QAtChat::resume()
{
    if ( d->suspended ) {
        d->suspended = false;

        // Force the device to be re-opened if the binary process closed it.
        if ( !d->device->isOpen() )
            d->device->open( QIODevice::ReadWrite );

        // Reconnect the incoming() signal and process any available data.
        connect( d->device, SIGNAL(readyRead()), this, SLOT(incoming()) );
        if ( d->device->bytesAvailable() > 0 ) {
            incoming();
        }
    }
}
 bool canFinish(int numCourses, vector<pair<int,int>>& prerequisites) {
     
     unordered_map<int,vector<int> > courses;
     vector<int> incoming(numCourses,0);
     
     for(auto par:prerequisites)
     {
         courses[par.second].push_back(par.first);
         ++incoming[par.first];
     }
     
     queue<int> que;
     // those who can be visited immediately. 
     
     for(int i=0;i<numCourses;i++)
     {
         if(incoming[i]==0) que.push(i);
     }
     
     while(!que.empty())
     {
         int cur=que.front();
         que.pop();
         for(auto cor:courses[cur])
         {
             --incoming[cor];
             if(incoming[cor]==0) que.push(cor);
         }
     }
     
     for(auto cor:incoming)
     if(cor!=0) return false;
     return true;
 }
Ejemplo n.º 6
0
void*
multipart_receiver(void* arg)
{
  zmq::socket_t s(ctx, ZMQ_REP);
  s.connect(static_cast<char*>(arg));

  ZmqMessage::has_more(s); //to load libzmqmessage.so

  for (size_t i = 0; i < ITERS; ++i)
  {
    ZmqMessage::Incoming<ZmqMessage::SimpleRouting, ReqStorage> incoming(s);

    incoming.receive(ARRAY_LEN(req_parts), req_parts, true);

    StringFace s1, s2, s3;

    incoming >> s1 >> s2 >> s3;

    assert(s1 == PART1);
    assert(s2 == PART2);
    assert(s3 == PART3);

    ZmqMessage::Outgoing<ZmqMessage::SimpleRouting> outgoing(s, 0);

    outgoing << ZmqMessage::NullMessage << ZmqMessage::Flush;
  }
  return 0;
}
Ejemplo n.º 7
0
MythImage* MythPainter::GetImageFromRect(const QRect &area, int radius,
                                         int ellipse,
                                         const QBrush &fillBrush,
                                         const QPen &linePen)
{
    if (area.width() <= 0 || area.height() <= 0)
        return NULL;

    uint64_t hash1 = ((0xfff & (uint64_t)area.width())) +
                     ((0xfff & (uint64_t)area.height())     << 12) +
                     ((0xff  & (uint64_t)fillBrush.style()) << 24) +
                     ((0xff  & (uint64_t)linePen.width())   << 32) +
                     ((0xff  & (uint64_t)radius)            << 40) +
                     ((0xff  & (uint64_t)linePen.style())   << 48) +
                     ((0xff  & (uint64_t)ellipse)           << 56);
    uint64_t hash2 = ((0xffffffff & (uint64_t)linePen.color().rgba())) +
                     ((0xffffffff & (uint64_t)fillBrush.color().rgba()) << 32);

    QString incoming("R");
    if (fillBrush.style() == Qt::LinearGradientPattern && fillBrush.gradient())
    {
        const QLinearGradient *gradient = static_cast<const QLinearGradient*>(fillBrush.gradient());
        if (gradient)
        {
            incoming = QString::number(
                             ((0xfff & (uint64_t)gradient->start().x())) +
                             ((0xfff & (uint64_t)gradient->start().y()) << 12) +
                             ((0xfff & (uint64_t)gradient->finalStop().x()) << 24) +
                             ((0xfff & (uint64_t)gradient->finalStop().y()) << 36));
            QGradientStops stops = gradient->stops();
            for (int i = 0; i < stops.size(); i++)
            {
                incoming += QString::number(
                             ((0xfff * (uint64_t)(stops[i].first * 100))) +
                             ((uint64_t)stops[i].second.rgba() << 12));
            }
        }
    }

    incoming += QString::number(hash1) + QString::number(hash2);

    if (m_StringToImageMap.contains(incoming))
    {
        m_StringExpireList.remove(incoming);
        m_StringExpireList.push_back(incoming);
        return m_StringToImageMap[incoming];
    }

    MythImage *im = GetFormatImage();
    if (im)
    {
        DrawRectPriv(im, area, radius, ellipse, fillBrush, linePen);
        m_SoftwareCacheSize += (im->bytesPerLine() * im->height());
        m_StringToImageMap[incoming] = im;
        m_StringExpireList.push_back(incoming);
        ExpireImages(m_MaxSoftwareCacheSize);
    }
    return im;
}
Ejemplo n.º 8
0
void
CORBA::NVList::evaluate (void)
{
  ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);

  if (this->incoming_ != 0)
    {
#if defined (ACE_HAS_CPP11)
      std::unique_ptr<TAO_InputCDR> incoming (this->incoming_);
#else
      auto_ptr<TAO_InputCDR> incoming (this->incoming_);
#endif /* ACE_HAS_CPP11 */
      this->incoming_ = 0;

      this->_tao_decode (*(incoming.get ()), this->incoming_flag_);
    }
}
Ejemplo n.º 9
0
void pawsSkillWindow::HandleMessage( MsgEntry* me )
{
    switch ( me->GetType() )
    {
        case MSGTYPE_FACTION_INFO:
        {
            if (!train)
                HandleFactionMsg(me);
            break;
        }

        case MSGTYPE_GUISKILL:
        {
            psGUISkillMessage incoming(me);

            switch (incoming.command)
            {
                case psGUISkillMessage::SKILL_LIST:
                {
                    bool flush = (train != incoming.trainingWindow) || incoming.openWindow;
                    train = incoming.trainingWindow;
                    if (train)
                    {
                        factRequest = false;
                        factions.DeleteAll();
                        factionList->Clear();
                    }

                    skillString = "no";
                    if (!IsVisible() && incoming.openWindow)
                    {
                        Show();
                    }
                    skillString = incoming.commandData;
                    skillCache.apply(&incoming.skillCache);

                    if (IsVisible())
                        HandleSkillList(incoming.focusSkill, flush);

                    hitpointsMax = incoming.hitpointsMax;
                    manaMax = incoming.manaMax;
                    physStaminaMax = incoming.physStaminaMax;
                    menStaminaMax = incoming.menStaminaMax;

                    break;
                }

                case psGUISkillMessage::DESCRIPTION:
                {
                    HandleSkillDescription(incoming.commandData);
                    break;
                }
            }
        }
    }
}
Ejemplo n.º 10
0
	String Daemon::read_callback(const TcpConnection& conn, const String& msg)
	{
		String output;
		Message incoming(msg);
		if (incoming.Type() == MessageType::Command)
			output = execute_command(incoming).ToPacket();
		else
			output = Message(MessageType::Exception, "Illegal Message Type", incoming).ToPacket();
		return output;
	}
Ejemplo n.º 11
0
/*!
    Suspends the AT chat process from the underlying device so
    that read() and write() can be used to process binary data.
    Call resume() to restart the AT chat process after the binary data.

    \sa resume()
*/
void QAtChat::suspend()
{
    if ( !d->suspended ) {
        d->suspended = true;

        // Disconnect the incoming() signal, so that we don't accidentally
        // steal the incoming data from the other entity that wants it.
        disconnect( d->device, SIGNAL(readyRead()), this, SLOT(incoming()) );
    }
}
Ejemplo n.º 12
0
bool Request::addTarget(const BinaryString &target, bool finished)
{
	if(mPath.empty() || target.empty()) return false;

	String prefix = mPath;
	if(prefix.size() >= 2 && prefix[prefix.size()-1] == '/')
		prefix.resize(prefix.size()-1);

	mFinishedAfterTarget|= finished;

	return incoming(Network::Locator(prefix, "/", link()) , target);
}
Ejemplo n.º 13
0
std::list< std::string > LabelOps::list( const std::string regex )
{
	BACKTRACE_BEGIN
	sendLabelCommand( regex, Tongue::Opcode::LIST_LABELS );
	std::list< std::string > result;
	for ( Stream::Incoming incoming( _socket ); not incoming.done(); incoming.next() ) {
		std::string label( reinterpret_cast< const char * >( incoming.buffer() ), incoming.bufferLength() );
		result.push_back( std::move( label ) );
	}
	return std::move( result );
	BACKTRACE_END_VERBOSE( "Regex " << regex );
}
Ejemplo n.º 14
0
void Server :: readDataFromClient()
{
 if(!fileSend)
  {
   QString incoming(clientConnection->readAll());
   qDebug() << "Client:" << incoming;
   emit messageReceived(incoming);
  }
   else 
    {
     //emit dataReceived(clientConnection -> readAll()); the Server doesn't receive
    }
}
Ejemplo n.º 15
0
Archivo: NVList.cpp Proyecto: CCJY/ATCD
void
CORBA::NVList::evaluate (void)
{
  ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);

  if (this->incoming_ != 0)
    {
      auto_ptr<TAO_InputCDR> incoming (this->incoming_);
      this->incoming_ = 0;

      this->_tao_decode (*(incoming.get ()), this->incoming_flag_);
    }
}
Ejemplo n.º 16
0
void slm_machine::messageHandler(QByteArray incomingMessage, QHostAddress peerAddress)
{
    QString incoming(incomingMessage);
    QString correspondingAlias;
    if(buddies->IPBuddyList.contains(peerAddress.toString(), Qt::CaseInsensitive))
    {
        correspondingAlias = buddies->AliasBuddyList[buddies->IPBuddyList.indexOf(peerAddress.toString(),0)];
        this->clientCreation(buddies->IPBuddyList.indexOf(peerAddress.toString(),0));
        clientList[(activeClientAliasList.indexOf(buddies->AliasBuddyList[buddies->IPBuddyList.indexOf(peerAddress.toString(),0)]))]->readMessagefromBuddy(incoming,peerAddress);
    }
    else
    {
        QMessageBox::warning(this,QString("UnKnown Buddy"),QString("An unknown Buddy sent a message from IP address " + peerAddress.toString()));
    }
}
Ejemplo n.º 17
0
/// Calculate the distances for L1 and element size for each element in the
/// sample
void FlatPlateAbsorption::initialiseCachedDistances() {
  try {
    m_L1s.resize(m_numVolumeElements);
    m_elementVolumes.resize(m_numVolumeElements);
    m_elementPositions.resize(m_numVolumeElements);
  } catch (...) {
    // Typically get here if the number of volume elements is too large
    // Provide a bit more information
    g_log.error("Too many volume elements requested - try increasing the value "
                "of the ElementSize property.");
    throw;
  }

  int counter = 0;

  for (int i = 0; i < m_numZSlices; ++i) {
    const double z = (i + 0.5) * m_ZSliceThickness - 0.5 * m_slabThickness;

    for (int j = 0; j < m_numYSlices; ++j) {
      const double y = (j + 0.5) * m_YSliceThickness - 0.5 * m_slabHeight;

      for (int k = 0; k < m_numXSlices; ++k) {
        const double x = (k + 0.5) * m_XSliceThickness - 0.5 * m_slabWidth;
        // Set the current position in the sample in Cartesian coordinates.
        m_elementPositions[counter](x, y, z);
        // This should never happen for the FlatPlateAbsorption algorithm, but
        // can for the
        // inherited CuboidGaugeVolumeAbsorption algorithm if the sample has not
        // been defined
        // to fully enclose the requested cuboid
        if (!m_sampleObject->isValid(m_elementPositions[counter])) {
          throw Exception::InstrumentDefinitionError(
              "Integration element not located within sample");
        }
        // Create track for distance in sample before scattering point
        Track incoming(m_elementPositions[counter], m_beamDirection * -1.0);
        m_sampleObject->interceptSurface(incoming);
        m_L1s[counter] = incoming.cbegin()->distFromStart;

        // Also calculate element volume here
        m_elementVolumes[counter] =
            m_XSliceThickness * m_YSliceThickness * m_ZSliceThickness;

        counter++;
      }
    }
  }
}
Ejemplo n.º 18
0
void pawsBankWindow::HandleMessage( MsgEntry* me )
{
    if(me->GetType() == MSGTYPE_BANKING)
    {
        psGUIBankingMessage incoming(me);

        switch(incoming.command)
        {
        case psGUIBankingMessage::VIEWBANK:
            {
                if(!IsVisible() && incoming.openWindow) 
                {
                    Show();
                }
                // Is there a better way to do this? Enlighten me.
                csString circles;
                csString octas;
                csString hexas;
                csString trias;
                csString circlesBanked;
                csString octasBanked;
                csString hexasBanked;
                csString triasBanked;
                csString maxCircles;
                csString maxOctas;
                csString maxHexas;
                csString maxTrias;
                csString fInfo;
                circlesCanDeposit->SetText(circles.AppendFmt("%i", incoming.circles));
                octasCanDeposit->SetText(octas.AppendFmt("%i", incoming.octas));
                hexasCanDeposit->SetText(hexas.AppendFmt("%i", incoming.hexas));
                triasCanDeposit->SetText(trias.AppendFmt("%i", incoming.trias));
                circlesCanWithdraw->SetText(circlesBanked.AppendFmt("%i", incoming.circlesBanked));
                octasCanWithdraw->SetText(octasBanked.AppendFmt("%i", incoming.octasBanked));
                hexasCanWithdraw->SetText(hexasBanked.AppendFmt("%i", incoming.hexasBanked));
                triasCanWithdraw->SetText(triasBanked.AppendFmt("%i", incoming.triasBanked));
                circlesCanExchange->SetText(maxCircles.AppendFmt("%i", incoming.maxCircles));
                octasCanExchange->SetText(maxOctas.AppendFmt("%i", incoming.maxOctas));
                hexasCanExchange->SetText(maxHexas.AppendFmt("%i", incoming.maxHexas));
                triasCanExchange->SetText(maxTrias.AppendFmt("%i", incoming.maxTrias));
                feeInfo->SetText(fInfo.AppendFmt("Fee charged for your account level: %.2f%%", incoming.exchangeFee));

                guild = incoming.guild;
                break;
            }
        }
    }
}
Ejemplo n.º 19
0
void pawsPetStatWindow::HandleMessage( MsgEntry* me )
{
    psPetSkillMessage incoming(me);

    switch (incoming.command)
    {
    case psPetSkillMessage::SKILL_LIST:
    {
        skillString = "no";
//            if (!IsVisible() && incoming.openWindow)
//                Show();
        skillString = incoming.commandData;
        HandleSkillList(skillString);

        SelectSkill(incoming.focusSkill);

        hitpointsMax = incoming.hitpointsMax;
        manaMax = incoming.manaMax;
        physStaminaMax = incoming.physStaminaMax;
        menStaminaMax = incoming.menStaminaMax;


        csString text;

        text.Format(": %i", hitpointsMax);
        hpTotal->SetText(text);

        text.Format(": %i", manaMax);
        manaTotal->SetText(text);

        text.Format(": %i", physStaminaMax);
        pysStaminaTotal->SetText(text);

        text.Format(": %i", menStaminaMax);
        menStaminaTotal->SetText(text);

        break;
    }

    case psPetSkillMessage::DESCRIPTION:
    {
        HandleSkillDescription(incoming.commandData);
        break;
    }
    }
}
Ejemplo n.º 20
0
void NSClientSocket::onAccept(simpleSocket::Socket client) {
	if (!inAllowedHosts(client.getAddrString())) {
		NSC_LOG_ERROR("Unothorized access from: " + client.getAddrString());
		client.close();
		return;
	}
	simpleSocket::DataBuffer db;
	client.readAll(db);
	if (db.getLength() > 0) {
		std::string incoming(db.getBuffer(), db.getLength());
		NSC_DEBUG_MSG_STD("Incoming data: " + incoming);
		std::string response = parseRequest(incoming);
		NSC_DEBUG_MSG("Outgoing data: " + response);
		client.send(response.c_str(), static_cast<int>(response.length()), 0);
	}
	client.close();
}
Ejemplo n.º 21
0
void
GaduDCCServer::watcher() {

	gg_event* dccEvent;
	bool handled = false;

	disableNotifiers();

	dccEvent = gg_dcc_watch_fd( dccSock );
	if ( ! dccEvent ) {
		// connection is f****d
		// we should try to reenable it
//		closeDCC();
		return;
	}
	switch ( dccEvent->type ) {
		case GG_EVENT_NONE:
			break;
		case GG_EVENT_DCC_ERROR:
			kdDebug( 14100 ) << " dcc error occured " << endl;
			break;
		case GG_EVENT_DCC_NEW:
			// I do expect reciver to set this boolean to true if he handled signal
			// if so, no other reciver should be bothered with it, and I shall not close it
			// otherwise connection is closed as not handled
			emit incoming( dccEvent->event.dcc_new, handled );
			if ( !handled ) {
				if ( dccEvent->event.dcc_new->file_fd > 0) {
					close( dccEvent->event.dcc_new->file_fd );
				}
				gg_dcc_free( dccEvent->event.dcc_new );
			}
			break;
		default:
			kdDebug(14100) << "unknown/unhandled DCC EVENT: " << dccEvent->type << endl;
			break;
	}

	if ( dccEvent ) {
		gg_free_event( dccEvent );
	}

	enableNotifiers( dccSock->check );
}
Ejemplo n.º 22
0
void OdbcLog::clear()
{ QF_STACK_PUSH(OdbcLog::clear)

  std::stringstream whereClause;

  whereClause << "WHERE ";

  if( m_pSessionID )
  {
    whereClause
    << "BeginString = '" << m_pSessionID->getBeginString().getValue() << "' "
    << "AND SenderCompID = '" << m_pSessionID->getSenderCompID().getValue() << "' "
    << "AND TargetCompID = '" << m_pSessionID->getTargetCompID().getValue() << "' ";

    if( m_pSessionID->getSessionQualifier().size() )
      whereClause << "AND SessionQualifier = '" << m_pSessionID->getSessionQualifier() << "'";
  }
  else
  {
    whereClause << "BeginString = NULL AND SenderCompID = NULL && TargetCompID = NULL";
  }

  std::stringstream incomingQuery;
  std::stringstream outgoingQuery;
  std::stringstream eventQuery;

  incomingQuery 
    << "DELETE FROM " << m_incomingTable << " " << whereClause.str();
  outgoingQuery 
    << "DELETE FROM " << m_outgoingTable << " " << whereClause.str();
  eventQuery 
    << "DELETE FROM " << m_eventTable << " " << whereClause.str();

  OdbcQuery incoming( incomingQuery.str() );
  OdbcQuery outgoing( outgoingQuery.str() );
  OdbcQuery event( eventQuery.str() );
  m_pConnection->execute( incoming );
  m_pConnection->execute( outgoing );
  m_pConnection->execute( event );
  
  QF_STACK_POP
}
STDMETHODIMP nsXPCDispTestMethods::InOutsIDispatch(IDispatch * * result)
{
    if (result == NULL)
        return E_POINTER;
    CComPtr<nsIXPCDispSimple> ptr;
    ptr.CoCreateInstance(CLSID_nsXPCDispSimple);
    CComPtr<IDispatch> incoming(*result);
    CComVariant value;
    HRESULT hResult = GetProperty(incoming, L"Number", value);
    if (FAILED(hResult))
        return hResult;
    if (value.lVal != 10)
        return E_FAIL;
    hResult = ptr->put_Number(value.lVal + 5);
    if (FAILED(hResult))
        return hResult;

    *result = ptr.Detach();
    return S_OK;
}
Ejemplo n.º 24
0
QAtChat::QAtChat( QSerialIODevice *device )
    : QObject( device )
{
    d = new QAtChatPrivate( device );
    connect( d->deadTimer, SIGNAL(timeout()), this, SLOT(timeout()) );
    connect( d->retryTimer, SIGNAL(timeout()), this, SLOT(retryTimeout()) );

    // Initialize the matcher, which we use to determine what needs
    // to be done with incoming lines.
    d->matcher = new QPrefixMatcher( this );
    d->matcher->add( "OK", QPrefixMatcher::OKTerminator );
    d->matcher->add( "+CME ERROR:", QPrefixMatcher::Terminator );
    d->matcher->add( "+CMS ERROR:", QPrefixMatcher::Terminator );
    d->matcher->add( "+EXT ERROR:", QPrefixMatcher::Terminator );
    d->matcher->add( "+CMT:", QPrefixMatcher::NotificationWithPDU );
    d->matcher->add( "+CDS:", QPrefixMatcher::NotificationWithPDU );
    d->matcher->add( "+CBM:", QPrefixMatcher::NotificationWithPDU );
    d->matcher->add( "ERROR", QPrefixMatcher::Terminator );
    d->matcher->add( "CONNECT", QPrefixMatcher::TerminatorOrNotification );
    d->matcher->add( "NO CARRIER", QPrefixMatcher::TerminatorOrNotification );
    d->matcher->add( "NO ANSWER", QPrefixMatcher::TerminatorOrNotification );
    d->matcher->add( "BUSY", QPrefixMatcher::TerminatorOrNotification );
    d->matcher->add( "NO DIALTONE", QPrefixMatcher::TerminatorOrNotification );
    d->matcher->add( "VCON", QPrefixMatcher::TerminatorOrNotification );
    d->matcher->add( "AT", QPrefixMatcher::CommandEcho );

    // Work arounds for Wavecom modems.  (a) Error 515 is actually an
    // intermediate warning that can be just ignored.  (b) AT+CPIN? does
    // not always give "OK" - it sometimes stops at "+CPIN: value".
    d->matcher->add( "+CME ERROR: 515", QPrefixMatcher::Terminator ); // XXX

    // Ask the device to tell us when it is ready to read.
    connect( device, SIGNAL(readyRead()), this, SLOT(incoming()) );

    // Make sure that the device is open, ready to receive AT commands.
    if ( !device->isOpen() )
        device->open( QIODevice::ReadWrite );
}
Ejemplo n.º 25
0
glm::vec3 Phong::areaLightShade(const ShadeRec& sr)const
{
	glm::vec3 incoming(-sr.ray.getDirection());
	glm::vec3 ambient = sr.world.getAmbient()->L(sr);
	glm::vec3 color = ambientBrdf->rho(sr,incoming);
	color.x *= ambient.x;
	color.y *= ambient.y;
	color.z *= ambient.z;

	int numLights = sr.world.lights.size();

	for(int i=0;i<numLights;i++)
	{
		glm::vec3 reflected(sr.world.lights[i]->getDirection(sr));
		float nDotI = glm::dot(sr.normal,reflected);
		if(nDotI > 0.0)
		{
			bool inShadow = false;
			if(hasShadows && sr.world.lights[i]->castsShadows())
			{
				Ray shadowRay(sr.hitPoint,reflected);
				inShadow = sr.world.lights[i]->inShadow(shadowRay,sr);
			}

			if(!inShadow)
			{
				glm::vec3 gainedColor(diffuseBrdf->f(sr,incoming,reflected) + specularBrdf->f(sr,incoming,reflected));
				glm::vec3 lightColor = sr.world.lights[i]->L(sr) * nDotI;
				lightColor.x *= gainedColor.x;
				lightColor.y *= gainedColor.y;
				lightColor.z *= gainedColor.z;
				color += lightColor;
			}
		}
	}
	return color;
}
Ejemplo n.º 26
0
void
multipart_sender(zmq::socket_t& s)
{
  for (size_t i = 0; i < ITERS; ++i)
  {
    ZmqMessage::Outgoing<ZmqMessage::SimpleRouting> outgoing(s, 0);

    outgoing
      << StringFace(PART1, ARRAY_LEN(PART1)-1)
      << StringFace(PART2, ARRAY_LEN(PART2)-1)
      << StringFace(PART3, ARRAY_LEN(PART3)-1)
      << ZmqMessage::Flush;

    ZmqMessage::Incoming<ZmqMessage::SimpleRouting, ResStorage> incoming(s);

    incoming.receive(1, true);

    if (i % 1000 == 0)
    {
      std::cout << ".";
      std::cout.flush();
    }
  }
}
Ejemplo n.º 27
0
void Ball::update(Uint32 deltaTime, AngularWall * wallAngle)
{
	BasePhysics::update(deltaTime);
	updateLabels(deltaTime);

	//Detect the collision with the ground
	if ((Ypos - ballRadius) < pixelsToMeters(10))
	{
		Ypos = pixelsToMeters(10.01) + ballRadius;
		Yvel = R *- Yvel;
		Xvel *= R;
	}

	//Collision detection with the right wall
	if ((Xpos + ballRadius) > pixelsToMeters(1490))
	{
		Xpos = pixelsToMeters(1489.99) - ballRadius;
		Yvel *= R;
		Xvel = R *- Xvel;
	}

	//Collision detection with the left wall
	if ((Xpos - ballRadius) < pixelsToMeters(10))
	{
		Xpos = pixelsToMeters(10.01) + ballRadius;
		Yvel *= R;
		Xvel = R *-Xvel;
	}

	//Collision detection against angular wall
	Vector2D pos(Xpos, Ypos);
	//For each side of the wall
	for (int i = 0; i < 4; i++)
	{
		//Get the start and end points of the line that represents this edge
		Vector2D start, end;
		wallAngle->getWallPoints(i, start, end);

		//Project the ball onto this line
		Vector2D point = GetClosestPointOnLineSegment(start, end, pos);

		float dist = (point - pos).length();

		// If the closest point on the line segment is within the bounds of our radius, then we have collided with it
		if (dist <= ballRadius)
		{
			Vector2D surfaceNormal = wallAngle->getSurfaceNormal(i);

			//Push the ball out so it isn't colliding anymore
			Vector2D newpos = point + (surfaceNormal * (ballRadius + pixelsToMeters(0.01)));
			Xpos = newpos.x;
			Ypos = newpos.y;

			//Since we have collided wih the wall, we need to bounce off it
			//To do so, we reflect the ball's velocity, around the wall's edge's surfacenormal
			//This code was adapted from: http://www.3dkingdoms.com/weekly/weekly.php?a=2
			Vector2D incoming(Xvel, Yvel);

			Vector2D result = surfaceNormal * incoming.dot(surfaceNormal);
			result *= -2.f;
			result += incoming;
			result *= R;

			Xvel = result.x;
			Yvel = result.y;
		}
	}
}
Ejemplo n.º 28
0
float lwEvalEnvelope( lwEnvelope *env, float time )
{
   lwKey *key0, *key1, *skey, *ekey;
   float t, h1, h2, h3, h4, in, out, offset = 0.0f;
   int noff;


   /* if there's no key, the value is 0 */

   if ( env->nkeys == 0 ) return 0.0f;

   /* if there's only one key, the value is constant */

   if ( env->nkeys == 1 )
      return env->key->value;

   /* find the first and last keys */

   skey = ekey = env->key;
   while ( ekey->next ) ekey = ekey->next;

   /* use pre-behavior if time is before first key time */

   if ( time < skey->time ) {
      switch ( env->behavior[ 0 ] )
      {
         case BEH_RESET:
            return 0.0f;

         case BEH_CONSTANT:
            return skey->value;

         case BEH_REPEAT:
            time = range( time, skey->time, ekey->time, NULL );
            break;

         case BEH_OSCILLATE:
            time = range( time, skey->time, ekey->time, &noff );
            if ( noff % 2 )
               time = ekey->time - skey->time - time;
            break;

         case BEH_OFFSET:
            time = range( time, skey->time, ekey->time, &noff );
            offset = noff * ( ekey->value - skey->value );
            break;

         case BEH_LINEAR:
            switch ( skey->shape ) {
               case SHAPE_STEP:
                  return skey->value;
               case SHAPE_LINE:
                  return ( skey->value - skey->next->value )
                       / ( skey->time - skey->next->time )
                       * ( time - skey->next->time )
                       + skey->next->value;
               case SHAPE_TCB:
               case SHAPE_HERM:
               case SHAPE_BEZI:
                  out = outgoing( skey, (Key*)(skey->next) )
                      / ( skey->next->time - skey->time );
                  return out * ( time - skey->time ) + skey->value;
               case SHAPE_BEZ2:
                  return ( skey->param[ 1 ] - skey->param[ 3 ] )
                       / ( skey->param[ 0 ] - skey->param[ 2 ] )
                       * ( time - skey->time )
                       + skey->value;
            }
      }
   }

   /* use post-behavior if time is after last key time */

   else if ( time > ekey->time ) {
      switch ( env->behavior[ 1 ] )
      {
         case BEH_RESET:
            return 0.0f;

         case BEH_CONSTANT:
            return ekey->value;

         case BEH_REPEAT:
            time = range( time, skey->time, ekey->time, NULL );
            break;

         case BEH_OSCILLATE:
            time = range( time, skey->time, ekey->time, &noff );
            if ( noff % 2 )
               time = ekey->time - skey->time - time;
            break;

         case BEH_OFFSET:
            time = range( time, skey->time, ekey->time, &noff );
            offset = noff * ( ekey->value - skey->value );
            break;

         case BEH_LINEAR:
            switch ( ekey->shape ) {
               case SHAPE_STEP:
                  return ekey->value;
               case SHAPE_LINE:
                  return ( ekey->value - ekey->prev->value )
                       / ( ekey->time - ekey->prev->time )
                       * ( time - ekey->prev->time )
                       + ekey->prev->value;
               case SHAPE_TCB:
               case SHAPE_HERM:
               case SHAPE_BEZI:
                  in = incoming( (Key*)(ekey->prev), (Key*)ekey )
                     / ( ekey->time - ekey->prev->time );
                  return in * ( time - ekey->time ) + ekey->value;
               case SHAPE_BEZ2:
                  return ( ekey->param[ 3 ] - ekey->param[ 1 ] )
                       / ( ekey->param[ 2 ] - ekey->param[ 0 ] )
                       * ( time - ekey->time )
                       + ekey->value;
            }
      }
   }

   /* get the endpoints of the interval being evaluated */

   key0 = env->key;
   while ( time > key0->next->time )
      key0 = key0->next;
   key1 = key0->next;

   /* check for singularities first */

   if ( time == key0->time )
      return key0->value + offset;
   else if ( time == key1->time )
      return key1->value + offset;

   /* get interval length, time in [0, 1] */

   t = ( time - key0->time ) / ( key1->time - key0->time );

   /* interpolate */

   switch ( key1->shape )
   {
      case SHAPE_TCB:
      case SHAPE_BEZI:
      case SHAPE_HERM:
         out = outgoing( key0, (Key*)key1 );
         in = incoming( (Key*)key0, (Key*)key1 );
         hermite( t, &h1, &h2, &h3, &h4 );
         return h1 * key0->value + h2 * key1->value + h3 * out + h4 * in + offset;

      case SHAPE_BEZ2:
         return bez2( (Key*)key0, (Key*)key1, time ) + offset;

      case SHAPE_LINE:
         return key0->value + t * ( key1->value - key0->value ) + offset;

      case SHAPE_STEP:
         return key0->value + offset;

      default:
         return offset;
   }
}
Ejemplo n.º 29
0
glm::vec3 Dielectric::shade(const ShadeRec& sr)const
{
	glm::vec3 L;
	//glm::vec3 L = Phong::shade(sr);
	glm::vec3 reflected;
	glm::vec3 incoming(-sr.ray.getDirection());
	glm::vec3 fr = fresnelBrdf->sampleF(sr,incoming,reflected);
	Ray reflectedRay(sr.hitPoint,reflected);
	float t = 0.0f;
	glm::vec3 Lr, Lt;
	float nDotR = glm::dot(sr.normal,reflected);

	if(fresnelBtdf->tir(sr))
	{
		if(nDotR < 0.0)
		{
			//reflected ray is inside
			Lr = sr.world.getTracer()->traceRay(reflectedRay,t,sr.depth + 1);
			glm::vec3 colorFilter = glm::pow(colorFilterIn,glm::vec3(t));
			L.x += colorFilter.x * Lr.x;
			L.y += colorFilter.y * Lr.y;
			L.z += colorFilter.z * Lr.z;
		}
		else
		{
			//reflected ray is outside
			Lr = sr.world.getTracer()->traceRay(reflectedRay,t,sr.depth + 1);
			glm::vec3 colorFilter = glm::pow(colorFilterOut,glm::vec3(t));			
			L.x += colorFilter.x * Lr.x;
			L.y += colorFilter.y * Lr.y;
			L.z += colorFilter.z * Lr.z;
		}
	}
	else
	{
		//no total internal reflection
		glm::vec3 transmitted;
		glm::vec3 ft = fresnelBtdf->sampleF(sr,incoming,transmitted);
		Ray transmittedRay(sr.hitPoint,transmitted);
		float nDotT = glm::dot(sr.normal,transmitted);

		if(nDotT > 0.0)
		{
			//reflected ray is inside
			Lr = sr.world.getTracer()->traceRay(reflectedRay,t,sr.depth +1) * fabs(nDotR);
			Lr.x *= fr.x;
			Lr.y *= fr.y;
			Lr.z *= fr.z;

			glm::vec3 colorFilterR = glm::pow(colorFilterIn,glm::vec3(t));
			L.x += colorFilterR.x * Lr.x;
			L.y += colorFilterR.y * Lr.y;
			L.z += colorFilterR.z * Lr.z;

			//transmitted ray is outside
			Lt = sr.world.getTracer()->traceRay(transmittedRay,t,sr.depth +1) * fabs(nDotT);
			Lt.x *= ft.x;
			Lt.y *= ft.y;
			Lt.z *= ft.z;

			glm::vec3 colorFilterT = glm::pow(colorFilterOut, glm::vec3(t));
			L.x += colorFilterT.x * Lt.x;
			L.y += colorFilterT.y * Lt.y;
			L.z += colorFilterT.z * Lt.z;
		}
		else
		{
			//reflected ray is outisde
			Lr = sr.world.getTracer()->traceRay(reflectedRay,t,sr.depth +1) * fabs(nDotR);
			Lr.x *= fr.x;
			Lr.y *= fr.y;
			Lr.z *= fr.z;

			glm::vec3 colorFilterR = glm::pow(colorFilterOut,glm::vec3(t));
			colorFilterR.x *= Lr.x;
			colorFilterR.y *= Lr.y;
			colorFilterR.z *= Lr.z;
			L += colorFilterR;

			//transmitted ray is inside
			Lt = sr.world.getTracer()->traceRay(transmittedRay,t,sr.depth +1) * fabs(nDotT);
			Lt.x *= ft.x;
			Lt.y *= ft.y;
			Lt.z *= ft.z;

			glm::vec3 colorFilterT = glm::pow(colorFilterIn,glm::vec3(t));
			colorFilterT.x *= Lt.x;
			colorFilterT.y *= Lt.y;
			colorFilterT.z *= Lt.z;
			L += colorFilterT;
		}
	}

	return L;
}
Ejemplo n.º 30
0
double LWEnvelope::Evaluate(double Time)
{

if ( NumKeys == 0 )
	return 0.0;

if ( NumKeys == 1 )
    return Keys.begin()->value;

if(InternalCalculation)
{
   float offset=0.0;

	if (Time>EndTime)
		Time=EndTime;
	if (Time<StartTime)
		Time=StartTime;

   /* get the endpoints of the interval being evaluated */

	std::list<LWKey>::iterator key0(Keys.begin());
	std::list<LWKey>::iterator key1(Keys.begin());

   while ( Time > (*(++key1)).Time )   // Hope this construction works!
   {
      key0 = key1;
   }

   /* check for singularities first */

   if ( Time == (*key0).Time )
      return (*key0).value + offset;
   else if ( Time == (*key1).Time )
      return (*key1).value + offset;

   /* get interval length, time in [0, 1] */

   float t = ( Time - (*key0).Time ) / ( (*key1).Time - (*key0).Time );

float out=0.0;
float in=0.0;

float h1,h2,h3,h4;

   switch ( (*key1).shape )
   {
      case SHAPE_TCB:
      case SHAPE_BEZI:
      case SHAPE_HERM:
         out = outgoing( key0, key1 );
         in = incoming( key0, key1 );
         hermite( t, &h1, &h2, &h3, &h4 );
         return h1 * (*key0).value + h2 * (*key1).value + h3 * out + h4 * in + offset;

      case SHAPE_BEZ2:
         return 0.0;//bez2( key0, key1, time ) + offset;

      case SHAPE_LINE:
         return (*key0).value + t * ( (*key1).value - (*key0).value ) + offset;

      case SHAPE_STEP:
         return (*key0).value + offset;

      default:
         return offset;
   }



	double TheResult=1.0;

		return TheResult;//Lightwave3D::chaninfo->channelEvaluate(EnvChannel,Time);
}
else
	return Lightwave3D::chaninfo->channelEvaluate(EnvChannel,Time);
}