Savarese Software Research Corporation
ServletRunner.h
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 
00022 #ifndef __SSRC_WSPR_FCGI_LUA_SERVLET_RUNNER_H
00023 #define __SSRC_WSPR_FCGI_LUA_SERVLET_RUNNER_H
00024 
00025 #include <vector>
00026 
00027 #include <ssrc/wispers/service/service.h>
00028 #include <ssrc/wispers/fcgi/FCGIResponse.h>
00029 #include <ssrc/wispers/fcgi/FCGIServiceInitializer.h>
00030 #include <ssrc/wispers/utility/LoadError.h>
00031 
00032 #include <ssrc/wispers/lua/lua.h>
00033 
00034 __BEGIN_NS_SSRC_WSPR_FCGI_LUA
00035 
00036 using std::string;
00037 using NS_SSRC_WSPR_SERVICE::ServiceProtocolProcessor;
00038 using NS_SSRC_WSPR_FCGI::fcgx_request_ptr;
00039 using NS_SSRC_WSPR_FCGI::MethodNum;
00040 using NS_SSRC_WSPR_FCGI::FCGIRequest;
00041 using NS_SSRC_WSPR_FCGI::FCGIResponse;
00042 using NS_SSRC_WSPR_UTILITY::LoadError;
00043 
00044 struct ServletRunnerInitializer : NS_SSRC_WSPR_FCGI::FCGIServiceInitializer {
00045   typedef std::vector<string> module_dir_list;
00046 
00048   string servlet_file;
00049 
00051   module_dir_list module_dirs;
00052 };
00053 
00058 class ServletRunner : public ServiceProtocolProcessor {
00059   typedef ServiceProtocolProcessor super;
00060 
00061   WISP_IMPORT(ServletRunnerInitializer, module_dir_list);
00062 
00063   Lua::lua_State *_lua_state;
00064   int _method_ref[MethodNum];
00065 
00066   void load_servlet(const string & servlet_file) SSRC_DECL_THROW(LoadError);
00067 
00068   virtual void transition(State state);
00069 
00070   static const char * const ServletFunctions[MethodNum];
00071 
00072 public:
00073   typedef FCGIRequest request_type;
00074   typedef FCGIResponse response_type;
00075   typedef boost::shared_ptr<request_type> request_ptr;
00076   typedef boost::shared_ptr<response_type> response_ptr;
00077 
00078   ServletRunner(caller_type & caller,
00079                 const ServletRunnerInitializer & initializer)
00080     SSRC_DECL_THROW(LoadError);
00081 
00082   ~ServletRunner();
00083 
00084   void process_fcgi_request(const fcgx_request_ptr & request);
00085 };
00086 
00087 __END_NS_SSRC_WSPR_FCGI_LUA
00088 
00089 #endif

Savarese Software Research Corporation
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.