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

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

5.2.6 構造体

(1)IDLマッピング

 IDL言語で構造体structを指定した場合、C++言語でもstructにマッピングされます。
 以降では、以下のIDL定義例をもとに説明します。

IDL言語

  module ODsample{
      struct samplefix {  // 構造体(固定長) 
          long    para1; 
          long    para2; 
      };
      struct samplevar {  // 構造体(可変長) 
          long    para1; 
          string  para2; 
      };
      interface  structtest{
          samplefix  op2(
                         in samplefix str1, 
                         out samplefix str2, 
                         inout samplefix str3 
          ); 
          samplevar  op1(
                         in samplevar str1, 
                         out samplevar str2, 
                         inout samplevar str3 
          ); 
      };
  };

C++言語

  struct samplefix{    // 構造体(固定長) 
      CORBA::Long    para1; 
      CORBA::Long    para2; 
  } ; 

  struct samplevar{    // 構造体(可変長) 
      CORBA::Long        para1; 
      CORBA::String_var  *para2; 
  } ;

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

 構造体(固定長)のパラメタ(in、out、inout)を扱う場合、構造体変数をパラメタに指定します。領域の獲得/解放を行う必要はありません。

      ODsample::samplefix    strf0, strf1, strf2, strf3; 
      CORBA::Environment     env; 
      ODsample::structtest_ptr    obj; 

  // inパラメタ
      strf1.para1 = 10;      // パラメタ設定
      strf1.para2 = 11;

  // inoutパラメタ
      strf3.para1 = 20;      // パラメタ設定
      strf3.para2 = 21;

  // サーバ呼出し
      fix0 = obj->op2( fix1, fix2, fix3, env );

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

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

パラメタ

サーバへ渡すパラメタ

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

in

領域を動的に獲得する場合は、new、データ域獲得関数を使用します。

inout

(inパラメタと同じ)

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

out
復帰

(inoutパラメタと同じ)

注意事項

 クライアントおよびスタブで動的に獲得した領域は、不要になった時点でdelete(C++演算子)で解放する必要があります。deleteを発行すると、構造体の可変長領域も解放されます。

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

      ODsample_samplevar         *str0, str1, *str2, str3; 
      CORBA::Environment         env; 
      ODsample::structtest_ptr   obj; 

  // inパラメタ
      str1.para1 = 5;                             // パラメタ設定
      str1.para2 = (const CORBA::Char *)"xxxx";

  // inoutパラメタ
      str3.para1 = 6;                             // パラメタ設定
      CORBA::Char *str = CORBA::sring_alloc(6);   // 領域獲得
      strcpy( str, "yyyyy" ); 
      str3.para2 = str;                           // パラメタ設定

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

  // 領域解放
      delete( str0 );                             // 復帰パラメタ
      delete( str2 );                             // outパラメタ

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

Copyright 2006 FUJITSU LIMITED