Valkka  1.6.1
OpenSource Video Management
Classes | Macros
sharedmem.h File Reference

Posix shared memory segment server/client management, shared memory ring buffer synchronized using posix semaphores. More...

#include "common.h"
#include <sys/shm.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <semaphore.h>
#include "framefilter.h"
#include "Python.h"
Include dependency graph for sharedmem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  EventFd
 A file descriptor for running select and poll with shmem ring buffers. More...
 
class  SharedMemSegment
 Handles a shared memory segment with metadata (the segment size) More...
 
class  SimpleSharedMemSegment
 Shared mem segment with simple metadata : just the payload length. More...
 
struct  RGB24Meta
 A seriazable metadata object. More...
 
class  RGB24SharedMemSegment
 A Shmem segment describing an RGB24 frame. More...
 
class  SharedMemRingBufferBase
 Interprocess shared memory ring buffer synchronized with posix semaphores. More...
 
class  SharedMemRingBuffer
 
class  SharedMemRingBufferRGB
 SharedMemRingBuffer for AVRGBFrame. More...
 
class  ShmemFrameFilter
 This FrameFilter writes frames into a SharedMemRingBuffer. More...
 
class  RGBShmemFrameFilter
 Like ShmemFrameFilter. More...
 

Macros

#define server_init(CLASSNAME, TYPENAME)
 
#define client_init(CLASSNAME, TYPENAME)
 
#define server_close(CLASSNAME, TYPENAME)
 
#define client_close(CLASSNAME, TYPENAME)
 
#define copy_meta_from(CLASSNAME, TYPENAME)
 
#define copy_meta_to(CLASSNAME, TYPENAME)
 

Detailed Description

Posix shared memory segment server/client management, shared memory ring buffer synchronized using posix semaphores.

Author
Sampsa Riikonen
Date
2017
Version
1.6.1

Macro Definition Documentation

◆ client_close

#define client_close (   CLASSNAME,
  TYPENAME 
)
Value:
void CLASSNAME::clientClose() { \
if (munmap(ptr, n_bytes)!=0 or munmap(ptr_, sizeof(TYPENAME)!=0)) { \
perror("valkka_core: sharedmem.cpp: CLASSNAME::clientClose: munmap failed"); \
exit(2); \
} \
} \

◆ client_init

#define client_init (   CLASSNAME,
  TYPENAME 
)
Value:
bool CLASSNAME::clientInit() { \
int fd, fd_;\
fd = shm_open(payload_name.c_str(), O_RDONLY, 0400);\
fd_= shm_open(meta_name.c_str(), O_RDONLY, 0400);\
if (fd == -1 or fd_==-1) {\
/* perror("valkka_core: sharedmem.cpp: SharedMemSegment::clientInit: shm_open failed"); */\
/* exit(2); */\
return false;\
}\
/* std::cout << "got shmem" << std::endl; */\
ptr =mmap(0, n_bytes, PROT_READ, MAP_SHARED, fd, 0);\
ptr_ =mmap(0, sizeof(TYPENAME), PROT_READ, MAP_SHARED, fd_, 0);\
if (ptr == MAP_FAILED or ptr_ == MAP_FAILED) {\
std::cout << "valkka_core: sharedmem.cpp: SharedMemSegment::clientInit: mmap failed" << std::endl;\
/* perror("valkka_core: sharedmem.cpp: SharedMemSegment::clientInit: mmap failed"); */\
/* exit(2);*/\
return false;\
}\
payload = (uint8_t*) ptr;\
meta = (TYPENAME*) ptr_;\
/*std::cout << "client meta reserved" << std::endl;*/\
close(fd);\
close(fd_);\
/*std::cout << "Client reserved " << sizeof(TYPENAME) << "bytes" << std::endl;*/\
return true;\
};\

◆ copy_meta_from

#define copy_meta_from (   CLASSNAME,
  TYPENAME 
)
Value:
void CLASSNAME::copyMetaFrom(void *meta_) { \
*meta = *((TYPENAME*)(meta_)); \
}\

◆ copy_meta_to

#define copy_meta_to (   CLASSNAME,
  TYPENAME 
)
Value:
void CLASSNAME::copyMetaTo(void *meta_) { \
*((TYPENAME*)(meta_)) = *meta; \
}\

◆ server_close

#define server_close (   CLASSNAME,
  TYPENAME 
)
Value:
void CLASSNAME::serverClose() { \
if (munmap(ptr, n_bytes)!=0 or munmap(ptr_, sizeof(TYPENAME)!=0)) { \
perror("valkka_core: sharedmem.cpp: CLASSNAME::serverClose: munmap failed"); \
exit(2); \
} \
if (shm_unlink(payload_name.c_str())!=0 or shm_unlink(meta_name.c_str())!=0) { \
perror("valkka_core: sharedmem.cpp: CLASSNAME::serverClose: shm_unlink failed"); \
/*exit(2);*/ \
} \
} \