ページの先頭行へ戻る
Interstage Application Server アプリケーション作成ガイド(CORBAサービス編)
Interstage

11.10.4 出口関数の例

本節では、C言語/C++言語のそれぞれについて、出口関数を使用する場合のプログラミング例とその出力結果を示します。


C言語の場合


(1) プログラミング例

C言語を使用した場合のサーバアプリケーションのプログラミング例を以下に示します。

/* 出口関数 */
void
exitfunc()
{
printf( "exitfunc is called.\n" );


return;
} /* インタフェース実装関数 */ CORBA_long ODsample_intf1_op1( ODsample_intf1 obj, CORBA_long l, CORBA_Environment *env ) { printf( "ODsample_intf1_op1 is called.\n" ); return 0; } /* main */ int main( int argc, char *argv[] ) { CORBA_ORB orb; CORBA_BOA boa; CORBA_ImplementationDef impl; CORBA_Environment env; orb = CORBA_ORB_init( &argc, argv, FJ_OM_ORBid, &env ); CORBA_ORB_register_reply_interceptor( orb, exitfunc, &env ); ... /* 中略 */ CORBA_BOA_impl_is_ready( boa, impl, &env ); return 0; }

(2) 出力結果

上記のサーバアプリケーション(インタフェース実装関数)に対してリクエストを送信した場合、サーバアプリケーションの出力結果は以下のようになります。

ODsample_intf1_op1 is called.
exitfunc is called.

C++言語の場合


(1)プログラミング例

C++言語を使用した場合のサーバアプリケーションのプログラミング例(出口関数としてメンバ関数を使用する場合)を以下に示します。

/* 出口関数 */
class MyClass
{
public:
    static void exitfunc()
    {
        printf( "MyClass::exitfunc is called.\n" );

        return;
    }
};

/* インタフェース実装関数 */
CORBA::Long
ODsample_intf1_impl::op1(
    CORBA::Long         l,
    CORBA::Environment  &env )
    throw( CORBA::Exception )
{
    printf( "ODsample_intf1_impl::op1 is called.\n" );

    return 0;
}

/* main */
int
main( int argc, char *argv[] )
{
    CORBA::ORB_ptr  orb;
    CORBA::BOA_ptr  boa;
    CORBA::ImplementationDef_ptr  impl;
    CORBA::Environment_ptr        env = new CORBA::Environment;

    try {
        orb = CORBA::ORB_init( argc, argv, FJ_OM_ORBid, *env );

        orb->register_reply_interceptor( MyClass::exitfunc, *env );

        ...  /* 中略 */

        boa->impl_is_ready( impl, *env );
    }
    catch ( CORBA::SystemException &se ) {
        printf( "SystemException raised!\n" );
        return 1;
    }
    catch ( CORBA::Exception &e ) {
        printf( "Exception raised!\n" );
        return 1;
    }

    delete env;

    return 0;
}

(2) 出力結果

上記のサーバアプリケーション(インタフェース実装関数)に対してリクエストを送信した場合、サーバアプリケーションの出力結果は以下のようになります。

ODsample_intf1_impl::op1 is called.
Myclass::exitfunc is called.