server.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * National Institute of Advanced Industrial Science and Technology (AIST)
00008  * General Robotix Inc. 
00009  */
00016 #include "CollisionDetector_impl.h"
00017 
00018 #ifdef _WIN32
00019 #include "winbase.h"
00020 #else
00021 #include <unistd.h>
00022 #endif /* _WIN32 */
00023 
00024 #include <iostream>
00025 
00026 using namespace std;
00027 
00035 int main(int argc, char* argv[]) {
00036     CORBA::ORB_var orb;
00037     try {
00038         orb = CORBA::ORB_init(argc, argv);
00039         //
00040         // Resolve Root POA
00041         //
00042         CORBA::Object_var poaObj = orb -> resolve_initial_references("RootPOA");
00043         PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObj);
00044 
00045         //
00046         // Get a reference to the POA manager
00047         //
00048         PortableServer::POAManager_var manager = rootPOA -> the_POAManager();
00049 
00050     // ネームサーバへの参照取得 //
00051     CORBA_Object_var ns;
00052     try {
00053       ns = orb -> resolve_initial_references("NameService");
00054     } catch (const CORBA_ORB::InvalidName&) {
00055       cerr << argv[0] << ": can't resolve `NameService'" << endl;
00056       return 1;
00057     }
00058     if(CORBA_is_nil(ns)) {
00059       cerr << argv[0]
00060            << ": `NameService' is a nil object reference"
00061            << endl;
00062       return 1;
00063     }
00064     
00065     // ルートネーミングコンテキスト取得 //
00066     CosNaming_NamingContext_var rootnc = CosNaming_NamingContext::_narrow(ns);
00067     if(CORBA_is_nil(rootnc)) {
00068       cerr << argv[0]
00069            << ": `NameService' is not a NamingContext object reference"
00070            << endl;
00071       return 1;
00072     }
00073 
00074     CORBA_Object_var cdFactory;
00075     CollisionDetectorFactory_impl* cdFactoryImpl = new CollisionDetectorFactory_impl(orb);
00076     cdFactory = cdFactoryImpl -> _this();
00077     CosNaming_Name nc;
00078     nc.length(1);
00079     nc[0].id = CORBA_string_dup("CollisionDetectorFactory");
00080     nc[0].kind = CORBA_string_dup("");
00081     rootnc -> rebind(nc, cdFactory);
00082     
00083     // クライアント側からの接続待ち //
00084     manager -> activate();
00085     cout << "ready" << endl;
00086     
00087     orb -> run();
00088     } catch (CORBA_SystemException& ex) {
00089         cerr << ex._rep_id() << endl;
00090         orb->destroy();
00091         return 1;
00092     }
00093     orb->destroy();
00094     return 0;
00095 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:19