понедельник, 11 мая 2009 г.

Надо портировать клиента на другую платформу

#include "Bank_c.hh"
#include "firewall_c.hh"
#if defined(_VIS_STD)
# include <fstream>
#else
# include <fstream.h>
#endif

// USE_STD_NS is a define setup by VisiBroker to use the std namespace
USE_STD_NS

void print_usage_and_exit()
{
cout << "Usage: client normal|passthru [account name]" << endl;
exit(1);
}

const int MAXBUF = 1024;

int main(int argc, char* const* argv)
{
try {
if (argc < 2)
print_usage_and_exit();

// Initialize the ORB
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

// Create the firewall support policy
CORBA::Any proxy_policy_value;
proxy_policy_value <<= QoSExt::USE_PROXY;
CORBA::Policy_var proxy_policy = orb->create_policy(
QoSExt::FIREWALL_PROXY_POLICY, proxy_policy_value);

// Create the proxy mode policy
QoSExt::ProxyModePolicyValue proxy_mode;
if (strcmp(argv[1], "passthru") == 0)
proxy_mode = QoSExt::PASS_THROUGH;
else if (strcmp(argv[1], "normal") == 0)
proxy_mode = QoSExt::NORMAL;
else
print_usage_and_exit();
CORBA::Any mode_policy_value;
mode_policy_value <<= proxy_mode;
CORBA::Policy_var mode_policy = orb->create_policy(
QoSExt::PROXY_MODE_POLICY, mode_policy_value);

// Enable the policies on the ORB level
CORBA::PolicyList policies;
policies.length(2);
policies[0] = CORBA::Policy::_duplicate(proxy_policy);
policies[1] = CORBA::Policy::_duplicate(mode_policy);
CORBA::Object_var obj = orb->resolve_initial_references("ORBPolicyManager");
CORBA::PolicyManager_var policy_mgr = CORBA::PolicyManager::_narrow(obj);
policy_mgr->set_policy_overrides(policies, CORBA::ADD_OVERRIDE);

// Resolve account manager reference from the file
ifstream in("ior.dat");
char ior[MAXBUF];
in.getline(ior, MAXBUF);
in.close();
CORBA::Object_var object = orb->string_to_object(ior);
Bank::AccountManager_var manager = Bank::AccountManager::_narrow(object);

// Request the account manager to open a named account
const char* name = argc > 2 ? argv[2] : "Jack B. Quick";
Bank::Account_var account = manager->open(name);

// Get the balance of the account
CORBA::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;
return 1;
}

return 0;
}

Комментариев нет:

Отправить комментарий