Interstage Application Server アプリケーション作成ガイド (CORBAサービス編)
目次 索引 前ページ次ページ

第5章 アプリケーションの開発(C++言語)> 5.2 データ型に対するマッピング

5.2.2 文字列型

(1)IDLマッピング

 IDL言語で文字列型stringを指定した場合、C++言語ではCORBA::Char *にマッピングされます。
 以降では、以下のIDL定義例をもとに説明します。

IDL言語

  module ODsample{
      interface  stringtest{
         string op1(in string str1, out string str2, inout string str3); 
      };
  };

C++言語

  CORBA::Char *
  ODsample::stringtest::op1(
      const CORBA::Char *str1,      // inパラメタ
      CORBA::Char  *&str2,          // outパラメタ
      CORBA::Char  *&str3,          // inoutパラメタ
      CORBA::Environment  &env )    // 例外情報

(2)クライアントアプリケーションで扱うパラメタ

 クライアントアプリケーションのパラメタの扱いについて、以下に示します。

パラメタ

サーバへ渡すパラメタ

サーバから渡されたパラメタ

in

CORBA::string_alloc()で領域を獲得します。

inout

(inパラメタと同じ)

領域はスタブで自動的に獲得されます。

out
復帰

(inoutパラメタと同じ)

注意事項

 クライアントおよびスタブで獲得した領域は、不要になった時点でCORBA::string_free()で解放する必要があります。

 以下にクライアントアプリケーションでの処理例を示します。

  CORBA::Environment  env; 
  CORBA::Char         *str1, *str2, *str3, *ret; 

  // inパラメタ
      str1 = CORBA::string_alloc(2);          // 領域獲得
      strcpy( str1 ,"IN" );                   // パラメタ設定

  // inoutパラメタ
      str3 = CORBA::string_alloc(7);          // 領域獲得
      strcpy( str3 ,"INOUT:1" );              // パラメタ設定

  // サーバ呼出し
      ret = obj->op1( str1, str2, str3, env );

  // 領域解放
      CORBA::string_free( ret );              // 復帰パラメタ
      CORBA::string_free( str1 );             // inパラメタ
      CORBA::string_free( str2 );             // outパラメタ
      CORBA::string_free( str3 );             // inoutパラメタ

目次 索引 前ページ次ページ

Copyright 2006 FUJITSU LIMITED