Hitachi

VisiBroker Version 5 Borland(R) Enterprise Server VisiBroker(R) デベロッパーズガイド


9.2.3 _tie_Accountクラスを使用するためのサーバの変更(C++)

コードサンプル9-2に_tie_Accountクラスを使用する際に必要なServer.Cファイルの変更内容を示します。

コードサンプル9-2 _tieクラスを使用したサーバの例
#include "Bank_s.hh"
#include <math.h>
. . .
int main(int argc, char* const* argv) {
   try {
      // Initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
 
      // get a reference to the rootPOA
      PortableServer::POA_var rootPOA = 
            PortableServer::POA::_narrow(
            orb->resolve_initial_references("RootPOA"));
 
      CORBA::PolicyList policies;
      policies.length(1);
      policies[(CORBA::ULong)0] = 
            rootPOA->create_lifespan_policy(
            PortableServer::PERSISTENT);
 
      // get the POA Manager
      PortableServer::POAManager_var poa_manager = 
            rootPOA->the_POAManager();
 
      // Create myPOA with the right policies
      PortableServer::POA_var myPOA = 
            rootPOA->create_POA("bank_agent_poa",
            poa_manager, policies);
      // Create the servant
      AccountManagerImpl managerServant(rootPOA);
 
      // Create the delegator
      POA_Bank_AccountManager_tie<AccountManagerImpl> 
            tieServer(managerServant);
 
      // Decide on the ID for the servant
      PortableServer::ObjectId_var managerId = 
            PortableServer::string_to_ObjectId("BankManager");
 
      // Activate the servant with the ID on myPOA
      myPOA->activate_object_with_id(managerId, &tieServer);
 
      // Activate the POA Manager
      poa_manager->activate();
 
      cout << myPOA->servant_to_reference(&tieServer) << 
            "is ready" << endl;
 
      // Wait for incoming requests
      orb->run();
   } catch(const CORBA::Exception& e) {
      cerr << e << endl;
      return 1;
   }
   return 0;
}