orb.C

00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
00018  */
00019 
00020 #include <unistd.h>
00021 #include <string.h>
00022 #include <stdlib.h>
00023 #include <iostream>
00024 
00025 #include <archon/util/logger.H>
00026 #include <archon/util/text.H>
00027 
00028 #include <archon/x3d/sai/orb.H>
00029 
00030 namespace Archon
00031 {
00032   namespace X3D
00033   {
00034     namespace SAI
00035     {
00036       using namespace Utilities;
00037 
00038       Orb::Orb(int port) 
00039       {
00040         char hostname[256];
00041         if(gethostname(hostname, sizeof(hostname))<0)
00042         {
00043           Logger::get()->log((string)strerror(errno) + "\n");
00044           abort();
00045         };
00046 
00047         hostname[sizeof(hostname)-1] = '\0';
00048 
00049         char endpoint[512];
00050         if(port<0) snprintf(endpoint, sizeof(endpoint), "giop:tcp:%s:", hostname);
00051         else snprintf(endpoint, sizeof(endpoint), "giop:tcp:%s:%d", hostname, port);
00052 
00053         const char *args[][2] =
00054           {
00055             { "endPoint"               , endpoint  },
00056           /*{ "offerBiDirectionalGIOP" , "1"       },
00057             { "acceptBiDirectionalGIOP", "1"       },
00058             { "clientTransportRule"    , "* tcp"   },
00059             { "serverTransportRule"    , "* tcp"   },*/
00060             { 0                        , 0         }
00061           };
00062 
00063         // Initialise the ORB.
00064         int argc = 0;
00065         orb = CORBA::ORB_init(argc, 0, "omniORB4", args);
00066     
00067         // Obtain a reference to the root POA.
00068         CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00069         poa = PortableServer::POA::_narrow(obj);
00070 
00071         PortableServer::POA_var rootPoa = PortableServer::POA::_narrow(obj);
00072 
00073         CORBA::PolicyList policies(1);
00074         policies.length(1);
00075         policies[0] = new BiDirPolicy::BidirectionalPolicy(BiDirPolicy::BOTH);
00076         poa = rootPoa->create_POA("archon", PortableServer::POAManager::_nil(), policies);
00077 
00078         // Obtain a POAManager, and tell the POA to start accepting
00079         // requests on its objects.
00080         PortableServer::POAManager_var pman = poa->the_POAManager();
00081         pman->activate();
00082       }
00083 
00084       Orb::~Orb()
00085       {{ // The extra scope is needed to work around gcc3.2 bug #8287
00086         orb->destroy();
00087       }}
00088     }
00089   }
00090 }
00091 

Generated on Sun Jul 30 22:55:47 2006 for Archon by  doxygen 1.4.4