omniorb (CORBA) C++

本文详细介绍了在 Ubuntu 18 x86 系统上使用 OmniORB 实现 CORBA 接口的过程,包括环境搭建、idl 文件编写、omniidl 编译器的使用及 C++ 示例代码实现。通过具体示例展示了如何创建和调用 CORBA 对象,为读者提供了完整的编程流程指导。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

Refer to  http://omniorb.sourceforge.net/omni42/omniORB/index.html

Refer to  https://my.oschina.net/u/2245781/blog/4355000

Code :  git@github.com:lakehu/example-omniORB.git

#### ubuntu18 x86

### omniorb runtime 
lake@PC-HM6DD43:~$ sudo apt-get install -y omniorb   libomniorb4-dev
 

 

idl

lake@PC-HM6DD43:/mnt/c/work/omiidl/example$ cat  echo.idl
interface Echo {
    string echoString(in string mesg);
};lake@PC-HM6DD43:/mnt/c/work/omiidl/example$

 

 

omniidl    -u

Usage: omniidl -b<back_end> [flags] file1 file2 ...

The supported flags are:

  -Dname[=value]  Define name for preprocessor
  -Uname          Undefine name for preprocessor
  -Idir           Include dir in search path for preprocessor
  -E              Run preprocessor only, print on stdout
  -Ycmd           Set command for the preprocessor
  -N              Do not run preprocessor
  -P              Add defines relevant to platform dependencies (internal use)
  -T              Use a temporary file, not a pipe, for preprocessor output
  -Wparg[,arg...] Send args to the preprocessor
  -bback_end      Select a back-end to be used. More than one permitted  =====================>  -bcxx /default omniidl/cxx

 

echo_serverimple.cpp


lake@PC-HM6DD43:/mnt/c/work/omiidl/example$ omniidl -bcxx echo.idl
lake@PC-HM6DD43:/mnt/c/work/omiidl/example$ ls  -l  echo.hh   echoSK.cc
-rwxrwxrwx 1 lake lake 4408 Aug  5 10:00 echo.hh
-rwxrwxrwx 1 lake lake 5425 Aug  5 10:00 echoSK.cc
lake@PC-HM6DD43:/mnt/c/work/omiidl/example$ date
Wed Aug  5 10:00:34 CST 2020
lake@PC-HM6DD43:/mnt/c/work/omiidl/example$ g++  -g  -c echo_serverimple.cpp
lake@PC-HM6DD43:/mnt/c/work/omiidl/example$ g++  -g  -c echo_client.cpp
lake@PC-HM6DD43:/mnt/c/work/omiidl/example$  g++  -g   -o   echo_test   echoSK.o    echo_serverimple.o    echo_client.o    -lomniDynamic4 -lomniORB4 -lomnithread
lake@PC-HM6DD43:/mnt/c/work/omiidl/example$ ./echo_test
I said,"Hello!". The Object said,"Hello!"

 

echo_client.cpp

#include  <iostream>
#include  "echo_server.h"

using namespace std;


char* Echo_i::echoString(const char* mesg)
{
  return CORBA::string_dup(mesg);
}

 

 

#include  <iostream>
#include  "echo_server.h"

using namespace std;




void  hello(CORBA::Object_ptr obj)
{
	Echo_var e = Echo::_narrow(obj);

	if (CORBA::is_nil(e)) {
	cerr << "cannot invoke on a nil object reference." << endl;
	return;
	}
	CORBA::String_var src = (const char*) "Hello!";
	CORBA::String_var dest;

	dest = e->echoString(src);

	cerr << "I said,\"" << src << "\"."
	<< " The Object said,\"" << dest <<"\"" << endl;
}



int main(int argc, char **argv)
{
	CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB4");
	
	CORBA::Object_var       obj = orb->resolve_initial_references("RootPOA");
	PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
 
	Echo_i *myecho = new Echo_i();
	PortableServer::ObjectId_var myechoid = poa->activate_object(myecho);

	Echo_var myechoref = myecho->_this();
	myecho->_remove_ref();

	PortableServer::POAManager_var pman = poa->the_POAManager();
	pman->activate();

	hello(myechoref);

	orb->destroy();
	return 0;
}


 

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值