| Interstage Application Server アプリケーション作成ガイド (CORBAサービス編) | 
			目次
			索引
			![]()  
		 | 
	
| 第5章 アプリケーションの開発(C++言語) | > 5.5 データ型に対するマッピング | 
 IDL言語で文字列型stringを指定した場合、C++言語ではCORBA::Char *にマッピングされます。
 以降では、以下のIDL定義例をもとに説明します。
  module ODsample{
      interface  stringtest{
         string op1(in string str1, out string str2, inout string str3); 
      };
  };
  CORBA::Char *
  ODsample::stringtest::op1(
      const CORBA::Char *str1,      // inパラメタ
      CORBA::Char  *&str2,          // outパラメタ
      CORBA::Char  *&str3,          // inoutパラメタ
      CORBA::Environment  &env )    // 例外情報
クライアントアプリケーションのパラメタの扱いについて、以下に示します。
| 
 パラメタ  | 
 サーバへ渡すパラメタ  | 
 サーバから渡されたパラメタ  | 
| 
 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パラメタ
サーバアプリケーションのパラメタの扱いについて、以下に示します。
| 
 パラメタ  | 
 クライアントから渡されたパラメタ  | 
 クライアントへ渡すパラメタ  | 
| 
 in  | 
 領域はスケルトンで自動的に獲得/解放されます。  | 
 −  | 
| 
 inout  | 
 領域はスケルトンで自動的に獲得されます。  | 
 渡されたパラメタより短い文字列を返す場合: 渡されたパラメタより長い文字列を返す場合: 渡した領域はスケルトンで自動的に解放されます。  | 
| 
 out  | 
 −  | 
 領域はCORBA::string_alloc()で獲得します。  | 
以下にサーバアプリケーションでの処理例を示します。
  CORBA::Char *
  ODsample_stringtest_impl::op1(
      const CORBA::Char  *str1,          // inパラメタ
      CORBA::Char        *&str2,         // outパラメタ
      CORBA::Char        *&str3,         // inoutパラメタ
      CORBA::Environment &env )          // 例外情報
      throws( CORBA::Exception ) 
  {
  // outパラメタ
      str2 = CORBA::string_alloc(3);     // 領域獲得
      strcpy( str2, "OUT" );             // パラメタ設定
  // inoutパラメタ
      CORBA::string_free( str3 );        // 領域解放
      str3 = CORBA::string_alloc(7);     // 領域再獲得
      strcpy( str3, "INOUT:2" );         // パラメタ設定
  // 復帰パラメタ
      str = CORBA::string_alloc(6);      // 領域獲得
      strcpy( str, "RETURN" );           // パラメタ設定
      return( str ); 
  } 
			目次
			索引
			![]()  
		 |