copying over queue-api-redo branch from my 2012 repo
This commit is not cleanly separated from the next one where I got
everything to compile again (and possibly even further on from there).
diff --git a/aos/atom_code/camera/Buffers.cpp b/aos/atom_code/camera/Buffers.cpp
index f580f89..bf16915 100644
--- a/aos/atom_code/camera/Buffers.cpp
+++ b/aos/atom_code/camera/Buffers.cpp
@@ -15,7 +15,6 @@
};
const std::string Buffers::kFDServerName("/tmp/aos_fd_server");
const std::string Buffers::kQueueName("CameraBufferQueue");
-const aos_type_sig Buffers::kSignature{sizeof(Message), 971, 1};
int Buffers::CreateSocket(int (*bind_connect)(int, const sockaddr *, socklen_t)) {
union af_unix_sockaddr {
@@ -66,7 +65,7 @@
void Buffers::Release() {
if (message_ != NULL) {
- aos_queue_free_msg(queue_, message_);
+ queue_->FreeMessage(message_);
message_ = NULL;
}
}
@@ -77,11 +76,12 @@
// TODO(brians) make sure the camera reader process hasn't died
do {
if (block) {
- message_ = static_cast<const Message *>(aos_queue_read_msg(queue_, PEEK | BLOCK));
+ message_ = static_cast<const Message *>(queue_->ReadMessage(
+ Queue::kPeek | Queue::kBlock));
} else {
static int index = 0;
- message_ = static_cast<const Message *>(aos_queue_read_msg_index(queue_, BLOCK,
- &index));
+ message_ = static_cast<const Message *>(queue_->ReadMessageIndex(
+ Queue::kBlock, &index));
}
} while (block && message_ == NULL);
if (message_ != NULL) {
@@ -137,7 +137,7 @@
}
Buffers::Buffers() : server_(CreateSocket(connect)), fd_(FetchFD()), message_(NULL) {
MMap();
- queue_ = aos_fetch_queue(kQueueName.c_str(), &kSignature);
+ queue_ = Queue::Fetch(kQueueName.c_str(), sizeof(Message), 971, 1);
}
Buffers::~Buffers() {
@@ -157,6 +157,5 @@
}
}
-} // namespace camera
-} // namespace aos
-
+} // namespace camera
+} // namespace aos
diff --git a/aos/atom_code/camera/Buffers.h b/aos/atom_code/camera/Buffers.h
index 6b54188..07177bc 100644
--- a/aos/atom_code/camera/Buffers.h
+++ b/aos/atom_code/camera/Buffers.h
@@ -53,9 +53,8 @@
// The current one. Sometimes NULL.
const Message *message_;
static const std::string kQueueName;
- static const aos_type_sig kSignature;
// NULL for the Reader one.
- aos_queue *queue_;
+ Queue *queue_;
// Make the actual mmap calls.
// Called by Buffers() automatically.
void MMap();
diff --git a/aos/atom_code/camera/Reader.cpp b/aos/atom_code/camera/Reader.cpp
index 5f30cfe..c87d173 100644
--- a/aos/atom_code/camera/Reader.cpp
+++ b/aos/atom_code/camera/Reader.cpp
@@ -31,8 +31,7 @@
// the bound socket listening for fd requests
int server_fd_;
- static const aos_type_sig kRecycleSignature;
- aos_queue *queue_, *recycle_queue_;
+ Queue *queue_, *recycle_queue_;
// the number of buffers currently queued in v4l2
uint32_t queued_;
public:
@@ -52,10 +51,11 @@
dev_name, errno, strerror(errno));
}
- queue_ = aos_fetch_queue_recycle(Buffers::kQueueName.c_str(), &Buffers::kSignature,
- &kRecycleSignature, &recycle_queue_);
+ queue_ = Queue::Fetch(Buffers::kQueueName.c_str(),
+ sizeof(Buffers::Message), 971, 1,
+ 1, Buffers::kNumBuffers, &recycle_queue_);
// read off any existing recycled messages
- while (aos_queue_read_msg(recycle_queue_, NON_BLOCK) != NULL);
+ while (recycle_queue_->ReadMessage(Queue::kNonBlock) != NULL);
queued_ = 0;
InitServer();
@@ -140,10 +140,11 @@
read = static_cast<const Buffers::Message *>(
// we block waiting for one if we can't dequeue one without leaving
// the driver <= 2 (to be safe)
- aos_queue_read_msg(recycle_queue_, (queued_ <= 2) ? BLOCK : NON_BLOCK));
+ recycle_queue_->ReadMessage((queued_ <= 2) ?
+ Queue::kBlock : Queue::kNonBlock));
if (read != NULL) {
buf.index = read->index;
- aos_queue_free_msg(recycle_queue_, read);
+ recycle_queue_->FreeMessage(read);
QueueBuffer(&buf);
}
} while (read != NULL);
@@ -163,7 +164,7 @@
}
Buffers::Message *const msg = static_cast<Buffers::Message *>(
- aos_queue_get_msg(queue_));
+ queue_->GetMessage());
if (msg == NULL) {
LOG(WARNING,
"couldn't get a message to send buf #%" PRIu32 " from queue %p."
@@ -175,7 +176,7 @@
msg->bytesused = buf.bytesused;
memcpy(&msg->timestamp, &buf.timestamp, sizeof(msg->timestamp));
msg->sequence = buf.sequence;
- if (aos_queue_write_msg_free(queue_, msg, OVERRIDE) == -1) {
+ if (!queue->WriteMessage(msg, Queue::kOverride)) {
LOG(WARNING,
"sending message %p with buf #%" PRIu32 " to queue %p failed."
" re-queueing now\n", msg, buf.index, queue_);
@@ -405,8 +406,6 @@
}
};
const char *const Reader::dev_name = "/dev/video0";
-const aos_type_sig Reader::kRecycleSignature{
- sizeof(Buffers::Message), 1, Buffers::kNumBuffers};
} // namespace camera
} // namespace aos