Beispiel #1
0
 /**
  * Returns the last written value written to this port, in case it is
  * kept by this port, otherwise, returns a default T().
  * @return The last written value or T().
  */
 T getLastWrittenValue() const
 {
     typename internal::AssignableDataSource<T>::shared_ptr last_written_value = this->last_written_value;
     if (written && last_written_value)
         return last_written_value->get();
     else return T();
 }
Beispiel #2
0
        virtual bool connectionAdded( base::ChannelElementBase::shared_ptr channel_input, ConnPolicy const& policy ) {
            // Initialize the new channel with last written data if requested
            // (and available)

            // This this the input channel element of the whole connection
            typename base::ChannelElement<T>::shared_ptr channel_el_input =
                static_cast< base::ChannelElement<T>* >(channel_input.get());


            if (written)
            {
                typename internal::AssignableDataSource<T>::shared_ptr last_written_value = this->last_written_value;
                if (last_written_value)
                {
                    T sample = last_written_value->get();
                    if ( channel_el_input->data_sample(sample) ) {
                        if ( policy.init )
                            return channel_el_input->write(sample);
                        return true;
                    } else {
                        Logger::In in("OutputPort");
                        log(Error) << "Failed to pass data sample to data channel. Aborting connection."<<endlog();
                        return false;
                    }
                }
            }
            // even if we're not written, test the connection with a default sample.
            return channel_el_input->data_sample( T() );
        }
Beispiel #3
0
 /**
  * Reads the last written value written to this port, in case it is
  * kept by this port, otherwise, returns false.
  * @param sample The data sample to store the value into.
  * @return true if it could be retrieved, false otherwise.
  */
 bool getLastWrittenValue(T& sample) const
 {
     typename internal::AssignableDataSource<T>::shared_ptr last_written_value = this->last_written_value;
     if (written && last_written_value)
     {
         sample = last_written_value->get();
         return true;
     }
     return false;
 }