📄 handbase.h
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
These sources, libraries and applications are
FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
as long as the following conditions are adhered to.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*____________________________________________________________________________*|
*
* $Source: /cvsroot/pi3web/Pi3Web_200/Source/Servlet/HandBase.h,v $
* $Date: 2003/05/13 18:42:18 $
*
Description:
\*____________________________________________________________________________*/
//$SourceTop:$
#ifndef HANDBASE_H_
#define HANDBASE_H_
#include <assert.h>
//#include "Pi2API.h"
#include "PIStrStr.h"
#include "PIHTTP.h"
#include "ServletContainer.h"
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
#define CONFIG_ERR(this, msg) \
{ PILog_addMessage( PIObject_getDB(this), \
PIObject_getConfigurationDB(this), PILOG_ERROR, "%s", (msg) ); }
#define KEY_CONF_SERVLETCONTEXT "Context"
#define KEY_CONF_CLASSNAME "ClassName"
#define KEY_CONF_SERVLETNAME "ServletName"
#define KEY_CONF_INITPARAM "Init"
#define KEY_CONF_EXTENDS "Extends"
#define KEY_CONF_SOURCEPATH "SourcePath"
#define KEY_CONF_OUTPUTPATH "OutputPath"
#define KEY_CONF_CLASSPATH "ClassPath"
#define KEY_CONF_ENCODING "JavaEncoding"
#define KEY_CONF_COMPILER "JavaCompiler"
#define DEFAULTEXTENDS "Pi3HttpJspPage"
/*____________________________________________________________________________*\
*
Class:
Description:
\*____________________________________________________________________________*/
class HandlerBaseServlet
{
// friend int HandlerBaseServlet_constructor( PIObject *pObj, HandlerBaseServlet *pHandler );
// friend PUBLIC_PIAPI int HandlerBaseServlet_destructor( PIObject *pObj, int, const char *[] );
private:
/* ---
Configuration data
--- */
static PIObject *pContainerObj; /* the servlet container */
static int ServletRefCount; /* servlet handler reference counter */
PIObject *pObject; /* the object */
int iOK; /* status */
const char *pLogName;
protected:
HandlerBaseServlet( const HandlerBaseServlet & ) { assert( 0 ); };
/* ---
Derived classes override this to handle parameters
--- */
virtual int Parameter( const char *pVariable, const char *pValue,
const char *pWhere )=0;
inline void SetOK( int iNewValue ) { iOK = iNewValue; };
inline const char *GetLogName() { return pLogName; };
static int ParameterFn( void *pData, const char *pVar, const char *pVal,
const char *pWhere )
{
assert( pData );
return ((HandlerBaseServlet *)pData)->Parameter( pVar, pVal,
pWhere ? pWhere : "" );
};
public:
HandlerBaseServlet( PIObject *pTheObject, const char *aLogName );
virtual ~HandlerBaseServlet();
virtual int Handle( int iPhase, PIHTTP &tPIHTTP, PIIOBuffer &tBuffer )=0;
virtual int Execute( int iArgc, const char *ppArgv[] );
inline int IsOK() { return iOK; };
inline PIObject *Object() { return pObject; };
void ReadParameters( int iArgc, const char *ppArgv[] );
inline ServletContainer *Context() {
return pContainerObj ? (ServletContainer *)PIObject_getUserData( pContainerObj ) : 0;
};
inline jobject SessionPool() {
return Context() ? Context()->SessionPool() : 0;
};
inline jobject ServletContext() {
return Context() ? Context()->ServletContext() : 0;
};
inline JavaVM *JVM() {
return Context() ? Context()->JVM() : 0;
};
inline JNIEnv *ENV() {
return Context() ? Context()->ENV() : 0;
};
inline int Log( PIHTTP *pPIHTTP, const char *msg, ... ) {
enum { BUF_SIZE=1024 };
char szBuf[BUF_SIZE];
va_list tvList;
va_start( tvList, msg );
vsprintf( &(szBuf[0]), msg, tvList );
va_end( tvList );
return Context() ? Context()->Log(pPIHTTP, &(szBuf[0]) ) : PIAPI_ERROR;
};
inline int Log( const char *msg, ... ) {
enum { BUF_SIZE=1024 };
char szBuf[BUF_SIZE];
va_list tvList;
va_start( tvList, msg );
vsprintf( &(szBuf[0]), msg, tvList );
va_end( tvList );
return Context() ? Context()->Log( &(szBuf[0]) ) : PIAPI_ERROR;
};
/* static inline void setContainerObject( PIObject *theServletContainer ) {
pContainerObj = theServletContainer;
};
static inline PIObject *getContainerObject() {
return pContainerObj;
};
*/
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Function prototypes
\*____________________________________________________________________________*/
PUBLIC_PIAPI int HandlerBaseServlet_execute( PIObject *pObj, int iArgc,
const char *ppArgv[] );
PUBLIC_PIAPI int HandlerBaseServlet_onClassLoad( PIClass_LoadAction eLoad,
PIDB *pDB );
int HandlerBaseServlet_constructor( PIObject *pObj,
HandlerBaseServlet *pHandler );
PUBLIC_PIAPI int HandlerBaseServlet_copyConstructor( PIObject *, int,
const char *[]);
PUBLIC_PIAPI int HandlerBaseServlet_destructor( PIObject *pObj, int,
const char *[] );
#endif /* HANDBASE_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -