/// TKS_SharedBuffer.h
///
/// (c) 2005-2008 Bastian Spiegel <bs@tkscript.de>
///     - distributed under terms of the GNU general public license (GPL).
///
#ifndef __TKS_SHAREDBUFFER_H__
#define __TKS_SHAREDBUFFER_H__

enum __TKS_SharedBufferHeader {
   TKS_SBH_SIZE = 0, // size of region excluding this header
      
   TKS_SHAREDBUFFERHEADER_SIZE = sizeof(sSI)
};

class TKS_SharedBuffer : public YAC_Buffer {
public:
   YAC_String shmKey;
   sBool      shmOwner;

   union {
      void      *ptr; // OS-dependent shared memory handle
      int        id;
   } shmHandle;

public:
   TKS_SharedBuffer(void);
   ~TKS_SharedBuffer();

   // Internal methods:
   void genSharedMemoryKey(void);

   // Exported methods (API):
   sSI         allocSharedMemory      (sSI _size);
   YAC_String *getSharedMemoryKey     (void);
   void        free                   (void);

   // Platform specific methods
   sSI         allocSharedMemoryByKey (YAC_String *_shmKey, sSI _size);
   sSI         visitSharedMemory      (YAC_String *_shmKey, sSI _size);
   void        freeSharedMemory       (void); // must only be called by free()

   // The following methods fail and issue a warning in this class
   sSI  setSize    (sSI _numbytes); 
   sSI  resize     (sSI _numbytes);

   sUI YAC_VCALL yacArrayAlloc  (sUI _sx, sUI, sUI, sUI);
   sUI YAC_VCALL yacArrayRealloc(sUI _sx, sUI _sy, sUI _type, sUI _elementbytesize);
   
};


#endif
