Fawkes API
Fawkes Development Version
|
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 InterfaceInfoList * list(const char *type_pattern, 00063 const char *id_pattern) const; 00064 00065 std::list<Interface *> open_multiple_for_reading(const char *type_pattern, 00066 const char *id_pattern = "*"); 00067 00068 /* InterfaceMediator methods */ 00069 virtual bool exists_writer(const Interface *interface) const; 00070 virtual unsigned int num_readers(const Interface *interface) const; 00071 virtual void notify_of_data_change(const Interface *interface); 00072 00073 private: 00074 const BlackBoardMemoryManager * memory_manager() const; 00075 00076 Interface * new_interface_instance(const char *type, const char *identifier); 00077 void delete_interface_instance(Interface *interface); 00078 00079 void * find_interface_in_memory(const char *type, const char *identifier); 00080 unsigned int next_mem_serial(); 00081 unsigned int next_instance_serial(); 00082 void create_interface(const char *type, const char *identifier, 00083 Interface* &interface, void* &ptr); 00084 00085 Interface * writer_for_mem_serial(unsigned int mem_serial); 00086 00087 private: 00088 unsigned int instance_serial; 00089 00090 BlackBoardMemoryManager *memmgr; 00091 BlackBoardMessageManager *msgmgr; 00092 Mutex *mutex; 00093 BlackBoardInstanceFactory *instance_factory; 00094 BlackBoardNotifier *notifier; 00095 00096 LockMap< unsigned int, Interface * > writer_interfaces; 00097 LockMap< unsigned int, RefCountRWLock * > rwlocks; 00098 }; 00099 00100 } // end namespace fawkes 00101 00102 #endif