interface_manager.h

00001  
00002 /***************************************************************************
00003  *  interface_manager.h - BlackBoard interface manager
00004  *
00005  *  Created: Mon Oct 09 19:05:46 2006
00006  *  Copyright  2006-2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __BLACKBOARD_INTERFACE_MANAGER_H_
00025 #define __BLACKBOARD_INTERFACE_MANAGER_H_
00026 
00027 #include <interface/mediators/interface_mediator.h>
00028 
00029 #include <core/utils/lock_map.h>
00030 #include <utils/misc/string_compare.h>
00031 
00032 #include <list>
00033 
00034 namespace fawkes {
00035 
00036 class Interface;
00037 class InterfaceInfoList;
00038 class BlackBoardMemoryManager;
00039 class BlackBoardMessageManager;
00040 class Mutex;
00041 class BlackBoardInstanceFactory;
00042 class BlackBoardInterfaceListener;
00043 class BlackBoardInterfaceObserver;
00044 class BlackBoardNotifier;
00045 class RefCountRWLock;
00046 
00047 class BlackBoardInterfaceManager : public InterfaceMediator
00048 {
00049  friend class BlackBoardMessageManager;
00050  public:
00051 
00052   BlackBoardInterfaceManager(BlackBoardMemoryManager *bb_memmgr,
00053                              BlackBoardMessageManager *bb_msgmgr,
00054                              BlackBoardNotifier *bb_notifier);
00055   virtual ~BlackBoardInterfaceManager();
00056 
00057   Interface *  open_for_reading(const char *interface_type, const char *identifier);
00058   Interface *  open_for_writing(const char *interface_type, const char *identifier);
00059   void         close(Interface *interface);
00060 
00061   InterfaceInfoList *  list_all() const;
00062 
00063   std::list<Interface *> open_multiple_for_reading(const char *interface_type,
00064                                                    const char *id_pattern = "*");
00065 
00066   /* InterfaceMediator methods */
00067   virtual bool exists_writer(const Interface *interface) const;
00068   virtual unsigned int num_readers(const Interface *interface) const;
00069   virtual void notify_of_data_change(const Interface *interface);
00070 
00071  private:
00072   const BlackBoardMemoryManager *  memory_manager() const;
00073 
00074   Interface *  new_interface_instance(const char *type, const char *identifier);
00075   void         delete_interface_instance(Interface *interface);
00076 
00077   void *       find_interface_in_memory(const char *type, const char *identifier);
00078   unsigned int next_mem_serial();
00079   unsigned int next_instance_serial();
00080   void         create_interface(const char *type, const char *identifier,
00081                                 Interface* &interface, void* &ptr);
00082 
00083   Interface *  writer_for_mem_serial(unsigned int mem_serial);
00084 
00085  private:
00086   unsigned int                  instance_serial;
00087 
00088   BlackBoardMemoryManager      *memmgr;
00089   BlackBoardMessageManager     *msgmgr;
00090   Mutex                        *mutex;
00091   BlackBoardInstanceFactory    *instance_factory;
00092   BlackBoardNotifier           *notifier;
00093 
00094   LockMap< unsigned int, Interface * >              writer_interfaces;
00095   LockMap< unsigned int, RefCountRWLock * >         rwlocks;
00096 };
00097 
00098 } // end namespace fawkes
00099 
00100 #endif

Generated on Tue Feb 22 13:32:25 2011 for Fawkes API by  doxygen 1.4.7