/**
 * Simple in-memory superblob implementation
 */

#ifndef MEMSUPERBLOB_H
#define MEMSUPERBLOB_H

#include "persifs.h"
#include "superblob.h"

#include <ihash.h>

struct memBlobEnt 
{
  blockFingerprint fp;
  blockAddress addr;
  str data;
  ihash_entry<memBlobEnt> hlink_fp;
  ihash_entry<memBlobEnt> hlink_addr;
};

class memSuperblob : public superblob
{
public:
  static void create(callback<void, ref<memSuperblob> >::ref cb,
                     cbe error);

  virtual void put(str blobContent,
                   callback<void, blockFingerprint, blockAddress>::ref cb,
                   cbe error);

  virtual void get(blockFingerprint fingerprint,
                   callback<void, str, blockAddress>::ref cb, cbe error);

  virtual void getDirect(blockAddress address,
                 callback<void, str, blockAddress>::ref on_get, cbe error);

  virtual ~memSuperblob();
  
protected:
  memSuperblob();
  ihash<blockFingerprint, memBlobEnt, &memBlobEnt::fp,
        &memBlobEnt::hlink_fp> dataByFP;
  ihash<blockAddress, memBlobEnt, &memBlobEnt::addr,
        &memBlobEnt::hlink_addr> dataByAddr;
  blockAddress nextAddr;
};


#endif // MEMSUPERBLOB_H
