4.4.1 Client.C

Clientプログラムは,bankのアカウントの現在の残高を取得するクライアントアプリケーションをインプリメントします。bankクライアントプログラムは次の手順を実行します。

  1. VisiBroker ORBを初期化します。
  2. AccountManagerオブジェクトにバインドします。
  3. bind()メソッドが返すオブジェクトリファレンスを使用して,Accountの残高を取得します。
  4. Accountオブジェクトでbalanceを呼び出して,残高を取得します。
コードサンプル4-1 クライアント側のプログラム(C++)

#include "Bank_c.hh"
int main(int argc, char* const* argv) {
  try {
     // Initialize the ORB.
     CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv);
     // Get the manager Id
     PortableServer::ObjectId_var managerId =
           PortableServer::string_to_ObjectId("BankManager");
     // Locate an account manager. Give the full POA name and
     // the servant ID.
     Bank::AccountManager_ptr manager =
     Bank::AccountManager::_bind(
           "/bank_agent_poa", managerId);
     // use argv[1] as the account name, or a default.
     const char* name = argc > 1 ? argv[1] : "Jack B. Quick";
     // Request the account manager to open a named account.
     Bank::Account_ptr account = manager->open(name);
     // Get the balance of the account.
     float balance = account->balance();
     // Print out the balance.
     cout << "The balance in "<< name << "'s account is $"
           << balance << endl;
  } catch(const CORBA::Exception& e) {
    cerr << e << endl;
  }
}