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 <xercesc/dom/DOM.hpp>
30 using namespace shibsp;
31 using namespace xmltooling;
32 using namespace xercesc;
36 //SHIBSP_DLLLOCAL PluginManager<ListenerService,const DOMElement*>::Factory MemoryListenerServiceFactory;
37 SHIBSP_DLLLOCAL PluginManager<ListenerService,string,const DOMElement*>::Factory TCPListenerServiceFactory;
39 SHIBSP_DLLLOCAL PluginManager<ListenerService,string,const DOMElement*>::Factory UnixListenerServiceFactory;
43 void SHIBSP_API shibsp::registerListenerServices()
45 SPConfig& conf=SPConfig::getConfig();
46 //conf.ListenerServiceManager.registerFactory(MEMORY_LISTENER_SERVICE, MemoryListenerServiceFactory);
47 conf.ListenerServiceManager.registerFactory(TCP_LISTENER_SERVICE, TCPListenerServiceFactory);
49 conf.ListenerServiceManager.registerFactory(UNIX_LISTENER_SERVICE, UnixListenerServiceFactory);
53 Remoted* ListenerService::regListener(const char* address, Remoted* listener)
56 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
57 if (i!=m_listenerMap.end())
59 m_listenerMap[address]=listener;
60 Category::getInstance(SHIBSP_LOGCAT".Listener").info("registered remoted message endpoint (%s)",address);
64 bool ListenerService::unregListener(const char* address, Remoted* current, Remoted* restore)
66 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
67 if (i!=m_listenerMap.end() && i->second==current) {
69 m_listenerMap[address]=restore;
71 m_listenerMap.erase(address);
72 Category::getInstance(SHIBSP_LOGCAT".Listener").info("unregistered remoted message endpoint (%s)",address);
78 Remoted* ListenerService::lookup(const char *address) const
80 map<string,Remoted*>::const_iterator i=m_listenerMap.find(address);
81 return (i==m_listenerMap.end()) ? NULL : i->second;
84 void ListenerService::receive(DDF &in, ostream& out)
87 throw ListenerException("Incoming message with no destination address rejected.");
88 else if (!strcmp("ping",in.name())) {
89 DDF outmsg=DDF(NULL).integer(in.integer() + 1);
90 DDFJanitor jan(outmsg);
94 Locker locker(SPConfig::getConfig().getServiceProvider());
95 Remoted* dest=lookup(in.name());
97 throw ListenerException("No destination registered for incoming message addressed to ($1).",params(1,in.name()));
99 dest->receive(in, out);