Interstage Application Server アプリケーション作成ガイド (CORBAサービス編) |
目次
索引
![]() ![]() |
第4章 アプリケーションの開発(C言語) | > 4.8 データ型に対するマッピング |
IDL言語で文字列型wstringを指定した場合、C言語ではCORBA_wstringにマッピングされます。CORBA_wstringは以下のように定義されています。
typedef CORBA_wchar *CORBA_wstring;
以下のIDL定義例をもとに説明します。
module ODsample{ interface wstringtest{ wstring op1(in wstring str1, out wstring str2, inout wstring str3); }; };
CORBA_wstring ODsample_wstringtest_op1( ODsample_wstringtest obj; /* オブジェクトリファレンス */ CORBA_wstring str1, /* inパラメタ */ CORBA_wstring *str2, /* outパラメタ */ CORBA_wstring *str3, /* inoutパラメタ */ CORBA_Environment *env ) /* 例外情報 */
クライアントアプリケーションのパラメタの扱いについて、以下に示します。
パラメタ |
サーバへ渡すパラメタ |
サーバから渡されたパラメタ |
in |
CORBA_wstring_alloc()で領域を獲得します。 |
− |
inout |
(inパラメタと同じ) |
領域はスタブで自動的に獲得されます。 |
out |
− |
(inoutパラメタと同じ) |
クライアントおよびスタブで獲得した領域は、不要になった時点でCORBA_free()で解放する必要があります。
以下にクライアントアプリケーションでの処理例を示します。
CORBA_wstring str1, str2, str3, ret; CORBA_Environment env; /* inパラメタ */ str1 = CORBA_wstring_alloc(2); /* 領域獲得 */ str1[0] = ...; /* パラメタ設定(“(4)文字列の設定方法”参照) */ : /* inoutパラメタ */ str3 = CORBA_wstring_alloc(5); /* 領域獲得 */ str3[0] = ...; /* パラメタ設定(“(4)文字列の設定方法”参照) */ : /* サーバ呼出し */ ret = ODsample_wstringtest_op1(obj, str1, &str2, &str3, &env ); /* 領域解放 */ CORBA_free( str1 ); /* inパラメタ */ CORBA_free( str2 ); /* outパラメタ */ CORBA_free( str3 ); /* inoutパラメタ */ CORBA_free( ret ); /* 復帰パラメタ */
サーバアプリケーションのパラメタの扱いについて、以下に示します。
パラメタ |
クライアントから渡されたパラメタ |
クライアントへ渡すパラメタ |
in |
文字列域はスケルトンで自動的に獲得/解放されます。 |
− |
inout |
文字列域はスケルトンで自動的に獲得されます。 |
渡されたパラメタより短い文字列を返す場合: 渡されたパラメタより長い文字列を返す場合: 文字列域はスケルトンで自動的に解放されます。 |
out |
− |
文字列域をCORBA_wstring_alloc()で獲得します。文字列域はスケルトンで自動的に解放されます。 |
以下にサーバアプリケーションでの処理例を示します。
CORBA_wstring ODsample_wstringtest_op1( ODsample_stringtest obj; /* オブジェクトリファレンス */ CORBA_wstring wstr1, /* inパラメタ */ CORBA_wstring *wstr2, /* outパラメタ */ CORBA_wstring *wstr3, /* inoutパラメタ */ CORBA_Environment *env ) /* 例外情報 */ { CORBA_wstring wstr; /* outパラメタ */ *wstr2 = CORBA_wstring_alloc(3); /* 領域獲得 */ (*wstr2)[0] = ...; /* パラメタ設定:(4)参照 */ : /* inoutパラメタ */ CORBA_free( *wstr3 ); /* 領域解放 */ *wstr3 = CORBA_wstring_alloc(5); /* 領域再獲得 */ (*wstr3)[0] = ...; /* パラメタ設定:(4)参照 */ : /* 復帰パラメタ */ wstr = CORBA_wstring_alloc(4); /* 領域獲得 */ wstr[0] = ...; /* パラメタ設定:(4)参照 */ : return( str ); }
ワイド文字列型への文字列の設定方法を以下に示します(変数wstrはCORBA_wchar*型です)。
文字を1文字ずつ設定します(EUCの場合)。
wstr[0] = 0xc6fc; /* "日" */ wstr[1] = 0xcbdc; /* "本" */ wstr[2] = 0xb8ec; /* "語" */ wstr[3] = 0x0000; /* 終端子 */
""で囲んだ文字列にL修飾子を付けるとUNICODEになります。
wstr = L"日本語";
UNICODEの値を1文字ずつ直接数値で設定します。
wstr[0] = 0x65e5; /* "日" */ wstr[1] = 0x672c; /* "本" */ wstr[2] = 0x8a9e; /* "語" */ wstr[3] = 0x0000; /* 終端子 */
Solaris OEシステム、Linuxシステムでは、L"..."の形式の文字列を処理することはできません。
目次
索引
![]() ![]() |