2 * Copyright 2001-2006 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * Interprocess remoting engine.
24 #include "exceptions.h"
25 #include "ListenerService.h"
27 #include <log4cpp/Category.hh>
28 #include <xercesc/dom/DOM.hpp>
30 using namespace shibsp;
31 using namespace xmltooling;
32 using namespace log4cpp;
33 using namespace xercesc;
37 //SHIBSP_DLLLOCAL PluginManager<ListenerService,const DOMElement*>::Factory MemoryListenerServiceFactory;
38 SHIBSP_DLLLOCAL PluginManager<ListenerService,const DOMElement*>::Factory TCPListenerServiceFactory;
40 SHIBSP_DLLLOCAL PluginManager<ListenerService,const DOMElement*>::Factory UnixListenerServiceFactory;
44 void SHIBSP_API shibsp::registerListenerServices()
46 SPConfig& conf=SPConfig::getConfig();
47 //conf.ListenerServiceManager.registerFactory(MEMORY_LISTENER_SERVICE, MemoryListenerServiceFactory);
48 conf.ListenerServiceManager.registerFactory(TCP_LISTENER_SERVICE, TCPListenerServiceFactory);
50 conf.ListenerServiceManager.registerFactory(UNIX_LISTENER_SERVICE, UnixListenerServiceFactory);
54 Remoted* ListenerService::regListener(const char* address, Remoted* listener)
57 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
58 if (i!=m_listenerMap.end())
60 m_listenerMap[address]=listener;
61 Category::getInstance(SHIBSP_LOGCAT".Listener").info("registered remoted message endpoint (%s)",address);
65 bool ListenerService::unregListener(const char* address, Remoted* current, Remoted* restore)
67 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
68 if (i!=m_listenerMap.end() && i->second==current) {
70 m_listenerMap[address]=restore;
72 m_listenerMap.erase(address);
73 Category::getInstance(SHIBSP_LOGCAT".Listener").info("unregistered remoted message endpoint (%s)",address);
79 Remoted* ListenerService::lookup(const char *address) const
81 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
82 return (i==m_listenerMap.end()) ? NULL : i->second;
85 DDF ListenerService::receive(const DDF &in)
88 throw ListenerException("Incoming message with no destination address rejected.");
89 else if (!strcmp("ping",in.name())) {
90 DDF out=DDF(NULL).integer(in.integer() + 1);
94 Remoted* dest=lookup(in.name());
96 throw ListenerException("No destination registered for incoming message addressed to ($1).",params(1,in.name()));
98 return dest->receive(in);