Commit b3b9b297 authored by Pavel Vainerman's avatar Pavel Vainerman

(Configuration): переделал использование argv на использование options,

для инициализации omniORB (ORB_init).
parent 818aab74
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<UserData/> <UserData/>
<omniORB> <omniORB>
<option name="-ORBendPoint" arg="giop:tcp:localhost:"/> <option name="endPoint" arg="giop:tcp:localhost:"/>
</omniORB> </omniORB>
<!-- Общие(стартовые) параметры по UniSet --> <!-- Общие(стартовые) параметры по UniSet -->
<UniSet> <UniSet>
......
...@@ -113,11 +113,6 @@ Configuration::Configuration(): ...@@ -113,11 +113,6 @@ Configuration::Configuration():
Configuration::~Configuration() Configuration::~Configuration()
{ {
for( int i=0; i<_argc; i++ )
delete[] _argv[i];
delete[] _argv;
if( oind ) if( oind )
oind.reset(); oind.reset();
if( unixml ) if( unixml )
...@@ -310,83 +305,81 @@ void Configuration::initConfiguration( int argc, const char* const* argv ) ...@@ -310,83 +305,81 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
else else
{ {
const string a(omniIt.getProp("arg")); const string a(omniIt.getProp("arg"));
uinfo << "(Configuration): add omniORB param: " << p << " " << a << endl; uinfo << "(Configuration): add omniORB option '" << p << "' " << a << endl;
omniParams.push_back( std::make_pair(p,a) ); omniParams.push_back( std::make_pair(p,a) );
} }
} }
} }
xmlNode* nsnode = getNode("NameService");
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
// добавляем новые параметры в argv // формируем options для ORB_init()
// для передачи параметров orb по списку узлов // Прототип из документации на omniORB4: const char* options[][2] = { { "traceLevel", "1" }, { 0, 0 } };
// взятому из configure.xml // --------------------------------------------------
// +N --> -ORBIniRef NodeName= // + спискок узлов (сформированный из configure.xml)
// +2 --> -ORBIniRef NameService= // + список параметров omniORB из секции <omniORB>
// + --> -ORBxxxx from configure.xml (<omniORB>) // +1 для завершающего {0,0}
_argc = argc+2*lnodes.size() + 2 + 2*omniParams.size(); int onum = lnodes.size() + omniParams.size() + 1;
const char** new_argv = new const char*[_argc];
if( nsnode )
onum += 1; // +1 --> IniRef NameService=
const char* (*omni_options)[2] = new const char*[onum][2];
int i = 0; int i = 0;
// перегоняем старые параметры
for( ; i < argc; i++ )
new_argv[i] = uni_strdup(argv[i]);
// формируем новые, используя i в качестве индекса // формируем новые, используя i в качестве индекса
for( auto &it: lnodes ) for( auto &it: lnodes )
{ {
new_argv[i] = "-ORBInitRef"; // делаем uni_strdup чтобы потом не думая
// "где мы выделяли, а где не мы"
// делать delete[]
omni_options[i][0] = uni_strdup("InitRef");
string name(oind->getNodeName(it.id)); string name(oind->getNodeName(it.id));
ostringstream param; ostringstream o;
param << this << name; o << this << name;
name = param.str(); name = o.str();
param << "=corbaname::" << it.host << ":" << it.port; o << "=corbaname::" << it.host << ":" << it.port;
const string sparam(param.str()); omni_options[i][1] = uni_strdup(o.str());
new_argv[i+1] = uni_strdup(sparam);
uinfo << "(Configuration): внесли параметр " << sparam << endl; uinfo << "(Configuration): add omniORB option 'InitRef' (nodes) " << o.str() << endl;
i+=2; i++;
ostringstream uri; ostringstream uri;
uri << "corbaname::" << it.host << ":" << it.port; uri << "corbaname::" << it.host << ":" << it.port;
if( !omni::omniInitialReferences::setFromArgs(name.c_str(), uri.str().c_str()) ) if( !omni::omniInitialReferences::setFromArgs(name.c_str(), uri.str().c_str()) )
cerr << "**********************!!!! FAILED ADD name=" << name << " uri=" << uri.str() << endl; ucrit << "(Configuration): init omniInitialReferences: FAILED ADD name=" << name << " uri=" << uri.str() << endl;
assert( i < _argc ); assert( i < onum );
} }
for( auto& p: omniParams ) for( auto& p: omniParams )
{ {
new_argv[i++] = uni_strdup(p.first); // делаем uni_strdup чтобы потом не думая
new_argv[i++] = uni_strdup(p.second); // "где мы выделяли, а где не мы"
assert( i < _argc ); // делать delete[]
omni_options[i][0] = uni_strdup(p.first);
omni_options[i][1] = uni_strdup(p.second);
i++;
assert( i < onum );
} }
// initRef for NameService
// т..к _argc уже изменился, то и _argv надо обновить if( nsnode )
// чтобы вызов getArgParam не привел к SIGSEGV
_argv = new_argv;
// NameService (+2)
xmlNode* nsnode = getNode("NameService");
if( !nsnode )
{ {
uwarn << "(Configuration): не нашли раздела 'NameService' \n"; // делаем uni_strdup чтобы потом не думая
new_argv[i] = ""; // "где мы выделяли, а где не мы"
new_argv[i+1] = ""; // делать delete[]
} omni_options[i][0] = uni_strdup("InitRef");
else string defPort( getPort( getProp(nsnode,"port") ) );
{
new_argv[i] = "-ORBInitRef";
new_argv[i+1] = ""; // сперва инициализиуем пустой строкой (т.к. будет вызываться getArgParam)
string defPort( getPort( getProp(nsnode,"port") ) ); // здесь вызывается getArgParam! проходящий по _argv
ostringstream param; ostringstream param;
param << this << "NameService=corbaname::" << getProp(nsnode,"host") << ":" << defPort; param << this << "NameService=corbaname::" << getProp(nsnode,"host") << ":" << defPort;
const string sparam(param.str()); omni_options[i][1] = uni_strdup(param.str());
new_argv[i+1] = uni_strdup(sparam); uinfo << "(Configuration): add omniORB option 'InitRef' " << param.str() << endl;
uinfo << "(Configuration): внесли параметр " << sparam << endl;
{ {
ostringstream ns_name; ostringstream ns_name;
...@@ -396,12 +389,31 @@ void Configuration::initConfiguration( int argc, const char* const* argv ) ...@@ -396,12 +389,31 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
if( !omni::omniInitialReferences::setFromArgs(ns_name.str().c_str(), uri.str().c_str()) ) if( !omni::omniInitialReferences::setFromArgs(ns_name.str().c_str(), uri.str().c_str()) )
cerr << "**********************!!!! FAILED ADD name=" << ns_name << " uri=" << uri.str() << endl; cerr << "**********************!!!! FAILED ADD name=" << ns_name << " uri=" << uri.str() << endl;
} }
i++;
} }
else
uwarn << "(Configuration): не нашли раздела 'NameService' \n";
_argv = new_argv; omni_options[i][0]=0;
omni_options[i][1]=0;
// ------------- CORBA INIT ------------- // ------------- CORBA INIT -------------
// orb init // orb init
orb = CORBA::ORB_init(_argc,(char**)_argv); orb = CORBA::ORB_init(_argc,(char**)_argv,"omniORB4",omni_options);
// освобождаем память..
for( int k=0; k<onum; k++ )
{
// на самом деле последний элемент = {0,0}
// но delete от 0 разрёшён и не приводит "к краху"
// так что отдельно не обрабатываем этот случай.
delete[] omni_options[k][0]; // см. uni_strdup()
delete[] omni_options[k][1]; // см. uni_strdup()
}
delete[] omni_options;
// create policy // create policy
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment