/workspaces/astro/sol3-sdk/cpp/sol3/core/shmem_buffer_impl.h Source File

Space-ng SDK: /workspaces/astro/sol3-sdk/cpp/sol3/core/shmem_buffer_impl.h Source File
Space-ng SDK
shmem_buffer_impl.h
Go to the documentation of this file.
1 
2 // Copyright (c) Space-ng, inc. All rights reserved.
3 
4 #pragma once
5 #include <unistd.h>
6 
7 #include <cstddef>
8 #include <cstdint>
9 #include <random>
10 
11 namespace sol3::core::impl {
12 
14  public:
15  explicit FileDescriptor(int fd = -1);
17 
18  // Move constructor
19  FileDescriptor(FileDescriptor&& other) noexcept;
20 
21  // Move assignment
23 
24  // Disable copy
25  FileDescriptor(FileDescriptor const&) = delete;
27 
28  int get() const;
29  void reset(int fd = -1);
30 
31  private:
32  int fd_;
33  void close();
34 };
35 
36 class Mmap {
37  public:
38  Mmap() = default;
39  Mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset);
40  ~Mmap();
41 
42  void* data() const;
43  size_t size() const;
44  bool valid() const;
45 
46  // Non-copyable, movable
47  Mmap(Mmap const&) = delete;
48  Mmap& operator=(Mmap const&) = delete;
49  Mmap(Mmap&& other) noexcept;
50  Mmap& operator=(Mmap&& other) noexcept;
51 
52  private:
53  void* ptr_ = nullptr;
54  size_t len_ = 0;
55 };
56 
57 inline uint64_t makeUuid() {
58  std::random_device rd;
59  std::mt19937_64 gen(rd());
60  return gen();
61 }
62 
63 } // namespace sol3::core::impl
Definition: shmem_buffer_impl.h:13
FileDescriptor & operator=(FileDescriptor const &)=delete
FileDescriptor & operator=(FileDescriptor &&other) noexcept
FileDescriptor(FileDescriptor const &)=delete
FileDescriptor(FileDescriptor &&other) noexcept
Definition: shmem_buffer_impl.h:36
Mmap & operator=(Mmap &&other) noexcept
Mmap & operator=(Mmap const &)=delete
Mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
size_t size() const
void * data() const
Mmap(Mmap const &)=delete
Mmap(Mmap &&other) noexcept
Definition: fb_json.h:129
uint64_t makeUuid()
Definition: shmem_buffer_impl.h:57