2 * Copyright 2001-2007 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 "ServiceProvider.h"
26 #include "remoting/ListenerService.h"
28 #include <log4cpp/Category.hh>
29 #include <xercesc/dom/DOM.hpp>
31 using namespace shibsp;
32 using namespace xmltooling;
33 using namespace log4cpp;
34 using namespace xercesc;
38 //SHIBSP_DLLLOCAL PluginManager<ListenerService,const DOMElement*>::Factory MemoryListenerServiceFactory;
39 SHIBSP_DLLLOCAL PluginManager<ListenerService,const DOMElement*>::Factory TCPListenerServiceFactory;
41 SHIBSP_DLLLOCAL PluginManager<ListenerService,const DOMElement*>::Factory UnixListenerServiceFactory;
45 void SHIBSP_API shibsp::registerListenerServices()
47 SPConfig& conf=SPConfig::getConfig();
48 //conf.ListenerServiceManager.registerFactory(MEMORY_LISTENER_SERVICE, MemoryListenerServiceFactory);
49 conf.ListenerServiceManager.registerFactory(TCP_LISTENER_SERVICE, TCPListenerServiceFactory);
51 conf.ListenerServiceManager.registerFactory(UNIX_LISTENER_SERVICE, UnixListenerServiceFactory);
55 Remoted* ListenerService::regListener(const char* address, Remoted* listener)
58 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
59 if (i!=m_listenerMap.end())
61 m_listenerMap[address]=listener;
62 Category::getInstance(SHIBSP_LOGCAT".Listener").info("registered remoted message endpoint (%s)",address);
66 bool ListenerService::unregListener(const char* address, Remoted* current, Remoted* restore)
68 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
69 if (i!=m_listenerMap.end() && i->second==current) {
71 m_listenerMap[address]=restore;
73 m_listenerMap.erase(address);
74 Category::getInstance(SHIBSP_LOGCAT".Listener").info("unregistered remoted message endpoint (%s)",address);
80 Remoted* ListenerService::lookup(const char *address) const
82 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
83 return (i==m_listenerMap.end()) ? NULL : i->second;
86 void ListenerService::receive(DDF &in, ostream& out)
89 throw ListenerException("Incoming message with no destination address rejected.");
90 else if (!strcmp("ping",in.name())) {
91 DDF outmsg=DDF(NULL).integer(in.integer() + 1);
92 DDFJanitor jan(outmsg);
96 Remoted* dest=lookup(in.name());
98 throw ListenerException("No destination registered for incoming message addressed to ($1).",params(1,in.name()));
100 Locker locker(SPConfig::getConfig().getServiceProvider());
101 dest->receive(in, out);