WebServiceRunner.cc
Go to the documentation of this file.
00001 /* 00002 * Copyright 2006-2009 Savarese Software Research Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * https://www.savarese.com/software/ApacheLicense-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include <ssrc/wispers/ws/WebServiceRunner.h> 00018 00019 #include <boost/filesystem/path.hpp> 00020 #include <boost/filesystem/operations.hpp> 00021 00022 __BEGIN_NS_SSRC_WSPR_WS 00023 00024 void WebServiceRunner::load_modules() SSRC_DECL_THROW(LoadError) { 00025 // A scratch variable to keep track of modules we've already loaded. 00026 // This allows multiple module instances to be created from the same .so 00027 // without loading the same .so multiple times. 00028 typedef std::unordered_map<string, ws_module_factory_ptr> factory_map; 00029 factory_map factories; 00030 00031 // Initialize modules. 00032 for(unsigned int i = 0; i < _module_configs.size(); ++i) { 00033 WebServiceModuleConfig & config = _module_configs[i]; 00034 ws_module_map::iterator it = _module_map.find(config.name); 00035 00036 if(it == _module_map.end()) { 00037 unsigned int j = 0; 00038 while(j < _module_dirs.size()) { 00039 boost::filesystem::path filename = _module_dirs[j]; 00040 filename /= config.module; 00041 00042 if(boost::filesystem::exists(filename)) { 00043 string modfile = filename.string(); 00044 factory_map::iterator fit = factories.find(modfile); 00045 ws_module_factory_ptr factory; 00046 00047 if(fit == factories.end()) { 00048 factory = new_module_factory(modfile); 00049 factories.insert(factory_map::value_type(modfile, factory)); 00050 } else { 00051 factory = fit->second; 00052 } 00053 00054 ws_module_ptr module(factory->new_module(ws_module_context_ptr(new WebServiceModuleContext(*this, _caller, config.type, config.properties)))); 00055 00056 if(module) { 00057 it = _module_map.insert(ws_module_map::value_type(config.name, 00058 ws_module_entry(factory, module))).first; 00059 super::add_service_type(module->ws_type()); 00060 00061 // Register request/response handlers; 00062 // TODO: report attempted overwrite of existing handler. 00063 // Eventually we'll allow multiple handlers for the same 00064 // message type and simply deliver messages to both handlers. 00065 for(message_handler_map::iterator it = module->request_begin(); 00066 it != module->request_end(); ++it) 00067 set_request_handler(*it); 00068 for(message_handler_map::iterator it = module->response_begin(); 00069 it != module->response_end(); ++it) 00070 set_response_handler(*it); 00071 } else 00072 throw LoadError(modfile); 00073 00074 break; 00075 } 00076 00077 ++j; 00078 } 00079 00080 if(j >= _module_dirs.size()) { 00081 string msg(config.module); 00082 throw LoadError(msg.append(" not found")); 00083 } 00084 } 00085 } 00086 00087 // Initialize actions. 00088 for(boost::ptr_vector<ActionConfig>::iterator action = _actions.begin(), 00089 end = _actions.end(); action != end; ++action) 00090 { 00091 ws_module_map::iterator it = _module_map.find(action->target); 00092 00093 // TODO: report missing module 00094 if(it != _module_map.end()) { 00095 call_handler_map::iterator handler = 00096 it->second.module->call_find(action->call); 00097 00098 // TODO: report missing handlers 00099 if(handler != it->second.module->call_end()) { 00100 set_action_handler(*action, handler->second); 00101 } 00102 } 00103 } 00104 } 00105 00106 __END_NS_SSRC_WSPR_WS
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.