/*============================================================================= Library: CTK Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ template ctkEABlacklistingHandlerTasks:: ctkEABlacklistingHandlerTasks(ctkPluginContext* context, ctkEABlackList* blackList, ctkEATopicHandlerFilters* topicHandlerFilters, ctkEAFilters* filters) : blackList(blackList), context(context), topicHandlerFilters(topicHandlerFilters), filters(filters) { checkNull(context, "Context"); checkNull(blackList, "BlackList"); checkNull(topicHandlerFilters, "TopicHandlerFilters"); checkNull(filters, "Filters"); } template ctkEABlacklistingHandlerTasks:: ~ctkEABlacklistingHandlerTasks() { delete filters; delete topicHandlerFilters; delete blackList; } template QList > > ctkEABlacklistingHandlerTasks:: createHandlerTasks(const ctkEvent& event) { QList > result; QList handlerRefs; try { handlerRefs = context->getServiceReferences( topicHandlerFilters->createFilterForTopic(event.getTopic())); } catch (const ctkInvalidArgumentException& e) { CTK_WARN_EXC(ctkEventAdminActivator::getLogService(), &e) << "Invalid EVENT_TOPIC [" << event.getTopic() << "]"; } for (int i = 0; i < handlerRefs.size(); ++i) { const ctkServiceReference& ref = handlerRefs.at(i); if (!blackList->contains(ref) //TODO security //&& ref.getPlugin()->hasPermission( // PermissionsUtil.createSubscribePermission(event.getTopic())) ) { try { if (event.matches(filters->createFilter( ref.getProperty(ctkEventConstants::EVENT_FILTER).toString()))) { result.push_back(ctkEAHandlerTask(ref, event, this)); } } catch (const ctkInvalidArgumentException& e) { CTK_WARN_SR_EXC(ctkEventAdminActivator::getLogService(), ref, &e) << "Invalid EVENT_FILTER - Blacklisting ServiceReference [" << ref << " | Plugin(" << ref.getPlugin() << ")]"; blackList->add(ref); } } } return result; } template void ctkEABlacklistingHandlerTasks:: blackListRef(const ctkServiceReference& handlerRef) { blackList->add(handlerRef); CTK_WARN(ctkEventAdminActivator::getLogService()) << "Blacklisting ServiceReference [" << handlerRef << " | Plugin(" << handlerRef.getPlugin() << ")] due to timeout!"; } template ctkEventHandler* ctkEABlacklistingHandlerTasks:: getEventHandler(const ctkServiceReference& handlerRef) { ctkEventHandler* result = (blackList->contains(handlerRef)) ? 0 : context->getService(handlerRef); return (result ? result : &nullEventHandler); } template void ctkEABlacklistingHandlerTasks:: ungetEventHandler(ctkEventHandler* handler, const ctkServiceReference& handlerRef) { if(&nullEventHandler != handler) { // Is the handler not unregistered or blacklisted? if(!blackList->contains(handlerRef) && (handlerRef.getPlugin())) { context->ungetService(handlerRef); } } } template void ctkEABlacklistingHandlerTasks:: checkNull(void* object, const QString& name) { if(object == 0) { throw ctkInvalidArgumentException(qPrintable(name + " may not be null")); } }