Interstage Application Server アプリケーション作成ガイド (CORBAサービス編) |
目次
索引
![]() ![]() |
第5章 アプリケーションの開発(C++言語) | > 5.5 データ型に対するマッピング |
IDL言語で構造体structを指定した場合、C++言語でもstructにマッピングされます。
以降では、以下の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 ); }; };
struct samplefix{ // 構造体(固定長) CORBA::Long para1; CORBA::Long para2; } ; struct samplevar{ // 構造体(可変長) CORBA::Long para1; CORBA::String_var *para2; } ;
構造体(固定長)のパラメタ(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 );
クライアントアプリケーションのパラメタの扱いについて、以下に示します。
パラメタ |
サーバへ渡すパラメタ |
サーバから渡されたパラメタ |
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パラメタ
構造体(固定長)のパラメタ(in、out、inout)を扱う場合、構造体変数をパラメタに指定します。領域の獲得/解放を行う必要はありません。
以下にサーバアプリケーションでの処理例を示します。
ODsample::samplefix ODsample_structtest_impl::op2( const ODsample::samplefix &str1, ODsample::samplefix &str2, ODsample::samplefix &str3, CORBA::Environment &env ) throw( CORBA::Exception ) { // outパラメタ str2.para1 = 1; str2.para2 = 2; // inoutパラメタ str3.para1 = 11; str3.para2 = 12; // 復帰パラメタ ODsample::samplefix fix; fix.para1 = 21; fix.para2 = 22; return( fix ); }
サーバアプリケーションのパラメタの扱いについて、以下に示します。
パラメタ |
クライアントからのパラメタ領域 |
クライアントへのパラメタ領域 |
in |
スケルトンで自動的に獲得/解放されます。 |
− |
inout |
スケルトンで自動的に獲得されます。 |
渡されたパラメタに新しいデータを設定します(古い領域は解放され、新しいデータに置き換わります)。 |
out |
− |
構造体/可変長データの領域をnew/データ域獲得関数で獲得します。 |
以下にサーバアプリケーションでの処理例を示します。
ODsample_samplevar * ODsample_structtest_impl::op1( const ODsample_samplevar &str1, ODsample::samplevar *&str2, ODsample::samplevar &str3, CORBA::Environment &env ) throw( CORBA::Exception ) { // outパラメタ str2 = new ODsample::samplevar; // 領域獲得 str2->para1 = 12; // パラメタ設定 str2->para2 = (const CORBA::Char *)"aaa"; // inoutパラメタ str3->para1 = 4; // パラメタ設定 str3->para2 = ( const CORBA::Char *)"bbb"; // 復帰パラメタ ODsample::samplevar *smp = new ODsample::samplevar; // 領域獲得 smp->para1 = 5; // パラメタ設定 smp->para2 = ( const CORBA::Char *)"bbb"; return( smp ); }
目次
索引
![]() ![]() |