赞
踩
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;
- }
-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。