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

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

4.7.2 文字列型

(1)IDLマッピング

 IDL言語で文字列型stringを指定した場合、C言語ではCORBA_stringにマッピングされます。CORBA_stringは以下のように定義されます。

  typedef  char  *CORBA_string;    /* stringの定義*/

 以降では、以下のIDL定義例をもとに説明します。

IDL言語

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

C言語

  CORBA_string
  ODsample_stringtest_op1(
      ODsample_stringtest obj;   /* オブジェクトリファレンス */
      CORBA_string str1,         /* inパラメタ */
      CORBA_string *str2,        /* outパラメタ */
      CORBA_string *str3,        /* inoutパラメタ */
      CORBA_Environment *env )   /* 例外情報 */

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

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

パラメタ

サーバへ渡すパラメタ

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

in

CORBA_string_alloc()で領域を獲得します。

inout

(inパラメタと同じ)

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

out
復帰

(inoutパラメタと同じ)

注意事項

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

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

  CORBA_string          str1, str2, str3, ret;
  CORBA_Environment     env;

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

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

  /* サーバ呼出し */
  ret = ODsample_stringtest_op1(obj, str1, &str2, &str3, &env );

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

(3)サーバアプリケーションで扱うパラメタ

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

パラメタ

クライアントから渡されたパラメタ

クライアントへ渡すパラメタ

in

文字列域はスケルトンで自動的に獲得/解放されます。

inout

文字列域はスケルトンで自動的に獲得されます。

渡されたパラメタより短い文字列を返す場合:
 渡された文字列域に文字列を設定します。

渡されたパラメタより長い文字列を返す場合:
 渡された文字列域をCORBA_free()で一度解放し、CORBA_string_alloc()で再獲得します。

文字列域はスケルトンで自動的に解放されます。

out
復帰

文字列域をCORBA_string_alloc()で獲得します。文字列域はスケルトンで自動的に解放されます。

 以下にサーバアプリケーションでの処理例を示します。

  CORBA_string
  ODsample_stringtest_op1(
      ODsample_stringtest obj;         /* オブジェクトリファレンス */
      CORBA_string str1,               /* inパラメタ */
      CORBA_string *str2,              /* outパラメタ */
      CORBA_string *str3,              /* inoutパラメタ */
      CORBA_Environment *env )         /* 例外情報 */
  {
      CORBA_string str; 

  /* outパラメタ */
      *str2 = CORBA_string_alloc(3);   /* 領域獲得 */
      strcpy( *str2, "OUT" );          /* パラメタ設定 */

  /* inoutパラメタ */
      CORBA_free( *str3 );             /* 領域解放 */
      *str3 = CORBA_string_alloc(7);   /* 領域再獲得 */
      strcpy( *str3, "INOUT:2" );      /* パラメタ設定 */

  /* 復帰パラメタ */
      str = CORBA_string_alloc(6);     /* 領域獲得 */
      strcpy( str, "RETURN" );         /* 復帰パラメタ設定 */
      return( str ); 
  }

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

All Rights Reserved, Copyright(C) 富士通株式会社 2005