![]() ![]() ![]() ![]() ![]() ![]() ![]() |
この付録では、インターセプタの実装を開始する際に使用できる次のコードを示します。
このコードを使用する場合は、YourInterceptor
を実装しているインターセプタの名前に置き換えてください。
#if defined(WIN32)
#include <windows.h>
#endif
#include <ctype.h>
#include "YourInterceptor
.h"
// Cleanup class -- suggested
class Cleanup
{
public:
Cleanup() {}
~Cleanup()
{
// <<<Fill in your code here>>>
}
};
static Cleanup CleanupOnImageExit;
#define SECURITY_BUFFSIZE 100
#if defined(WIN32)
// suggestion for standard DLL processing
BOOL WINAPI DllMain( HANDLE hDLL,
DWORD dwReason,
LPVOID lpReserved )
{
switch( dwReason )
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
// Return that the operation was successful
return( TRUE );
}
#endif /* WIN32 */
/*************************************************************
FUNCTION NAME:YourInterceptor
Init
FUNCTIONAL DESCRIPTION:
Initialization routine called by the ORB during initialization.
This routine will create and return instances of the
RequestLevelInterceptor classes that it supports.
NOTE: An interceptor library can support more than one set of
interceptors by supplying multiple initialization entry points
(each initialization entry must be separately registered with the
ORB) Also, it is legal for only one kind of interceptor to be
supplied (i.e. only a client or only a target.)
***************************************************************/
#ifdef WIN32
extern "C" __declspec(dllexport) void __cdecl
#else
extern "C" void
#endifYourInterceptor
Init(
CORBA::ORB_ptr TheORB,
RequestLevelInterceptor::ClientRequestInterceptor ** ClientPtr,
RequestLevelInterceptor::TargetRequestInterceptor ** TargetPtr,
CORBA::Boolean * RetStatus)
{
// <<<Fill in your code here>>>
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Client constructor
FUNCTIONAL DESCRIPTION:
***************************************************************/YourInterceptor
Client::YourInterceptor
Client(CORBA::ORB_ptr TheOrb)
{
// This next line is useful, but not absolutely necessary.
m_orb = TheOrb;
// <<<Fill in your code here>>>
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Client::shutdown
FUNCTIONAL DESCRIPTION:
The shutdown operation is used by the ORB to notify an
implementation of an interceptor that the interceptor
is being shutdown. The ORB will destroy the instance
of the interceptor once control is returned from the
operation back to the ORB.
***************************************************************/
Interceptors::ShutdownReturnStatusYourInterceptor
Client::shutdown(
Interceptors::ShutdownReason reason,
CORBA::Exception_ptr & excep_val)
{
// The following lines are a suggestion only. Replace them if you wish.
Interceptors::ShutdownReturnStatus ret_status = Interceptors::SHUTDOWN_NO_EXCEPTION;
switch (reason)
{
case Interceptors::ORB_SHUTDOWN:
// <<<Fill in your code here>>>
break;
case Interceptors::CONNECTION_ABORTED:
// <<<Fill in your code here>>>
break;
case Interceptors::RESOURCES_EXCEEDED:
// <<<Fill in your code here>>>
break;
}
return ret_status;
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Client::id
FUNCTIONAL DESCRIPTION:
The id accessor operation is used by the ORB to obtain
the vendor assigned identity of the interceptor as a string
value. This attribute is used primarily for debugging and
tracing of operations on the interceptors called by the ORB.
***************************************************************/
CORBA::StringYourInterceptor
Client::id()
{
// <<<Fill in your code here>>>
// The next line is a possible implementation that is useful
return CORBA::string_dup("YourInterceptor
Client");
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Client::exception_occurred
FUNCTIONAL DESCRIPTION:
The exception_occurred operation is called on a request-level
interceptor implementation when an exception occurs.
It is called instead of the <xxx>_response
method of that interceptor. The ORB calls this operation to
allow the interceptor implementation to clean-up any state
that it might have been managing that is specific to a request.
***************************************************************/
voidYourInterceptor
Client::exception_occurred (
const RequestLevelInterceptor::ReplyContext & reply_context,
CORBA::Exception_ptr excep_val)
{
// <<<Fill in your code here>>>
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Client::client_invoke
FUNCTIONAL DESCRIPTION:
This operation is called by the ORB anytime that an
invocation is being sent to a target object, regardless
of whether the target object is in a different address
space or the same address space as the target object.
***************************************************************/
Interceptors::InvokeReturnStatusYourInterceptor
Client::client_invoke (
const RequestLevelInterceptor::RequestContext & request_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr request_arg_stream,
CORBA::DataOutputStream_ptr reply_arg_stream,
CORBA::Exception_ptr & excep_val)
{
// The next line is a suggestion that works in conjunction with the last line below
Interceptors::InvokeReturnStatus ret_status = Interceptors::INVOKE_NO_EXCEPTION;
// <<<Fill in your code here>>>
return ret_status;
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Client::client_response
FUNCTIONAL DESCRIPTION:
The operation is called by the ORB anytime that a reply
to an invocation is being received by the initiator of
the request, regardless of whether the initiator is in
a different address space or the same address space as
the target object.
***************************************************************/
Interceptors::ResponseReturnStatusYourInterceptor
Client::client_response (
const RequestLevelInterceptor::ReplyContext & reply_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr arg_stream,
CORBA::Exception_ptr & excep_val)
{
// The next line is a suggestion that works in conjunction with the last line below
// See the examples for other suggestions of general use
Interceptors::ResponseReturnStatus ret_status = Interceptors::RESPONSE_NO_EXCEPTION;
// <<<Fill in your code here>>>
return ret_status;
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Target constructor
FUNCTIONAL DESCRIPTION:
This function constructs the target interceptor instance.
This example provides data members that could be used to
implement a security interceptor.
***************************************************************/YourInterceptor
Target::YourInterceptor
Target(CORBA::ORB_ptr TheOrb) :
m_orb(TheOrb), // suggestion
m_security_current(0), // suggestion for security interceptors
m_attributes_to_get(0) // suggestion for security interceptors
{
// <<<Fill in your code here>>>
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Target::shutdown
FUNCTIONAL DESCRIPTION:
The shutdown operation is used by the ORB to notify an
implementation of an interceptor that the interceptor
is being shutdown. The ORB will destroy the instance
of the interceptor once control is returned from the
operation back to the ORB.
***************************************************************/
Interceptors::ShutdownReturnStatusYourInterceptor
Target::shutdown(
Interceptors::ShutdownReason reason,
CORBA::Exception_ptr & excep_val)
{
// <<<Fill in your code here>>>
// The following lines are a suggestion only. Replace them if you wish.
Interceptors::ShutdownReturnStatus ret_status = Interceptors::SHUTDOWN_NO_EXCEPTION;
switch (reason)
{
case Interceptors::ORB_SHUTDOWN:
// <<<Fill in your code here>>>
break;
case Interceptors::CONNECTION_ABORTED:
// <<<Fill in your code here>>>
break;
case Interceptors::RESOURCES_EXCEEDED:
// <<<Fill in your code here>>>
break;
}
return ret_status;
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Target::id
FUNCTIONAL DESCRIPTION:
The id accessor operation is used by the ORB to obtain
the vendor assigned identity of the interceptor as a string
value. This attribute is used primarily for debugging and
tracing of operations on the interceptors called by the ORB.
***************************************************************/
CORBA::StringYourInterceptor
Target::id()
{
// <<<Fill in your code here>>>
// The next line is a possible implementation that is useful
return CORBA::string_dup("YourInterceptor
Target");
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Target::exception_occurred
FUNCTIONAL DESCRIPTION:
The exception_occurred operation is called on a request-level
interceptor implementation when an exception occurs.
It is called instead of the <xxx>_response
method of that interceptor. The ORB calls this operation to
allow the interceptor implementation to clean-up any state
that it might have been managing that is specific to a request.
***************************************************************/
voidYourInterceptor
Target::exception_occurred (
const RequestLevelInterceptor::ReplyContext & reply_context,
CORBA::Exception_ptr excep_val)
{
// <<<Fill in your code here>>>
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Target::target_invoke
FUNCTIONAL DESCRIPTION:
The operation is called by the ORB anytime that an
invocation is being received by a target object,
regardless of whether the target object is in a
different address space or the same address space
as the target object.
***************************************************************/
Interceptors::InvokeReturnStatusYourInterceptor
Target::target_invoke (
const RequestLevelInterceptor::RequestContext & request_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr request_arg_stream,
CORBA::DataOutputStream_ptr reply_arg_stream,
CORBA::Exception_ptr & excep_val)
{
// The next line is a suggestion that works in conjunction with the last line below
Interceptors::InvokeReturnStatus ret_status = Interceptors::INVOKE_NO_EXCEPTION;
// <<<Fill in your code here>>>
return ret_status;
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Target::target_response
FUNCTIONAL DESCRIPTION:
The operation is called by the ORB anytime that a reply
to an invocation is being sent to the initiator of the
request, regardless of whether the initiator is in a
different address space or the same address space as
the target object.
***************************************************************/
Interceptors::ResponseReturnStatusYourInterceptor
Target::target_response (
const RequestLevelInterceptor::ReplyContext & reply_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr arg_stream,
CORBA::Exception_ptr & excep_val)
{
// The next line is a suggestion that works in conjunction with the last line below
Interceptors::ResponseReturnStatus ret_status = Interceptors::RESPONSE_NO_EXCEPTION;
// <<<Fill in your code here>>>
return ret_status;
}
/*************************************************************
FUNCTION NAME:YourInterceptor
Target destructor
FUNCTIONAL DESCRIPTION:
***************************************************************/YourInterceptor
Target::~YourInterceptor
Target()
{
// <<<Fill in your code here>>>
}
#include <CORBA.h>
#include <RequestLevelInterceptor.h>
#include <security_c.h> //used with security
classYourInterceptor
Client : public virtual RequestLevelInterceptor::ClientRequestInterceptor
{
private:
YourInterceptor
Client() {}
CORBA::ORB_ptr m_orb;
public:
YourInterceptor
Client(CORBA::ORB_ptr TheOrb);
~YourInterceptor
Client() {}
Interceptors::ShutdownReturnStatus shutdown(
Interceptors::ShutdownReason reason,
CORBA::Exception_ptr & excep_val);
CORBA::String id();
void exception_occurred (
const RequestLevelInterceptor::ReplyContext & reply_context,
CORBA::Exception_ptr excep_val);
Interceptors::InvokeReturnStatus client_invoke (
const RequestLevelInterceptor::RequestContext & request_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr request_arg_stream,
CORBA::DataOutputStream_ptr reply_arg_stream,
CORBA::Exception_ptr & excep_val);
Interceptors::ResponseReturnStatus client_response (
const RequestLevelInterceptor::ReplyContext & reply_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr arg_stream,
CORBA::Exception_ptr & excep_val);
};
classYourInterceptor
Target : public virtual RequestLevelInterceptor::TargetRequestInterceptor
{
private:
YourInterceptor
Target() {}
CORBA::ORB_ptr m_orb;
SecurityLevel1::Current_ptr m_security_current; //used with security
Security::AttributeTypeList * m_attributes_to_get; //used with security
public:
YourInterceptor
Target(CORBA::ORB_ptr TheOrb);
~YourInterceptor
Target();
Interceptors::ShutdownReturnStatus shutdown(
Interceptors::ShutdownReason reason,
CORBA::Exception_ptr & excep_val);
CORBA::String id();
void exception_occurred (
const RequestLevelInterceptor::ReplyContext & reply_context,
CORBA::Exception_ptr excep_val);
Interceptors::InvokeReturnStatus target_invoke (
const RequestLevelInterceptor::RequestContext & request_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr request_arg_stream,
CORBA::DataOutputStream_ptr reply_arg_stream,
CORBA::Exception_ptr & excep_val);
Interceptors::ResponseReturnStatus target_response (
const RequestLevelInterceptor::ReplyContext & reply_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr arg_stream,
CORBA::Exception_ptr & excep_val);
};
![]() ![]() ![]() |