Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
8d8de61d
Commit
8d8de61d
authored
Aug 25, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Удалил лишнюю сущность ObjectRepositoryFactory, перенёс его функциональность
в класс ObjectRepository.
parent
24d1baff
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
315 additions
and
415 deletions
+315
-415
admin.cc
Utilities/Admin/admin.cc
+1
-2
ObjectRepository.h
include/ObjectRepository.h
+25
-3
ObjectRepositoryFactory.h
include/ObjectRepositoryFactory.h
+0
-75
Makefile.am
src/ObjectRepository/Makefile.am
+1
-1
ObjectRepository.cc
src/ObjectRepository/ObjectRepository.cc
+288
-2
ObjectRepositoryFactory.cc
src/ObjectRepository/ObjectRepositoryFactory.cc
+0
-330
uniset2.files
uniset2.files
+0
-2
No files found.
Utilities/Admin/admin.cc
View file @
8d8de61d
...
...
@@ -9,7 +9,6 @@
// --------------------------------------------------------------------------
#include "ORepHelpers.h"
#include "ObjectRepository.h"
#include "ObjectRepositoryFactory.h"
#include "Exceptions.h"
#include "UniSetObject.h"
#include "UniSetTypes.h"
...
...
@@ -523,7 +522,7 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
// ==============================================================================================
static
void
createSections
(
const
std
::
shared_ptr
<
UniSetTypes
::
Configuration
>&
rconf
)
{
ObjectRepository
Factory
repf
(
rconf
);
ObjectRepository
repf
(
rconf
);
repf
.
createRootSection
(
rconf
->
getRootSection
());
repf
.
createRootSection
(
rconf
->
getSensorsSection
());
...
...
include/ObjectRepository.h
View file @
8d8de61d
...
...
@@ -86,13 +86,32 @@ class ObjectRepository
};
//! Получение списка how_many объектов из секции section.
bool
list
(
const
std
::
string
&
section
,
UniSetTypes
::
ListObjectName
*
ls
,
unsigned
in
t
how_many
=
300
)
throw
(
UniSetTypes
::
ORepFailed
);
bool
list
(
const
std
::
string
&
section
,
UniSetTypes
::
ListObjectName
*
ls
,
size_
t
how_many
=
300
)
throw
(
UniSetTypes
::
ORepFailed
);
//! Получние списка how_many подсекций из секции in_section.
bool
listSections
(
const
std
::
string
&
in_section
,
UniSetTypes
::
ListObjectName
*
ls
,
unsigned
int
how_many
=
300
)
throw
(
UniSetTypes
::
ORepFailed
);
bool
listSections
(
const
std
::
string
&
in_section
,
UniSetTypes
::
ListObjectName
*
ls
,
size_t
how_many
=
300
)
throw
(
UniSetTypes
::
ORepFailed
);
// -------------------------------------------------------------------
//! Создание секции
bool
createSection
(
const
std
::
string
&
name
,
const
std
::
string
&
in_section
)
throw
(
UniSetTypes
::
ORepFailed
,
UniSetTypes
::
InvalidObjectName
);
/*! Создание секции по полному имени */
bool
createSectionF
(
const
std
::
string
&
fullName
)
throw
(
UniSetTypes
::
ORepFailed
,
UniSetTypes
::
InvalidObjectName
);
//! Функция создания секции в корневом 'каталоге'
bool
createRootSection
(
const
std
::
string
&
name
);
//! Функция удаления секции
bool
removeSection
(
const
std
::
string
&
fullName
,
bool
recursive
=
false
);
//! Функция переименования секции
bool
renameSection
(
const
std
::
string
&
newName
,
const
std
::
string
&
fullName
);
/*! Функция выводящая на экран список всех объектов расположенных в данной секции */
void
printSection
(
const
std
::
string
&
fullName
);
// @}
// end of ORepServiceGroup
// end of
add to
ORepServiceGroup
protected
:
...
...
@@ -102,6 +121,9 @@ class ObjectRepository
bool
list
(
const
std
::
string
&
section
,
UniSetTypes
::
ListObjectName
*
ls
,
unsigned
int
how_many
,
ObjectType
type
);
/*! Создание нового контекста(секции) */
bool
createContext
(
const
std
::
string
&
cname
,
CosNaming
::
NamingContext_ptr
ctx
);
private
:
bool
init
()
const
;
mutable
CosNaming
::
NamingContext_var
localctx
;
...
...
include/ObjectRepositoryFactory.h
deleted
100644 → 0
View file @
24d1baff
/*
* Copyright (c) 2015 Pavel Vainerman.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 2.1.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// --------------------------------------------------------------------------
/*! \file
* \brief Интерфейсный класс для создания структуры репозитария объектов
* \author Pavel Vainerman
*/
// --------------------------------------------------------------------------
#ifndef ObjectRepositoryFactory_H_
#define ObjectRepositoryFactory_H_
// --------------------------------------------------------------------------
#include <omniORB4/CORBA.h>
#include <omniORB4/Naming.hh>
#include "Exceptions.h"
#include "ObjectRepository.h"
// -----------------------------------------------------------------------------------------
//namespase ORepositoryFacotry
//{
/*!\class ObjectRepositoryFactory */
class
ObjectRepositoryFactory
:
private
ObjectRepository
{
public
:
ObjectRepositoryFactory
(
const
std
::
shared_ptr
<
UniSetTypes
::
Configuration
>&
conf
);
~
ObjectRepositoryFactory
();
//! Создание секции
bool
createSection
(
const
std
::
string
&
name
,
const
std
::
string
&
in_section
)
throw
(
UniSetTypes
::
ORepFailed
,
UniSetTypes
::
InvalidObjectName
);
/*! Создание секции по полному имени */
bool
createSectionF
(
const
std
::
string
&
fullName
)
throw
(
UniSetTypes
::
ORepFailed
,
UniSetTypes
::
InvalidObjectName
);
//! Функция создания секции в корневом 'каталоге'
bool
createRootSection
(
const
std
::
string
&
name
);
//! Функция удаления секции
bool
removeSection
(
const
std
::
string
&
fullName
,
bool
recursive
=
false
);
//! Функция переименования секции
bool
renameSection
(
const
std
::
string
&
newName
,
const
std
::
string
&
fullName
);
/**
@addtogroup ORepServiceGroup
@{
*/
/*! Функция выводящая на экран список всех объектов расположенных в данной секции */
void
printSection
(
const
std
::
string
&
fullName
);
// void printSection(CosNaming::NamingContext_ptr ctx);
// @}
// end of add to ORepServiceGroup
protected
:
private
:
/*! Создание нового контекста(секции) */
bool
createContext
(
const
std
::
string
&
cname
,
CosNaming
::
NamingContext_ptr
ctx
);
};
//};
#endif
src/ObjectRepository/Makefile.am
View file @
8d8de61d
...
...
@@ -2,7 +2,7 @@ noinst_LTLIBRARIES = libObjectsRepository.la
libObjectsRepository_la_SOURCES
=
UniSetTypes_iSK.cc UniSetObject_iSK.cc UniSetTypes.cc
\
UniSetManager_iSK.cc ObjectIndex.cc ObjectIndex_Array.cc ObjectIndex_XML.cc ObjectIndex_idXML.cc
\
ORepHelpers.cc UniSetObject.cc UniSetManager.cc
\
UniSetActivator.cc ObjectRepository.cc
ObjectRepositoryFactory.cc
\
UniSetActivator.cc ObjectRepository.cc
\
ProxyManager.cc PassiveObject.cc IORFile.cc
# ServiceActivator.cc
...
...
src/ObjectRepository/ObjectRepository.cc
View file @
8d8de61d
...
...
@@ -308,7 +308,7 @@ throw(ORepFailed, NameNotFound)
* количество объектов в этой секции превышает заданное how_many.
* \exception ORepFailed - генерируется если произошла при получении доступа к секции
*/
bool
ObjectRepository
::
list
(
const
string
&
section
,
ListObjectName
*
ls
,
unsigned
in
t
how_many
)
throw
(
ORepFailed
)
bool
ObjectRepository
::
list
(
const
string
&
section
,
ListObjectName
*
ls
,
size_
t
how_many
)
throw
(
ORepFailed
)
{
return
list
(
section
,
ls
,
how_many
,
ObjectRef
);
}
...
...
@@ -322,7 +322,7 @@ bool ObjectRepository::list(const string& section, ListObjectName* ls, unsigned
* количество объектов в этой секции превышает заданное how_many.
* \exception ORepFailed - генерируется если произошла при получении доступа к секции
*/
bool
ObjectRepository
::
listSections
(
const
string
&
in_section
,
ListObjectName
*
ls
,
unsigned
in
t
how_many
)
throw
(
ORepFailed
)
bool
ObjectRepository
::
listSections
(
const
string
&
in_section
,
ListObjectName
*
ls
,
size_
t
how_many
)
throw
(
ORepFailed
)
{
return
list
(
in_section
,
ls
,
how_many
,
Section
);
}
...
...
@@ -444,3 +444,289 @@ bool ObjectRepository::isExist( const ObjectPtr& oref ) const
}
// --------------------------------------------------------------------------
/*!
* \param name - имя создаваемой секции
* \param in_section - полное имя секции внутри которой создается новая
* \param section - полное имя секции начиная с Root.
* \exception ORepFailed - генерируется если произошла при получении доступа к секции
*/
bool
ObjectRepository
::
createSection
(
const
string
&
name
,
const
string
&
in_section
)
throw
(
ORepFailed
,
InvalidObjectName
)
{
char
bad
=
ORepHelpers
::
checkBadSymbols
(
name
);
if
(
bad
!=
0
)
{
ostringstream
err
;
err
<<
"ObjectRepository(registration): (InvalidObjectName) "
<<
name
;
err
<<
" содержит недопустимый символ "
<<
bad
;
throw
(
InvalidObjectName
(
err
.
str
().
c_str
())
);
}
ulogrep
<<
"CreateSection: name = "
<<
name
<<
" in section = "
<<
in_section
<<
endl
;
if
(
in_section
.
empty
()
)
{
ulogrep
<<
"CreateSection: in_section..empty"
<<
endl
;
return
createRootSection
(
name
);
}
int
argc
(
uconf
->
getArgc
());
const
char
*
const
*
argv
(
uconf
->
getArgv
());
CosNaming
::
NamingContext_var
ctx
=
ORepHelpers
::
getContext
(
in_section
,
argc
,
argv
,
uconf
->
getNSName
()
);
return
createContext
(
name
,
ctx
.
in
()
);
}
// -------------------------------------------------------------------------------------------------------
/*!
* \param fullName - полное имя создаваемой секции
* \exception ORepFailed - генерируется если произошла при получении доступа к секции
*/
bool
ObjectRepository
::
createSectionF
(
const
string
&
fullName
)
throw
(
ORepFailed
,
InvalidObjectName
)
{
string
name
(
ObjectIndex
::
getBaseName
(
fullName
));
string
sec
(
ORepHelpers
::
getSectionName
(
fullName
));
ulogrep
<<
name
<<
endl
;
ulogrep
<<
sec
<<
endl
;
if
(
sec
.
empty
()
)
{
ulogrep
<<
"SectionName is empty!!!"
<<
endl
;
ulogrep
<<
"Добавляем в "
<<
uconf
->
getRootSection
()
<<
endl
;
return
createSection
(
name
,
uconf
->
getRootSection
());
}
else
return
createSection
(
name
,
sec
);
}
// ---------------------------------------------------------------------------------------------------------------
bool
ObjectRepository
::
createRootSection
(
const
string
&
name
)
{
CORBA
::
ORB_var
orb
=
uconf
->
getORB
();
CosNaming
::
NamingContext_var
ctx
=
ORepHelpers
::
getRootNamingContext
(
orb
,
uconf
->
getNSName
());
return
createContext
(
name
,
ctx
);
}
// -----------------------------------------------------------------------------------------------------------
bool
ObjectRepository
::
createContext
(
const
string
&
cname
,
CosNaming
::
NamingContext_ptr
ctx
)
{
CosNaming
::
Name_var
nc
=
omniURI
::
stringToName
(
cname
.
c_str
());
try
{
ulogrep
<<
"ORepFactory(createContext): создаю новый контекст "
<<
cname
<<
endl
;
ctx
->
bind_new_context
(
nc
);
ulogrep
<<
"ORepFactory(createContext): создал. "
<<
endl
;
return
true
;
}
catch
(
const
CosNaming
::
NamingContext
::
AlreadyBound
&
ab
)
{
// ctx->resolve(nc);
ulogrep
<<
"ORepFactory(createContext): context "
<<
cname
<<
" уже есть"
<<
endl
;
return
true
;
}
catch
(
const
CosNaming
::
NamingContext
::
NotFound
)
{
ulogrep
<<
"ORepFactory(createContext): NotFound "
<<
cname
<<
endl
;
throw
NameNotFound
();
}
catch
(
const
CosNaming
::
NamingContext
::
InvalidName
&
nf
)
{
uwarn
<<
"ORepFactory(createContext): (InvalidName) "
<<
cname
;
}
catch
(
const
CosNaming
::
NamingContext
::
CannotProceed
&
cp
)
{
uwarn
<<
"ORepFactory(createContext): catch CannotProced "
<<
cname
<<
" bad part="
<<
omniURI
::
nameToString
(
cp
.
rest_of_name
);
throw
NameNotFound
();
}
catch
(
const
CORBA
::
SystemException
&
ex
)
{
ucrit
<<
"ORepFactory(createContext): CORBA::SystemException: "
<<
ex
.
NP_minorString
()
<<
endl
;
}
catch
(
const
CORBA
::
Exception
&
)
{
ucrit
<<
"поймали CORBA::Exception."
<<
endl
;
}
catch
(
const
omniORB
::
fatalException
&
fe
)
{
ucrit
<<
"поймали omniORB::fatalException:"
<<
endl
;
ucrit
<<
" file: "
<<
fe
.
file
()
<<
endl
;
ucrit
<<
" line: "
<<
fe
.
line
()
<<
endl
;
ucrit
<<
" mesg: "
<<
fe
.
errmsg
()
<<
endl
;
}
return
false
;
}
// -----------------------------------------------------------------------------------------------------------
/*!
\note Функция не вывести список, если не сможет получить доступ к секции
*/
void
ObjectRepository
::
printSection
(
const
string
&
fullName
)
{
ListObjectName
ls
;
try
{
list
(
fullName
.
c_str
(),
&
ls
);
if
(
ls
.
empty
()
)
cout
<<
fullName
<<
" пуст!!!"
<<
endl
;
}
catch
(
ORepFailed
)
{
cout
<<
"printSection: cath exceptions ORepFailed..."
<<
endl
;
return
;
}
cout
<<
fullName
<<
"("
<<
ls
.
size
()
<<
"):"
<<
endl
;
for
(
auto
v
:
ls
)
cout
<<
v
<<
endl
;
}
// -----------------------------------------------------------------------------------------------------------
/*!
* \param fullName - имя удаляемой секции
* \param recursive - удлаять рекурсивно все секции или возвращать не удалять и ошибку ( временно )
* \warning Функция вынимает только первые 1000 объектов, остальные игнорируются...
*/
bool
ObjectRepository
::
removeSection
(
const
string
&
fullName
,
bool
recursive
)
{
// string name = getName(fullName.c_str(),'/');
// string sec = getSectionName(fullName.c_str(),'/');
// CosNaming::NamingContext_var ctx = getContext(sec, argc, argv);
unsigned
int
how_many
=
1000
;
CosNaming
::
NamingContext_var
ctx
;
try
{
int
argc
(
uconf
->
getArgc
());
const
char
*
const
*
argv
(
uconf
->
getArgv
());
ctx
=
ORepHelpers
::
getContext
(
fullName
,
argc
,
argv
,
nsName
);
}
catch
(
ORepFailed
)
{
return
false
;
}
CosNaming
::
BindingList_var
bl
;
CosNaming
::
BindingIterator_var
bi
;
ctx
->
list
(
how_many
,
bl
,
bi
);
// хитрая проверка на null приобращении к bl
// coverity говорит потенциально это возможно
// т.к. там возвращается указатель, который по умолчанию null
if
(
!
bl
.
operator
->
()
)
return
false
;
if
(
how_many
>
bl
->
length
()
)
how_many
=
bl
->
length
();
bool
rem
=
true
;
// удалять или нет
for
(
unsigned
int
i
=
0
;
i
<
how_many
;
i
++
)
{
if
(
bl
[
i
].
binding_type
==
CosNaming
::
nobject
)
{
// cout <<"удаляем "<< omniURI::nameToString(bl[i].binding_name) << endl;
ctx
->
unbind
(
bl
[
i
].
binding_name
);
}
else
if
(
bl
[
i
].
binding_type
==
CosNaming
::
ncontext
)
{
if
(
recursive
)
{
ulogrep
<<
"ORepFactory: удаляем рекурсивно..."
<<
endl
;
string
rctx
=
fullName
+
"/"
+
omniURI
::
nameToString
(
bl
[
i
].
binding_name
);
ulogrep
<<
rctx
<<
endl
;
if
(
!
removeSection
(
rctx
))
{
ulogrep
<<
"рекурсивно удалить не удалось"
<<
endl
;
rem
=
false
;
}
}
else
{
ulogrep
<<
"ORepFactory: "
<<
omniURI
::
nameToString
(
bl
[
i
].
binding_name
)
<<
" - контекст!!! "
;
ulogrep
<<
"ORepFactory: пока не удаляем"
<<
endl
;
rem
=
false
;
}
}
}
// Удаляем контекст, если он уже пустой
if
(
rem
)
{
// Получаем имя контекста содержащего удаляемый
string
in_sec
(
ORepHelpers
::
getSectionName
(
fullName
));
//Получаем имя удаляемого контекста
string
name
(
ObjectIndex
::
getBaseName
(
fullName
));
try
{
int
argc
(
uconf
->
getArgc
());
const
char
*
const
*
argv
(
uconf
->
getArgv
());
CosNaming
::
Name_var
ctxName
=
omniURI
::
stringToName
(
name
.
c_str
());
CosNaming
::
NamingContext_var
in_ctx
=
ORepHelpers
::
getContext
(
in_sec
,
argc
,
argv
,
nsName
);
ctx
->
destroy
();
in_ctx
->
unbind
(
ctxName
);
}
catch
(
const
CosNaming
::
NamingContext
::
NotEmpty
&
ne
)
{
ulogrep
<<
"ORepFactory: контекст"
<<
fullName
<<
" не пустой "
<<
endl
;
rem
=
false
;
}
catch
(
ORepFailed
)
{
ulogrep
<<
"ORepFactory: не удаось получить ссылку на контекст "
<<
in_sec
<<
endl
;
rem
=
false
;
}
}
if
(
!
CORBA
::
is_nil
(
bi
)
)
bi
->
destroy
();
// ??
return
rem
;
}
// -----------------------------------------------------------------------------------------------------------
/*!
* \param newFName - полное имя новой секции
* \param oldFName - полное имя удаляемрй секции
*/
bool
ObjectRepository
::
renameSection
(
const
string
&
newFName
,
const
string
&
oldFName
)
{
string
newName
(
ObjectIndex
::
getBaseName
(
newFName
));
string
oldName
(
ObjectIndex
::
getBaseName
(
oldFName
));
CosNaming
::
Name_var
ctxNewName
=
omniURI
::
stringToName
(
newName
.
c_str
());
CosNaming
::
Name_var
ctxOldName
=
omniURI
::
stringToName
(
oldName
.
c_str
());
string
in_sec
(
ORepHelpers
::
getSectionName
(
newFName
));
try
{
int
argc
(
uconf
->
getArgc
());
const
char
*
const
*
argv
(
uconf
->
getArgv
());
CosNaming
::
NamingContext_var
in_ctx
=
ORepHelpers
::
getContext
(
in_sec
,
argc
,
argv
,
nsName
);
CosNaming
::
NamingContext_var
ctx
=
ORepHelpers
::
getContext
(
oldFName
,
argc
,
argv
,
nsName
);
// заменит контекст newFName если он существовал
in_ctx
->
rebind_context
(
ctxNewName
,
ctx
);
in_ctx
->
unbind
(
ctxOldName
);
}
catch
(
ORepFailed
)
{
return
false
;
}
return
true
;
}
// -----------------------------------------------------------------------------------------------------------
src/ObjectRepository/ObjectRepositoryFactory.cc
deleted
100644 → 0
View file @
24d1baff
/*
* Copyright (c) 2015 Pavel Vainerman.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 2.1.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// --------------------------------------------------------------------------
/*! \file
* \author Pavel Vainerman
*/
// --------------------------------------------------------------------------
#include <omniORB4/CORBA.h>
#include <omniORB4/omniURI.h>
#include <string.h>
#include <sstream>
#include "ObjectRepositoryFactory.h"
#include "ORepHelpers.h"
#include "Configuration.h"
#include "Debug.h"
// ---------------------------------------------------------------------------------------------------------------
using
namespace
UniSetTypes
;
using
namespace
std
;
using
namespace
omni
;
// ---------------------------------------------------------------------------------------------------------------
ObjectRepositoryFactory
::
ObjectRepositoryFactory
(
const
std
::
shared_ptr
<
UniSetTypes
::
Configuration
>&
_conf
)
:
ObjectRepository
(
_conf
)
{
}
ObjectRepositoryFactory
::~
ObjectRepositoryFactory
()
{
}
// -------------------------------------------------------------------------------------------------------
/*!
* \param name - имя создаваемой секции
* \param in_section - полное имя секции внутри которой создается новая
* \param section - полное имя секции начиная с Root.
* \exception ORepFailed - генерируется если произошла при получении доступа к секции
*/
bool
ObjectRepositoryFactory
::
createSection
(
const
string
&
name
,
const
string
&
in_section
)
throw
(
ORepFailed
,
InvalidObjectName
)
{
char
bad
=
ORepHelpers
::
checkBadSymbols
(
name
);
if
(
bad
!=
0
)
{
ostringstream
err
;
err
<<
"ObjectRepository(registration): (InvalidObjectName) "
<<
name
;
err
<<
" содержит недопустимый символ "
<<
bad
;
throw
(
InvalidObjectName
(
err
.
str
().
c_str
())
);
}
ulogrep
<<
"CreateSection: name = "
<<
name
<<
" in section = "
<<
in_section
<<
endl
;
if
(
in_section
.
empty
()
)
{
ulogrep
<<
"CreateSection: in_section..empty"
<<
endl
;
return
createRootSection
(
name
);
}
int
argc
(
uconf
->
getArgc
());
const
char
*
const
*
argv
(
uconf
->
getArgv
());
CosNaming
::
NamingContext_var
ctx
=
ORepHelpers
::
getContext
(
in_section
,
argc
,
argv
,
uconf
->
getNSName
()
);
return
createContext
(
name
,
ctx
.
in
()
);
}
// -------------------------------------------------------------------------------------------------------
/*!
* \param fullName - полное имя создаваемой секции
* \exception ORepFailed - генерируется если произошла при получении доступа к секции
*/
bool
ObjectRepositoryFactory
::
createSectionF
(
const
string
&
fullName
)
throw
(
ORepFailed
,
InvalidObjectName
)
{
string
name
(
ObjectIndex
::
getBaseName
(
fullName
));
string
sec
(
ORepHelpers
::
getSectionName
(
fullName
));
ulogrep
<<
name
<<
endl
;
ulogrep
<<
sec
<<
endl
;
if
(
sec
.
empty
()
)
{
ulogrep
<<
"SectionName is empty!!!"
<<
endl
;
ulogrep
<<
"Добавляем в "
<<
uconf
->
getRootSection
()
<<
endl
;
return
createSection
(
name
,
uconf
->
getRootSection
());
}
else
return
createSection
(
name
,
sec
);
}
// ---------------------------------------------------------------------------------------------------------------
bool
ObjectRepositoryFactory
::
createRootSection
(
const
string
&
name
)
{
CORBA
::
ORB_var
orb
=
uconf
->
getORB
();
CosNaming
::
NamingContext_var
ctx
=
ORepHelpers
::
getRootNamingContext
(
orb
,
uconf
->
getNSName
());
return
createContext
(
name
,
ctx
);
}
// -----------------------------------------------------------------------------------------------------------
bool
ObjectRepositoryFactory
::
createContext
(
const
string
&
cname
,
CosNaming
::
NamingContext_ptr
ctx
)
{
CosNaming
::
Name_var
nc
=
omniURI
::
stringToName
(
cname
.
c_str
());
try
{
ulogrep
<<
"ORepFactory(createContext): создаю новый контекст "
<<
cname
<<
endl
;
ctx
->
bind_new_context
(
nc
);
ulogrep
<<
"ORepFactory(createContext): создал. "
<<
endl
;
return
true
;
}
catch
(
const
CosNaming
::
NamingContext
::
AlreadyBound
&
ab
)
{
// ctx->resolve(nc);
ulogrep
<<
"ORepFactory(createContext): context "
<<
cname
<<
" уже есть"
<<
endl
;
return
true
;
}
catch
(
const
CosNaming
::
NamingContext
::
NotFound
)
{
ulogrep
<<
"ORepFactory(createContext): NotFound "
<<
cname
<<
endl
;
throw
NameNotFound
();
}
catch
(
const
CosNaming
::
NamingContext
::
InvalidName
&
nf
)
{
uwarn
<<
"ORepFactory(createContext): (InvalidName) "
<<
cname
;
}
catch
(
const
CosNaming
::
NamingContext
::
CannotProceed
&
cp
)
{
uwarn
<<
"ORepFactory(createContext): catch CannotProced "
<<
cname
<<
" bad part="
<<
omniURI
::
nameToString
(
cp
.
rest_of_name
);
throw
NameNotFound
();
}
catch
(
const
CORBA
::
SystemException
&
ex
)
{
ucrit
<<
"ORepFactory(createContext): CORBA::SystemException: "
<<
ex
.
NP_minorString
()
<<
endl
;
}
catch
(
const
CORBA
::
Exception
&
)
{
ucrit
<<
"поймали CORBA::Exception."
<<
endl
;
}
catch
(
const
omniORB
::
fatalException
&
fe
)
{
ucrit
<<
"поймали omniORB::fatalException:"
<<
endl
;
ucrit
<<
" file: "
<<
fe
.
file
()
<<
endl
;
ucrit
<<
" line: "
<<
fe
.
line
()
<<
endl
;
ucrit
<<
" mesg: "
<<
fe
.
errmsg
()
<<
endl
;
}
return
false
;
}
// -----------------------------------------------------------------------------------------------------------
/*!
\note Функция не вывести список, если не сможет получить доступ к секции
*/
void
ObjectRepositoryFactory
::
printSection
(
const
string
&
fullName
)
{
ListObjectName
ls
;
try
{
list
(
fullName
.
c_str
(),
&
ls
);
if
(
ls
.
empty
()
)
cout
<<
fullName
<<
" пуст!!!"
<<
endl
;
}
catch
(
ORepFailed
)
{
cout
<<
"printSection: cath exceptions ORepFailed..."
<<
endl
;
return
;
}
cout
<<
fullName
<<
"("
<<
ls
.
size
()
<<
"):"
<<
endl
;
for
(
auto
v
:
ls
)
cout
<<
v
<<
endl
;
}
// -----------------------------------------------------------------------------------------------------------
/*!
* \param fullName - имя удаляемой секции
* \param recursive - удлаять рекурсивно все секции или возвращать не удалять и ошибку ( временно )
* \warning Функция вынимает только первые 1000 объектов, остальные игнорируются...
*/
bool
ObjectRepositoryFactory
::
removeSection
(
const
string
&
fullName
,
bool
recursive
)
{
// string name = getName(fullName.c_str(),'/');
// string sec = getSectionName(fullName.c_str(),'/');
// CosNaming::NamingContext_var ctx = getContext(sec, argc, argv);
unsigned
int
how_many
=
1000
;
CosNaming
::
NamingContext_var
ctx
;
try
{
int
argc
(
uconf
->
getArgc
());
const
char
*
const
*
argv
(
uconf
->
getArgv
());
ctx
=
ORepHelpers
::
getContext
(
fullName
,
argc
,
argv
,
nsName
);
}
catch
(
ORepFailed
)
{
return
false
;
}
CosNaming
::
BindingList_var
bl
;
CosNaming
::
BindingIterator_var
bi
;
ctx
->
list
(
how_many
,
bl
,
bi
);
// хитрая проверка на null приобращении к bl
// coverity говорит потенциально это возможно
// т.к. там возвращается указатель, который по умолчанию null
if
(
!
bl
.
operator
->
()
)
return
false
;
if
(
how_many
>
bl
->
length
()
)
how_many
=
bl
->
length
();
bool
rem
=
true
;
// удалять или нет
for
(
unsigned
int
i
=
0
;
i
<
how_many
;
i
++
)
{
if
(
bl
[
i
].
binding_type
==
CosNaming
::
nobject
)
{
// cout <<"удаляем "<< omniURI::nameToString(bl[i].binding_name) << endl;
ctx
->
unbind
(
bl
[
i
].
binding_name
);
}
else
if
(
bl
[
i
].
binding_type
==
CosNaming
::
ncontext
)
{
if
(
recursive
)
{
ulogrep
<<
"ORepFactory: удаляем рекурсивно..."
<<
endl
;
string
rctx
=
fullName
+
"/"
+
omniURI
::
nameToString
(
bl
[
i
].
binding_name
);
ulogrep
<<
rctx
<<
endl
;
if
(
!
removeSection
(
rctx
))
{
ulogrep
<<
"рекурсивно удалить не удалось"
<<
endl
;
rem
=
false
;
}
}
else
{
ulogrep
<<
"ORepFactory: "
<<
omniURI
::
nameToString
(
bl
[
i
].
binding_name
)
<<
" - контекст!!! "
;
ulogrep
<<
"ORepFactory: пока не удаляем"
<<
endl
;
rem
=
false
;
}
}
}
// Удаляем контекст, если он уже пустой
if
(
rem
)
{
// Получаем имя контекста содержащего удаляемый
string
in_sec
(
ORepHelpers
::
getSectionName
(
fullName
));
//Получаем имя удаляемого контекста
string
name
(
ObjectIndex
::
getBaseName
(
fullName
));
try
{
int
argc
(
uconf
->
getArgc
());
const
char
*
const
*
argv
(
uconf
->
getArgv
());
CosNaming
::
Name_var
ctxName
=
omniURI
::
stringToName
(
name
.
c_str
());
CosNaming
::
NamingContext_var
in_ctx
=
ORepHelpers
::
getContext
(
in_sec
,
argc
,
argv
,
nsName
);
ctx
->
destroy
();
in_ctx
->
unbind
(
ctxName
);
}
catch
(
const
CosNaming
::
NamingContext
::
NotEmpty
&
ne
)
{
ulogrep
<<
"ORepFactory: контекст"
<<
fullName
<<
" не пустой "
<<
endl
;
rem
=
false
;
}
catch
(
ORepFailed
)
{
ulogrep
<<
"ORepFactory: не удаось получить ссылку на контекст "
<<
in_sec
<<
endl
;
rem
=
false
;
}
}
if
(
!
CORBA
::
is_nil
(
bi
)
)
bi
->
destroy
();
// ??
return
rem
;
}
// -----------------------------------------------------------------------------------------------------------
/*!
* \param newFName - полное имя новой секции
* \param oldFName - полное имя удаляемрй секции
*/
bool
ObjectRepositoryFactory
::
renameSection
(
const
string
&
newFName
,
const
string
&
oldFName
)
{
string
newName
(
ObjectIndex
::
getBaseName
(
newFName
));
string
oldName
(
ObjectIndex
::
getBaseName
(
oldFName
));
CosNaming
::
Name_var
ctxNewName
=
omniURI
::
stringToName
(
newName
.
c_str
());
CosNaming
::
Name_var
ctxOldName
=
omniURI
::
stringToName
(
oldName
.
c_str
());
string
in_sec
(
ORepHelpers
::
getSectionName
(
newFName
));
try
{
int
argc
(
uconf
->
getArgc
());
const
char
*
const
*
argv
(
uconf
->
getArgv
());
CosNaming
::
NamingContext_var
in_ctx
=
ORepHelpers
::
getContext
(
in_sec
,
argc
,
argv
,
nsName
);
CosNaming
::
NamingContext_var
ctx
=
ORepHelpers
::
getContext
(
oldFName
,
argc
,
argv
,
nsName
);
// заменит контекст newFName если он существовал
in_ctx
->
rebind_context
(
ctxNewName
,
ctx
);
in_ctx
->
unbind
(
ctxOldName
);
}
catch
(
ORepFailed
)
{
return
false
;
}
return
true
;
}
// -----------------------------------------------------------------------------------------------------------
uniset2.files
View file @
8d8de61d
...
...
@@ -302,7 +302,6 @@ include/ObjectIndex_Array.h
include/ObjectIndex_idXML.h
include/ObjectIndex_XML.h
include/ObjectRepository.h
include/ObjectRepositoryFactory.h
include/OmniThreadCreator.h
include/ORepHelpers.h
include/PassiveObject.h
...
...
@@ -396,7 +395,6 @@ src/ObjectRepository/ObjectIndex_Array.cc
src/ObjectRepository/ObjectIndex_idXML.cc
src/ObjectRepository/ObjectIndex_XML.cc
src/ObjectRepository/ObjectRepository.cc
src/ObjectRepository/ObjectRepositoryFactory.cc
src/ObjectRepository/ORepHelpers.cc
src/ObjectRepository/PassiveObject.cc
src/ObjectRepository/ProxyManager.cc
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment