Ejemplo n.º 1
0
bool
PortImpl::apply_poly(Maid& maid, uint32_t poly)
{
	ThreadManager::assert_thread(THREAD_PROCESS);
	if (buffer_type() != PortType::CONTROL && buffer_type() != PortType::AUDIO)
		return false;

	if (!_prepared_buffers)
		return true;

	assert(poly == _prepared_buffers->size());

	_poly = poly;

	// Apply a new set of buffers from a preceding call to prepare_poly
	maid.push(set_buffers(_prepared_buffers));
	assert(_buffers == _prepared_buffers);
	_prepared_buffers = NULL;

	if (is_a(PortType::CONTROL))
		for (uint32_t v = 0; v < _poly; ++v)
			if (_buffers->at(v))
				boost::static_pointer_cast<AudioBuffer>(_buffers->at(v))->set_value(
						_value.get_float(), 0, 0);

	assert(_buffers->size() >= poly);
	assert(this->poly() == poly);
	assert(!_prepared_buffers);

	return true;
}
Ejemplo n.º 2
0
void
PortImpl::broadcast_value(Context& context, bool force)
{
	Raul::Atom val;
	switch (buffer_type().symbol()) {
	case PortType::UNKNOWN:
		break;
	case PortType::AUDIO:
	case PortType::CONTROL:
		val = ((AudioBuffer*)buffer(0).get())->value_at(0);
		break;
	case PortType::EVENTS:
		if (((EventBuffer*)buffer(0).get())->event_count() > 0) {
			const Events::SendPortActivity ev(context.engine(), context.start(), this);
			context.event_sink().write(sizeof(ev), &ev);
		}
		break;
	case PortType::VALUE:
	case PortType::MESSAGE:
		Ingen::Shared::LV2Atom::to_atom(_bufs.uris(), ((ObjectBuffer*)buffer(0).get())->atom(), val);
		break;
	}

	if (val.is_valid() && (force || val != _last_broadcasted_value)) {
		_last_broadcasted_value = val;
		const Events::SendPortValue ev(context.engine(), context.start(), this, true, 0, val);
		context.event_sink().write(sizeof(ev), &ev);
	}
}
Ejemplo n.º 3
0
BigInt::reference BigInt::operator*= ( const_reference o )
{
    if ( o.buffer.size() == 1 )
        return multiply_by_digit ( o.buffer[0] );

    sign_ = sign_ != o.sign_;

    std::queue<BigInt> partial;

    for ( unsigned i = 0; i < o.buffer.size(); i++ )
    {
        BigInt copy = *this;
        copy.multiply_by_digit ( o.buffer[i] );
        partial.push ( copy );
    }

    BigInt temp;
    *this = zero;
    for( unsigned i = 0; !partial.empty(); i++ )
    {
        temp = partial.front();
        partial.pop();
        temp.buffer = buffer_type(i,0) + temp.buffer;
        *this += temp;
    }
    return normalize();
}
Ejemplo n.º 4
0
 boost::shared_ptr<parcel_buffer_type> get_buffer(parcel const & p = parcel(), std::size_t arg_size = 0)
 {
     if(!buffer_ || (buffer_ && !buffer_->parcels_decoded_))
     {
         buffer_ = boost::make_shared<parcel_buffer_type>(buffer_type());
     }
     buffer_->data_.reset();
     return buffer_;
 }
Ejemplo n.º 5
0
bool
PortImpl::prepare_poly(BufferFactory& bufs, uint32_t poly)
{
	ThreadManager::assert_thread(THREAD_PRE_PROCESS);
	if (buffer_type() != PortType::CONTROL && buffer_type() != PortType::AUDIO)
		return false;

	if (_poly == poly)
		return true;

	if (_prepared_buffers && _prepared_buffers->size() != poly) {
		delete _prepared_buffers;
		_prepared_buffers = NULL;
	}

	if (!_prepared_buffers)
		_prepared_buffers = new Array<BufferFactory::Ref>(poly, *_buffers, NULL);

	return true;
}
Ejemplo n.º 6
0
void
TransportSendBuffer::insert(SequenceNumber sequence, const buffer_type& value)
{

  // Age off oldest sample if we are at capacity:
  if (this->buffers_.size() == this->capacity_) {
    BufferMap::iterator it(this->buffers_.begin());
    if (it == this->buffers_.end()) return;

    if ( OpenDDS::DCPS::Transport_debug_level >= 10) {
      ACE_DEBUG((LM_DEBUG,
        ACE_TEXT("(%P|%t) TransportSendBuffer::insert() - ")
        ACE_TEXT("aging off PDU: 0x%x as buffer(0x%x,0x%x)\n"),
        it->first.getValue(),
        it->second.first, it->second.second
      ));
    }

    release(it->second);
    this->buffers_.erase(it);
  }

  std::pair<BufferMap::iterator, bool> pair =
    this->buffers_.insert(BufferMap::value_type(sequence, buffer_type()));
  if (pair.first == this->buffers_.end()) return;

  buffer_type& buffer(pair.first->second);

  // Copy sample's TransportQueueElements:
  TransportSendStrategy::QueueType*& elems = buffer.first;
  ACE_NEW(elems, TransportSendStrategy::QueueType(value.first->size(), 1));

  CopyChainVisitor visitor(*elems,
                           &this->retained_allocator_,
                           &this->retained_mb_allocator_,
                           &this->retained_db_allocator_);
  value.first->accept_visitor(visitor);

  // Copy sample's message/data block descriptors:
  ACE_Message_Block*& data = buffer.second;
  data = TransportQueueElement::clone(value.second,
                                      &this->retained_mb_allocator_,
                                      &this->retained_db_allocator_);

  if ( OpenDDS::DCPS::Transport_debug_level >= 10) {
    ACE_DEBUG((LM_DEBUG,
      ACE_TEXT("(%P|%t) TransportSendBuffer::insert() - ")
      ACE_TEXT("saved PDU: 0x%x as buffer(0x%x,0x%x)\n"),
      sequence.getValue(),
      buffer.first, buffer.second
    ));
  }
}
Ejemplo n.º 7
0
buffer_type create(const type::supplier<device::device_type> &device, VkBufferCreateFlags flags, VkDeviceSize size,
		VkBufferUsageFlags usage, VkSharingMode sharingMode, const std::vector<uint32_t> &queueFamilyIndices) {
	VkBufferCreateInfo create = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, NULL};
	create.flags = flags;
	create.size = size;
	create.usage = usage;
	create.sharingMode = sharingMode;
	create.queueFamilyIndexCount = (uint32_t) queueFamilyIndices.size();
	create.pQueueFamilyIndices = queueFamilyIndices.empty() ? NULL : &queueFamilyIndices.front();
	VkBuffer buffer;
	VKCHECK(vkCreateBuffer(internal::get_instance(*device), &create, NULL, &buffer));
	return buffer_type(buffer, device);
}
Ejemplo n.º 8
0
 buffer_type chunk()
 {
   switch(status_)
   {
     case PREFIX_CHUNK:
       return boost::asio::buffer(reinterpret_cast<char*>(&storage_.prefix_), sizeof(prefix_type));
     case DATA_CHUNK:
       return boost::asio::buffer(&storage_.data_[0], storage_.data_.size());
     default:
       BOOST_ASSERT_MSG(false, 
         "prefixed_receive_buffer::next_chunk: Invalid status.");
       return buffer_type(nullptr, 0);
   }
 }
Ejemplo n.º 9
0
BigInt::buffer_type BigInt::conv_ulong ( unsigned long n )
{
    if ( n == 0 )
        return buffer_type ( 1, 0 );

    buffer_type t;
    t.reserve ( sizeof(n)*3 );

    while ( n )
    {
        t.push_back ( n%10 );
        n/=10;
    }

    return t;
}
Ejemplo n.º 10
0
ERROR_CODE _bencoding_string_end_callback(struct bencoding_engine_t *bencoding_engine, const unsigned char *pointer, size_t size) {
    /* allocates space for the reference to the
    type structure to hold the string */
    struct type_t *type;

    /* retrieves the bencoding handler from the template engine context
    then uses it to store the (current) value */
    struct bencoding_handler_t *bencoding_handler = (struct bencoding_handler_t *) bencoding_engine->context;

    /* allocates memory for the string and then copies the source pointer
    data into the string buffer for the provided size and then closes it */
    char *string = MALLOC(size + 1);
    memcpy(string, pointer, size);
    string[size] = '\0';

    /* in case the next key flag is active must set the current key as
    the just retrieved string */
    if(bencoding_handler->next_key == 1) {
        /* in case there's a key pending to be release must release it
        to avoid memory leaks, then sets the current string as the key
        and unsets the next key flag to save the value */
        if(bencoding_handler->key != NULL) { FREE(bencoding_handler->key); }
        bencoding_handler->key = (unsigned char *) string;
        bencoding_handler->next_key = 0;
    }
    /* otherwise in case the sequence type is defined the string must
    be a value and must be associated with the sequence */
    else if(bencoding_handler->sequence != NULL) {
        /* creates a new type structure for the string
        and sets it with the correct string value */
        create_type(&type, STRING_TYPE);
        *type = buffer_type(string, size);

        /* switches over the type of current sequence to
        execute the proper operations */
        switch(bencoding_handler->sequence->type) {
            case LIST_TYPE:
                /* adds the current type to the list sequence */
                append_value_linked_list(
                    bencoding_handler->sequence->value.value_list,
                    (void *) type
                );

                /* breaks the switch */
                break;

            case MAP_TYPE:
                /* sets the value in the map for the current key and sets the next key
                flag so that the next string is saved as a key */
                set_value_string_hash_map(
                    bencoding_handler->sequence->value.value_map,
                    bencoding_handler->key,
                    (void *) type
                );
                bencoding_handler->next_key = 1;

                /* breaks the switch */
                break;

            case SORT_MAP_TYPE:
                /* sets the value in the map for the current key and sets the next key
                flag so that the next string is saved as a key */
                set_value_string_sort_map(
                    bencoding_handler->sequence->value.value_sort_map,
                    bencoding_handler->key,
                    (void *) type
                );
                bencoding_handler->next_key = 1;

                /* breaks the switch */
                break;

            default:
                /* breaks the switch */
                break;
        }
    }

    /* in case there is no top type defined for the handler sets the
    current type as the top type (base type) */
    if(bencoding_handler->top == NULL) { bencoding_handler->top = type; }

    /* raises no error */
    RAISE_NO_ERROR;
}