当前位置:   article > 正文

omniorb (CORBA) C++_ubuntu c++ corba

ubuntu c++ corba

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

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

 

 

  1. omniidl -u
  2. Usage: omniidl -b<back_end> [flags] file1 file2 ...
  3. The supported flags are:
  4. -Dname[=value] Define name for preprocessor
  5. -Uname Undefine name for preprocessor
  6. -Idir Include dir in search path for preprocessor
  7. -E Run preprocessor only, print on stdout
  8. -Ycmd Set command for the preprocessor
  9. -N Do not run preprocessor
  10. -P Add defines relevant to platform dependencies (internal use)
  11. -T Use a temporary file, not a pipe, for preprocessor output
  12. -Wparg[,arg...] Send args to the preprocessor
  13. -bback_end Select a back-end to be used. More than one permitted =====================> -bcxx /default omniidl/cxx

 

echo_serverimple.cpp

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

 

echo_client.cpp

  1. #include <iostream>
  2. #include "echo_server.h"
  3. using namespace std;
  4. char* Echo_i::echoString(const char* mesg)
  5. {
  6. return CORBA::string_dup(mesg);
  7. }

 

 

  1. #include <iostream>
  2. #include "echo_server.h"
  3. using namespace std;
  4. void hello(CORBA::Object_ptr obj)
  5. {
  6. Echo_var e = Echo::_narrow(obj);
  7. if (CORBA::is_nil(e)) {
  8. cerr << "cannot invoke on a nil object reference." << endl;
  9. return;
  10. }
  11. CORBA::String_var src = (const char*) "Hello!";
  12. CORBA::String_var dest;
  13. dest = e->echoString(src);
  14. cerr << "I said,\"" << src << "\"."
  15. << " The Object said,\"" << dest <<"\"" << endl;
  16. }
  17. int main(int argc, char **argv)
  18. {
  19. CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB4");
  20. CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
  21. PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
  22. Echo_i *myecho = new Echo_i();
  23. PortableServer::ObjectId_var myechoid = poa->activate_object(myecho);
  24. Echo_var myechoref = myecho->_this();
  25. myecho->_remove_ref();
  26. PortableServer::POAManager_var pman = poa->the_POAManager();
  27. pman->activate();
  28. hello(myechoref);
  29. orb->destroy();
  30. return 0;
  31. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/496872
推荐阅读
相关标签
  

闽ICP备14008679号