您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 数据库 > Cobra-omniORB中间件复习
命名服务基本与Cobra-omniORB-IOR相似,下面具体对需要的操作步骤进行描述。一、设置环境变量0)、在IOR实验中设置的环境变量不改变,还需要加入一个环境变量1)、在“D:\omniORB-4.1.1\”目录下新建目录Omninames;2)、设置用户环境变量“OMNINAMES_LOGDIR=D:\omniORB-4.1.1\Omninames”。如果不设置这环境变量,在你做omniNames–start时候出现错误:Error:cannotcreateinitiallogfile'C:\temp\omninames-CHINA-E499FC10A.log':Nosuchfileordirectory执行完omniNames–start在Omninames文件夹下面会出现两个文件。二、配置命名服务双击执行D:/omniORB-4.1.1/sample.reg注册文件,开始-运行regedit打开HKEY_LOCAL_MACHINE/SOFTWARE/omniORB/InitRef右击InitRef-新建-字符串值:加入类型为字符串键“1”,键值为NameService=corbaname::my.host.name(这里的my.host.name是你的机器名)如果使用本机来测试,键值可以为NameService=corbaname::127.0.0.1。这里的shane-120ef1cf3.是我的机器名。三、使用Cobra-omniORB–IOR的工程文件testOrbServer工程文件,修改testOrbServer.cpp代码:3.1服务端程序如下:#includeiostream//#includeomniORB4/CORBA.h#includeCobartest.husingnamespacestd;classCobartest_impl:publicvirtualPOA_Cobartest{public:virtualdoubleDiv(doublea,doubleb);};doubleCobartest_impl::Div(doublea,doubleb){doublec=a/b;returnc;}intmain(intargc,char*argv[]){CORBA::ORB_varorb;Cobartest_impl*impl=NULL;try{orb=CORBA::ORB_init(argc,argv);CORBA::Object_varrootPOAObj=orb-resolve_initial_references(RootPOA);PortableServer::POA_varrootPOA=PortableServer::POA::_narrow(rootPOAObj.in());CORBA::PolicyListpolicies;policies.length(1);policies[0]=rootPOA-create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);PortableServer::POAManager_varmanager=rootPOA-the_POAManager();PortableServer::POA_varmyPOA=rootPOA-create_POA(myPOA,manager,policies);CORBA::ULonglen=policies.length();for(CORBA::ULongi=0;ilen;i++)policies[i]-destroy();CORBA::Object_varrootContextObj=orb-resolve_initial_references(NameService);CosNaming::NamingContext_varnc=CosNaming::NamingContext::_narrow(rootContextObj.in());impl=newCobartest_impl();PortableServer::ObjectId_varmyObjID=myPOA-activate_object(impl);CORBA::Object_varo=myPOA-servant_to_reference(impl);_CORBA_String_vars=orb-object_to_string(o);coutTheIORoftheobjectis:s.in()endl;CosNaming::Namename;name.length(1);name[0].id=(constchar*)FirstTimeService;name[0].kind=(constchar*);nc-rebind(name,o);manager-activate();orb-run();}catch(constCORBA::Exception&){cerrexceptionendl;return1;}return0;}3.2、VC向导工程设置图CodeGeneration下选择“Run-timeLibrary”选择MultiThreadedDLL图增加预定义宏Preprocessordefinitions:1)、__WIN32__,2)、__x86__,3)、_WIN32_WINNT=0x0400,4)、__NT__,5)、__OSVERSION__=4,输入的格式:__WIN32__,__x86__,_WIN32_WINNT=0x0400,__NT__,__OSVERSION__=4,加入路径:$(OMNI_ROOT)/include图增加工程依赖的库文件1、选择Link选项卡,Category选择Input,添加库模块:1)、ws2_32.lib2)、mswsock.lib3)、advapi32.lib4)、omniORB411_rt.lib5)、omniDynamic411_rt.lib6)、omnithread33_rt.lib输入的格式:ws2_32.libmswsock.libadvapi32.libomniORB411_rt.libomniDynamic411_rt.libomnithread33_rt.lib(不是:omnithread32_rt.lib)2、设置库模块的路径:$(OMNI_ROOT)/lib/x86_win32;3、testOrbClient工程设置与testOrbServer一致。四、使用Cobra-omniORB–IOR的工程文件testOrbClinet工程文件,修改testOrbClinet.cpp代码://testOrbClient.cpp:Definestheentrypointfortheconsoleapplication.#includeiostream#includeCobartest.husingnamespacestd;intmain(intargc,char*argv[]){CORBA::ORB_varorb;try{if(argc!=2){throw0;}orb=CORBA::ORB_init(argc,argv);CORBA::Object_varrootContextObj=orb-resolve_initial_references(NameService);if(CORBA::is_nil(rootContextObj)){cerrNilTimeReferenceendl;throw0;}CosNaming::NamingContext_varnc=CosNaming::NamingContext::_narrow(rootContextObj.in());CosNaming::Namename;name.length(1);name[0].id=(constchar*)argv[1];name[0].kind=(constchar*);//InvoketherootcontexttoretrievetheobjectreferenceCORBA::Object_varmanagerObj=nc-resolve(name);//Narrowthepreviousobjecttoobtainthecorrecttype::Cobartest_varmanager=::Cobartest::_narrow(managerObj.in());if(CORBA::is_nil(manager)){cerrNilTimeReferenceendl;throw0;}coutOK,Let'shavealook:manager-Div(111,333)endl;}catch(constCORBA::Exception&){cerrExceptionendl;return1;}return0;}五、编译上述两个工程六、启动命名服务输入omniNames–start六、运行testOrbServer.exe服务端程序(可以直接在VC环境中运行)七、运行testOrbClient.exe客户端程序(不可以直接在VC环境中运行,缺少参数)
本文标题:Cobra-omniORB中间件复习
链接地址:https://www.777doc.com/doc-2906553 .html