00001 /*========================================================================= 00002 00003 Program: BlueBerry Platform 00004 Language: C++ 00005 Date: $Date: 2010-01-16 19:57:43 +0100 (Sa, 16 Jan 2010) $ 00006 Version: $Revision: 21070 $ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include <berryPlatform.h> 00019 #include <berryIExtensionPointService.h> 00020 #include <berryIConfigurationElement.h> 00021 #include <mitkInputDeviceRegistry.h> 00022 #include <mitkInputDeviceDescriptor.h> 00023 #include "mitkCoreExtConstants.h" 00024 00025 mitk::InputDeviceRegistry::InputDeviceRegistry() 00026 { 00027 //initialize the registry by copying all available extension points into a local variable 00028 berry::IExtensionPointService::Pointer extensionPointService = berry::Platform::GetExtensionPointService(); 00029 std::vector<berry::IConfigurationElement::Pointer> allExtensionsInputDevices 00030 = extensionPointService->GetConfigurationElementsFor(mitk::CoreExtConstants::INPUTDEVICE_EXTENSION_NAME); 00031 00032 for(std::vector<berry::IConfigurationElement::Pointer>::const_iterator it = allExtensionsInputDevices.begin(); 00033 it != allExtensionsInputDevices.end();++it) 00034 { 00035 InputDeviceDescriptorPtr temp(new mitk::InputDeviceDescriptor(*it)); 00036 00037 // The equation with the end means, that if there is no such element and 00038 // the pointer will be at end (not the last element, actually after it) 00039 if(this->m_ListRegisteredDevices.find(temp->GetID()) == this->m_ListRegisteredDevices.end()) 00040 { 00041 m_ListRegisteredDevices.insert(std::make_pair<std::string, InputDeviceDescriptorPtr>(temp->GetID(),temp)); 00042 } 00043 else 00044 { 00045 throw std::runtime_error("The Input Device ID: "+temp->GetID()+" is already registered."); 00046 } 00047 } 00048 } 00049 00050 mitk::InputDeviceRegistry::~InputDeviceRegistry() 00051 { 00052 } 00053 00054 mitk::InputDeviceRegistry::InputDeviceDescriptorPtr mitk::InputDeviceRegistry::Find(const std::string &id) const 00055 { 00056 Poco::HashMap<std::string,InputDeviceDescriptorPtr>::ConstIterator result = this->m_ListRegisteredDevices.find(id); 00057 00058 // first = key, second = element or vice versa, if inserted different in the hash map 00059 if(result != this->m_ListRegisteredDevices.end()) return result->second; 00060 00061 return InputDeviceDescriptorPtr(0); 00062 } 00063 00064 std::vector<mitk::InputDeviceRegistry::InputDeviceDescriptorPtr> mitk::InputDeviceRegistry::GetInputDevices() const 00065 { 00066 std::vector<mitk::InputDeviceRegistry::InputDeviceDescriptorPtr> temp; 00067 for(Poco::HashMap<std::string, InputDeviceDescriptorPtr>::ConstIterator it = m_ListRegisteredDevices.begin(); 00068 it != m_ListRegisteredDevices.end();++it) 00069 { 00070 // first = key, second = element or vice versa, if inserted different in the hash map 00071 temp.push_back(it->second); 00072 } 00073 return temp; 00074 } 00075 00076 bool mitk::InputDeviceRegistry::IsA(const std::type_info& type) 00077 { 00078 std::string name(GetType().name()); 00079 return name == type.name() || berry::Service::IsA(type); 00080 } 00081 00082 const std::type_info& mitk::InputDeviceRegistry::GetType() const 00083 { 00084 return typeid(IInputDeviceRegistry); 00085 } 00086