46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#include <fcntl.h>
|
|
#include <sys/mman.h>
|
|
#include <unistd.h>
|
|
|
|
#include <cstdio>
|
|
#include <string>
|
|
|
|
#include "contract/contract.h"
|
|
|
|
int main(int argc, char** argv) {
|
|
if (argc != 2) {
|
|
return 2;
|
|
}
|
|
const std::string name = "/" + std::string(argv[1]);
|
|
const int fd = shm_open(name.c_str(), O_RDONLY, 0);
|
|
if (fd < 0) {
|
|
return 3;
|
|
}
|
|
void* map = mmap(
|
|
nullptr,
|
|
sizeof(nui::contract::FrameContract),
|
|
PROT_READ,
|
|
MAP_SHARED,
|
|
fd,
|
|
0);
|
|
if (map == MAP_FAILED) {
|
|
close(fd);
|
|
return 4;
|
|
}
|
|
const auto* contract =
|
|
static_cast<const nui::contract::FrameContract*>(map);
|
|
nui::contract::FrameData frame{};
|
|
nui::contract::read_latest_frame(*contract, frame);
|
|
std::printf(
|
|
"published=%llu frame=%u slot_sequence=%llu\n",
|
|
static_cast<unsigned long long>(contract->published_sequence),
|
|
frame.frame_number,
|
|
static_cast<unsigned long long>(
|
|
contract->slots[
|
|
contract->published_sequence % nui::contract::kFrameSlotCount]
|
|
.sequence));
|
|
munmap(map, sizeof(nui::contract::FrameContract));
|
|
close(fd);
|
|
return 0;
|
|
}
|