2 * Copyright 2001-2010 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 <xercesc/dom/DOM.hpp>
30 using namespace shibsp;
31 using namespace xmltooling;
32 using namespace xercesc;
36 SHIBSP_DLLLOCAL PluginManager<ListenerService,string,const DOMElement*>::Factory TCPListenerServiceFactory;
38 SHIBSP_DLLLOCAL PluginManager<ListenerService,string,const DOMElement*>::Factory UnixListenerServiceFactory;
42 void SHIBSP_API shibsp::registerListenerServices()
44 SPConfig& conf=SPConfig::getConfig();
45 conf.ListenerServiceManager.registerFactory(TCP_LISTENER_SERVICE, TCPListenerServiceFactory);
47 conf.ListenerServiceManager.registerFactory(UNIX_LISTENER_SERVICE, UnixListenerServiceFactory);
59 ListenerService::ListenerService()
63 ListenerService::~ListenerService()
67 Remoted* ListenerService::regListener(const char* address, Remoted* listener)
70 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
71 if (i!=m_listenerMap.end())
73 m_listenerMap[address]=listener;
74 Category::getInstance(SHIBSP_LOGCAT".Listener").info("registered remoted message endpoint (%s)",address);
78 bool ListenerService::unregListener(const char* address, Remoted* current, Remoted* restore)
80 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
81 if (i!=m_listenerMap.end() && i->second==current) {
83 m_listenerMap[address]=restore;
85 m_listenerMap.erase(address);
86 Category::getInstance(SHIBSP_LOGCAT".Listener").info("unregistered remoted message endpoint (%s)",address);
92 Remoted* ListenerService::lookup(const char *address) const
94 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
95 return (i==m_listenerMap.end()) ? nullptr : i->second;
98 void ListenerService::receive(DDF &in, ostream& out)
101 throw ListenerException("Incoming message with no destination address rejected.");
102 else if (!strcmp("ping",in.name())) {
103 DDF outmsg=DDF(nullptr).integer(in.integer() + 1);
104 DDFJanitor jan(outmsg);
108 // Two stage lookup, on the listener itself, and the SP interface.
109 ServiceProvider* sp = SPConfig::getConfig().getServiceProvider();
111 Remoted* dest = lookup(in.name());
113 dest = sp->lookupListener(in.name());
115 throw ListenerException("No destination registered for incoming message addressed to ($1).", params(1,in.name()));
118 dest->receive(in, out);
121 bool ListenerService::init(bool force)
126 void ListenerService::term()