⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thiefclient.cpp

📁 一个使用CORBA DSI编程的例子
💻 CPP
字号:
#include <iostream.h>
#include "ThiefC.h"

int main(int argc, char* argv[])
{
	try 
	{
		CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
		CORBA::Object_var obj = orb->string_to_object(argv[1]);
		if (CORBA::is_nil(obj))
		{
			cerr << "Nil Reference" << endl;
			throw 0;
		}
		
		Thief::SessionFactory_var factory = Thief::SessionFactory::_narrow(obj);
		if (CORBA::is_nil(factory))
		{
			cerr << "not SessionFactory" << endl;
			throw 0;
		}
		
		cout << "--------------" << endl;
		
		Thief::Session_var session;
		cout << "----------------------" << endl;
		factory->login(session);
		cout << "---------------------------------" << endl;
		cout << "logined" << endl;
		
		Thief::Valuable_var money;
		session->applyKey("money", money);
		cout << "money referenct obtained" << endl;
		
		Thief::Valuable_var jewelry;
		session->applyKey("jewelry", jewelry);
		cout << "jewelry reference obtained" << endl;
		
		cout << "please input your choice: M(for Money)/J(for Jewelry)/C(for ChangeMode)/Q(for Quit):" << endl;
		char choice;
		cin >> choice;
		int mode = 0;
		while (1)
		{
			if (choice == 'M')
			{
				money->sayValue();
				Thief::Money_var m_var = Thief::Money::_narrow(money);
				Thief::Count_var c_var;
				m_var->getCount(c_var);
				c_var->print();
				c_var->print();
			}
			else if (choice == 'J')
			{
				jewelry->sayValue();
			}
			else if (choice == 'C')
			{
				if (mode == 0)
				{
					cout << "current Mode is 0, change to Mode 1" << endl;;
					session->setMode(1);
					mode = 1;
				}
				else if (mode == 1)
				{
					cout << "current Mode is 1, change to Mode 0" << endl;
					session->setMode(0);
					mode = 0;
				}
			}
			else
			{
				break;
			}
			
			cout << "please input your choice: M(for Money)/J(for Jewelry)/C(for ChangeMode)/Q(for Quit):" << endl;
			cin >> choice;
		}
	}
	catch (const CORBA::Exception& e )
	{
		CORBA::SystemException *se;
		if ((se = CORBA::INV_POLICY::_downcast(&e)) != 0)
		{
			cout << "policy" << endl;
		}
		else if ((se = CORBA::MARSHAL::_downcast(&e)) != 0)
		{
			cout << "marshal" << endl;
		}
		else if ((se = CORBA::OBJECT_NOT_EXIST::_downcast(&e)) != 0)
		{
			cout << "not exist" << endl;
		}
		else if ((se = CORBA::COMM_FAILURE::_downcast(&e)) != 0)
		{
			cout << "comm" << endl;
		}
		else if ((se = CORBA::INV_OBJREF::_downcast(&e)) != 0)
		{
			cout << "objref" << endl;
		}
		else if ((se = CORBA::NO_IMPLEMENT::_downcast(&e)) != 0)
		{
			cout << "implement" << endl;
		}
		else if ((se = CORBA::TRANSIENT::_downcast(&e)) != 0)
		{
			cout << "transient" << endl;
		}
		else if ((se = CORBA::UNKNOWN::_downcast(&e)) != 0)
		{
			cout << "*****" << endl;
		}
		else
		{
			cout << "unknow" << endl;
		}
		//cout << "Uncaught CORBA exception" << endl;
		return 1;
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -