Пример #1
0
jint ByteChannel::write(jobject source)
{
  const ByteBuffer::ClassImpl& bufimpl = ByteBuffer::impl(m_env);

  const jint remaining = get_remaining(m_env, source,
                                       bufimpl.m_mid_get_remaining);
  if (!remaining)
    {
      // No data in the buffer; don't try to write anything.
      return 0;
    }

  const jint position = get_position(m_env, source,
                                     bufimpl.m_mid_get_position);

  jint bytes_written = 0;
  const void* data = m_env.GetDirectBufferAddress(source);
  if (data)
    {
      data = static_cast<const char*>(data) + position;
      bytes_written = m_writer(m_env, data, remaining);
    }
  else
    {
      // It was not a direct buffer ... see if it has an array.
      jbyteArray raw_array = get_array(m_env, source,
                                       bufimpl.m_mid_has_array,
                                       bufimpl.m_mid_get_array);
      if (raw_array)
        {
          const jint array_offset = get_array_offset(
              m_env, source,
              bufimpl.m_mid_get_array_offset);
          const ByteArray array(m_env, raw_array);
          ByteArray::Contents contents(array);
          data = contents.data();
          data = static_cast<const char*>(data) + position + array_offset;
          bytes_written = m_writer(m_env, data, remaining);
        }
    }
  if (data)
    {
      if (bytes_written > 0)
        set_position(m_env, source,
                     bufimpl.m_mid_set_position,
                     position + bytes_written);
      return bytes_written;
    }

  // No accessible array, either. Oh well. Get an array from the
  // buffer and read data from that.
  ByteArray array(m_env, remaining);
  get_bytearray(m_env, source,
                bufimpl.m_mid_get_bytearray,
                array);
  ByteArray::Contents contents(array);
  bytes_written = m_writer(m_env, contents.data(), contents.length());
  return bytes_written;
}
Пример #2
0
bool GPxiBasicAnalogOutput::UpdatePhysicalOutput( double newSetPoint )
{
	try {
		// Create a writer
		CNiDAQmxAnalogSingleChannelWriter m_writer(Stream);
		// And write immediately
		m_writer.WriteSingleSample(true, newSetPoint);
		// Wait until the I/O completes before destroying the task
		WaitUntilDone(-1);
	}
	catch (CNiDAQmxException *exception) {
		exception->ReportError();
		exception->Delete();
		return false;
	}
	return true;
}
Пример #3
0
MojSocketService::Connection::Connection(MojSocketService& service)
: SockHandler(service),
  m_state(StateInit)
  m_writer(m_writeBuf),
  m_readSlot(this, &Connection::read),
  m_flushSlot(this, &Connection::flush)
{
}

MojErr MojSocketService::Connection::open(MojSockT sock)
{
	MojAssert(sock != MojInvalidSock);

	m_sock.open(sock);
	MojErr err = start();
	MojErrCheck(err);

	return MojErrNone;
}
Пример #4
0
// Flush sector buffer to device if appropriate.
//
bool DevicePrint::flush(void)
{
  if (m_bufferIndex != 0 && m_sectorsAvailable != 0)
  {
    if (m_writer(m_buffer, m_sector, 1) != 0)
    {
      return false;
    }

    // Only advance internal counters when flushing a full buffer.
    // This allows periodic flushes to maintain the data integrity.
    //
    if (m_bufferIndex == 512)
    {
      m_bufferIndex = 0;

      ++m_sector;
      --m_sectorsAvailable;
    }
  }

  return true;
}
Пример #5
0
 template<class msg_type> void operator()(msg_type & msg) const {
     m_writer(msg);
 }