/* LICENSE:
  =========================================================================
    CMPack'04 Source Code Release for OPEN-R SDK 1.1.5-r2 for ERS7
    Copyright (C) 2004 Multirobot Lab [Project Head: Manuela Veloso]
    School of Computer Science, Carnegie Mellon University
    All rights reserved.
  ========================================================================= */

#ifndef INCLUDED_SharedMemMgr_h
#define INCLUDED_SharedMemMgr_h

#include <utility>

#include <Types.h>
#include <OPENR/ObjcommMessages.h>
#include <OPENR/ObjcommTypes.h>
#include <OPENR/OObject.h>
#include <OPENR/OObserverVector.h>
//#include <OPENR/OSharedMemoryBuffer.h>
#include <OPENR/OSubject.h>

#include "def.h"

#include "../headers/AperiosSharedMem.h"

class SharedMemMgr : public OObject {
public:
  static const int MaxRegions=10;

  OSubject*        subject[numOfSubject];
  OObserverVector* observer[numOfObserver];
 
  SharedMemMgr();
  ~SharedMemMgr() {}

  //
  //  OPEN-R Method
  //
  virtual OStatus DoInit   (const OSystemEvent&);
  virtual OStatus DoStart  (const OSystemEvent&);
  virtual OStatus DoStop   (const OSystemEvent&);
  virtual OStatus DoDestroy(const OSystemEvent&);

  //
  // Inter Object Communication Method 
  //
  void ReadyForRegion(const OReadyEvent  &event);
  void RequestRegion (const ONotifyEvent &event);
  void RegisterRegion(const ONotifyEvent &event);

private:
  // methods
  void sendObjectInfoIfReady(const ObserverID &obs_id);
  void sendObjectInfoIfReady();

  typedef std::pair<RCRegion *, list<ObserverID> > RegionConnector;

  RegionConnector *regionConnectors;
};

#endif
