예제 #1
0
int main() {
    auto opts = osvr::common::IPCRingBuffer::Options("Test");
    auto buf = osvr::common::IPCRingBuffer::find(opts);
    if (!buf) {
        std::cout << "Couldn't find it." << std::endl;
        return 1;
    }

    std::cout << "Capacity: " << buf->getEntries() << " entries.\n";
    std::cout << "Entry size: " << buf->getEntrySize() << " bytes per entry."
              << std::endl;

    osvr::common::IPCRingBuffer::sequence_type seq(0);
    while (true) {
        std::cin.ignore();
        std::cout << "Sequence number " << seq << ": ";
        auto res = buf->get(seq);
        if (res) {
            std::cout << (res.get())[0] << (res.get())[1] << (res.get())[2];
        } else {
            std::cout << "Not available";
        }
        std::cout << std::endl;
        seq++;
    }

    return 0;
}
예제 #2
0
int main() {

    auto opts = osvr::common::IPCRingBuffer::Options("Test");
    auto buf = osvr::common::IPCRingBuffer::create(opts);
    if (!buf) {
        std::cout << "Couldn't create it." << std::endl;
        return 1;
    }
    std::cout << "Using backend: " << int(buf->getBackend()) << std::endl;

    std::cout << "Capacity: " << buf->getEntries() << " entries.\n";
    std::cout << "Entry size: " << buf->getEntrySize() << " bytes per entry."
              << std::endl;

    while (true) {
        // std::this_thread::sleep_for(std::chrono::milliseconds(100));
        std::string data;
        std::getline(std::cin, data);
        auto seq =
            buf->put(reinterpret_cast<const unsigned char *>(data.data()),
                     data.length());
        std::cout << "Sequence number " << seq << std::endl;
        // auto proxy = buf->put();
    }

    return 0;
}
예제 #3
0
파일: ringbuffer.c 프로젝트: goshng/cocoa
/*---------------------------------------------------------------------------*/
logc_error_t
rng_readRingbuffer(
      const rng_ringBuffer_t* const rngBuf,
      char* const buffer,
      const size_t size,
      size_t* const writtenBytes
      )
{
   logc_error_t err = LOG_ERR_OK;

   assert(rngBuf != NULL);
   assert(buffer != NULL);
   assert(writtenBytes != NULL);

   *writtenBytes = 0;

   if (rngBuf->entries == 0) {
      err = LOG_ERR_NO_ENTRIES;
   }

   if (err == LOG_ERR_OK) {
      size_t entries = rngBuf->entries;
      char* bufptr = buffer;
      char* tmpReadAt = rngBuf->readAt;

      while (entries-- != 0) {
         size_t entrySize = getEntrySize(rngBuf, tmpReadAt);
         if ((*writtenBytes + entrySize) < size) {
            getEntry(bufptr, rngBuf, &tmpReadAt);
            *writtenBytes += entrySize;
            bufptr += entrySize;
         } else {
            err = LOG_ERR_INSUFFICIENT_BUFFER;
            break;
         }
      }
      buffer[*writtenBytes] = 0;
      (*writtenBytes)++;
   }

   return err;
}
bool ProbabilityDictContent::setProbabilityEntry(const int terminalId,
        const ProbabilityEntry *const probabilityEntry) {
    if (terminalId < 0) {
        return false;
    }
    const int entryPos = getEntryPos(terminalId);
    if (terminalId >= mSize) {
        ProbabilityEntry dummyEntry;
        // Write new entry.
        int writingPos = getBuffer()->getTailPosition();
        while (writingPos <= entryPos) {
            // Fulfilling with dummy entries until writingPos.
            if (!writeEntry(&dummyEntry, writingPos)) {
                AKLOGE("Cannot write dummy entry. pos: %d, mSize: %d", writingPos, mSize);
                return false;
            }
            writingPos += getEntrySize();
        }
        mSize = terminalId + 1;
    }
    return writeEntry(probabilityEntry, entryPos);
}
int ProbabilityDictContent::getEntryPos(const int terminalId) const {
    return terminalId * getEntrySize();
}