00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #define DATASVC_DATASVC_CPP
00021
00022
00023 #include <cstdlib>
00024 #include <vector>
00025 #include <algorithm>
00026
00027 #include "GaudiKernel/IConverter.h"
00028 #include "GaudiKernel/IDataDirectory.h"
00029 #include "GaudiKernel/IOpaqueAddress.h"
00030 #include "GaudiKernel/IConversionSvc.h"
00031
00032 #include "GaudiKernel/xtoa.h"
00033 #include "GaudiKernel/SvcFactory.h"
00034 #include "GaudiKernel/DataObject.h"
00035 #include "GaudiKernel/GaudiException.h"
00036
00037 #include "GaudiKernel/TransientStore.h"
00038 #include "GaudiKernel/RegistryEntry.h"
00039 #include "GaudiKernel/DataSvc.h"
00040
00041 extern const CLID CLID_Event;
00042
00043
00044
00045 static SvcFactory<DataSvc> s_factory;
00046 const ISvcFactory& DataSvcFactory = s_factory;
00047
00049 StatusCode DataSvc::clearSubTree(const std::string& sub_tree_path) {
00050 if ( checkRoot() ) {
00051 RegistryEntry* node_entry = m_root->findLeaf(sub_tree_path);
00052 if ( 0 != node_entry ) {
00053 RegistryEntry* parent = node_entry->parentEntry();
00054 if ( 0 != parent ) {
00055 parent->remove(node_entry);
00056 return SUCCESS;
00057 }
00058 return INVALID_PARENT;
00059 }
00060 return INVALID_OBJECT;
00061 }
00062 return INVALID_ROOT;
00063 }
00064
00066 StatusCode DataSvc::clearSubTree(DataObject* pObject) {
00067 if ( checkRoot() ) {
00068 RegistryEntry* entry = dynamic_cast<RegistryEntry*>(pObject->directory());
00069 if ( 0 != entry ) {
00070 RegistryEntry* parent = entry->parentEntry();
00071 if ( 0 != parent ) {
00072 parent->remove(entry);
00073 return SUCCESS;
00074 }
00075 return INVALID_PARENT;
00076 }
00077 return INVALID_OBJECT;
00078 }
00079 return INVALID_ROOT;
00080 }
00081
00083 StatusCode DataSvc::clearStore() {
00084 if ( checkRoot() ) {
00085 m_root->release();
00086 m_root = 0;
00087 return SUCCESS;
00088 }
00089 return INVALID_ROOT;
00090 }
00091
00093 StatusCode DataSvc::traverseSubTree ( const std::string& sub_tree_path,IDataStoreAgent* pAgent ) {
00094 if ( checkRoot() ) {
00095 RegistryEntry* entry = m_root->findLeaf(sub_tree_path);
00096 if ( 0 != entry ) {
00097 return entry->traverseTree(pAgent);
00098 }
00099 return INVALID_OBJECT;
00100 }
00101 return INVALID_ROOT;
00102 }
00103
00105 StatusCode DataSvc::traverseSubTree ( DataObject* pObject,IDataStoreAgent* pAgent ) {
00106 if ( checkRoot() ) {
00107 RegistryEntry* entry = dynamic_cast<RegistryEntry*>(pObject->directory());
00108 if ( 0 != entry ) {
00109 return entry->traverseTree(pAgent);
00110 }
00111 return INVALID_OBJECT;
00112 }
00113 return INVALID_ROOT;
00114 }
00115
00117 StatusCode DataSvc::traverseTree(IDataStoreAgent* pAgent) {
00118 if ( checkRoot() ) {
00119 return m_root->traverseTree(pAgent);
00120 }
00121 return INVALID_ROOT;
00122 }
00123
00125 StatusCode DataSvc::setRoot(const std::string& root_path, DataObject* pRootObj) {
00126 clearStore();
00127 if ( 0 != pRootObj ) {
00128 m_root = new RegistryEntry(root_path);
00129 m_root->makeHard(pRootObj);
00130 preLoad();
00131 }
00132 return SUCCESS;
00133 }
00134
00136 StatusCode DataSvc::setRoot(const std::string& root_path, IOpaqueAddress* pRootAddr) {
00137 clearStore();
00138 if ( 0 != pRootAddr ) {
00139 m_root = new RegistryEntry(root_path);
00140 m_root->makeHard(pRootAddr);
00141 preLoad();
00142 }
00143 return SUCCESS;
00144 }
00145
00147 StatusCode DataSvc::setDataLoader(IConversionSvc* pDataLoader) {
00148 if ( 0 != pDataLoader ) pDataLoader->addRef();
00149 if ( 0 != m_dataLoader ) m_dataLoader->release();
00150 m_dataLoader = pDataLoader;
00151 return SUCCESS;
00152 }
00153
00155 StatusCode DataSvc::registerObject(const std::string& fullPath, DataObject* pObject) {
00156 if ( checkRoot() ) {
00157 RegistryEntry* node_entry = m_root->findParent(fullPath);
00158 if ( 0 != node_entry ) {
00159 int loc = fullPath.rfind(IDataDirectory::SEPARATOR);
00160 std::string obj_name(fullPath, loc, fullPath.length()-loc);
00161 StatusCode status = node_entry->add( obj_name, pObject );
00162 return status.isSuccess() ? status.getCode() : DOUBL_OBJ_PATH;
00163 }
00164 return INVALID_PARENT;
00165 }
00166 return INVALID_ROOT;
00167 }
00168
00169
00171 StatusCode DataSvc::registerObject(const std::string& parentPath, const std::string& objPath, DataObject* pObject) {
00172 if ( checkRoot() ) {
00173 RegistryEntry* node_entry = m_root->findLeaf(parentPath);
00174 if ( 0 != node_entry ) {
00175 StatusCode status = node_entry->add( objPath, pObject );
00176 return status.isSuccess() ? status.getCode() : DOUBL_OBJ_PATH;
00177 }
00178 return INVALID_PARENT;
00179 }
00180 return INVALID_ROOT;
00181 }
00182
00184 StatusCode DataSvc::registerObject(const std::string& parentPath, int item, DataObject* pObject) {
00185 if ( checkRoot() ) {
00186 RegistryEntry* node_entry = m_root->findLeaf(parentPath);
00187 if ( 0 != node_entry ) {
00188 char buffer[32] = "/";
00189 _itoa( item, &buffer[1] , 10 );
00190 StatusCode status = node_entry->add( buffer, pObject );
00191 return status.isSuccess() ? status.getCode() : DOUBL_OBJ_PATH;
00192 }
00193 return INVALID_PARENT;
00194 }
00195 return INVALID_ROOT;
00196 }
00197
00199 StatusCode DataSvc::registerObject(DataObject* parentObj, const std::string& objPath, DataObject* pObject) {
00200 if ( checkRoot() ) {
00201 RegistryEntry* node_entry = m_root->findLeaf(parentObj);
00202 if ( 0 != node_entry ) {
00203 StatusCode status;
00204 int sep = objPath.rfind(IDataDirectory::SEPARATOR);
00205 if ( sep > 0 ) {
00206 std::string p_path (objPath, 0, sep);
00207 std::string o_path (objPath, sep, objPath.length());
00208 node_entry = m_root->findLeaf(p_path);
00209 if ( 0 != node_entry ) {
00210 status = registerObject( node_entry->object(), o_path, pObject );
00211 }
00212 else {
00213 status = INVALID_PARENT;
00214 }
00215 }
00216 else {
00217 status = node_entry->add( objPath, pObject );
00218 }
00219 return status.isSuccess() ? status.getCode() : DOUBL_OBJ_PATH;
00220 }
00221 return INVALID_PARENT;
00222 }
00223 return INVALID_ROOT;
00224 }
00225
00227 StatusCode DataSvc::registerObject(DataObject* parentObj, int item, DataObject* pObject) {
00228 if ( checkRoot() ) {
00229 RegistryEntry* node_entry = m_root->findLeaf(parentObj);
00230 if ( 0 != node_entry ) {
00231 char buffer[32] = "/";
00232 _itoa( item, &buffer[1] , 10 );
00233 StatusCode status = node_entry->add( buffer, pObject );
00234 return status.isSuccess() ? status.getCode() : DOUBL_OBJ_PATH;
00235 }
00236 return INVALID_PARENT;
00237 }
00238 return INVALID_ROOT;
00239 }
00240
00242 StatusCode DataSvc::unregisterObject(const std::string& fullPath) {
00243 if ( checkRoot() ) {
00244 RegistryEntry* parent = m_root->findParent(fullPath);
00245 if ( 0 != parent ) {
00246 int loc = fullPath.rfind(IDataDirectory::SEPARATOR);
00247 std::string obj(fullPath, loc, fullPath.length()-loc);
00248 RegistryEntry* entry = parent->findLeaf(obj);
00249 if ( 0 != entry ) {
00250 if ( entry->isEmpty() ) {
00251 if ( 0 != entry->object() ) {
00252 entry->object()->addRef();
00253 }
00254 parent->remove(entry);
00255 return SUCCESS;
00256 }
00257 return DIR_NOT_EMPTY;
00258 }
00259 return INVALID_OBJECT;
00260 }
00261 return INVALID_PARENT;
00262 }
00263 return INVALID_ROOT;
00264 }
00265
00267 StatusCode DataSvc::unregisterObject(const std::string& parentPath, const std::string& objPath) {
00268 if ( checkRoot() ) {
00269 RegistryEntry* parent = m_root->findLeaf(parentPath);
00270 if ( 0 != parent ) {
00271 RegistryEntry* entry = parent->findLeaf(objPath);
00272 if ( 0 != entry ) {
00273 if ( entry->isEmpty() ) {
00274 if ( 0 != entry->object() ) {
00275 entry->object()->addRef();
00276 }
00277 parent->remove(entry);
00278 return SUCCESS;
00279 }
00280 return DIR_NOT_EMPTY;
00281 }
00282 return INVALID_OBJECT;
00283 }
00284 return INVALID_PARENT;
00285 }
00286 return INVALID_ROOT;
00287 }
00288
00290 StatusCode DataSvc::unregisterObject(const std::string& parentPath, int item) {
00291 if ( checkRoot() ) {
00292 RegistryEntry* parent = m_root->findLeaf(parentPath);
00293 if ( 0 != parent ) {
00294 char objPath[32] = "/";
00295 _itoa( item, &objPath[1] , 10 );
00296 RegistryEntry* entry = parent->findLeaf(objPath);
00297 if ( 0 != entry ) {
00298 if ( entry->isEmpty() ) {
00299 if ( 0 != entry->object() ) {
00300 entry->object()->addRef();
00301 }
00302 parent->remove(entry);
00303 return SUCCESS;
00304 }
00305 return DIR_NOT_EMPTY;
00306 }
00307 return INVALID_OBJECT;
00308 }
00309 return INVALID_PARENT;
00310 }
00311 return INVALID_ROOT;
00312 }
00313
00315 StatusCode DataSvc::unregisterObject(DataObject* pObject) {
00316 if ( checkRoot() ) {
00317 RegistryEntry* parent = m_root->findParent(pObject);
00318 if ( 0 != parent ) {
00319 RegistryEntry* entry = parent->findLeaf(pObject);
00320 if ( 0 != entry ) {
00321 if ( entry->isEmpty() ) {
00322 if ( 0 != entry->object() ) {
00323 entry->object()->addRef();
00324 }
00325 parent->remove(entry);
00326 return SUCCESS;
00327 }
00328 return DIR_NOT_EMPTY;
00329 }
00330 return INVALID_OBJECT;
00331 }
00332 return INVALID_PARENT;
00333 }
00334 return INVALID_ROOT;
00335 }
00336
00338 StatusCode DataSvc::unregisterObject(DataObject* pParentObj, const std::string& objectPath) {
00339 if ( checkRoot() ) {
00340 try {
00341 RegistryEntry* parent = dynamic_cast<RegistryEntry*>(pParentObj->directory());
00342 if ( 0 != parent ) {
00343 RegistryEntry* entry = parent->findLeaf(objectPath);
00344 if ( 0 != entry ) {
00345 if ( entry->isEmpty() ) {
00346 if ( 0 != entry->object() ) {
00347 entry->object()->addRef();
00348 }
00349 parent->remove(entry);
00350 return SUCCESS;
00351 }
00352 return DIR_NOT_EMPTY;
00353 }
00354 return INVALID_OBJECT;
00355 }
00356 }
00357 catch(...) {
00358 }
00359 return INVALID_PARENT;
00360 }
00361 return INVALID_ROOT;
00362 }
00363
00365 StatusCode DataSvc::unregisterObject(DataObject* pParentObj, int item) {
00366 if ( checkRoot() ) {
00367 try {
00368 RegistryEntry* parent = dynamic_cast<RegistryEntry*>(pParentObj->directory());
00369 if ( 0 != parent ) {
00370 char objPath[32] = "/";
00371 _itoa( item, &objPath[1] , 10 );
00372 RegistryEntry* entry = parent->findLeaf(objPath);
00373 if ( 0 != entry ) {
00374 if ( entry->isEmpty() ) {
00375 if ( 0 != entry->object() ) {
00376 entry->object()->addRef();
00377 }
00378 parent->remove(entry);
00379 return SUCCESS;
00380 }
00381 return DIR_NOT_EMPTY;
00382 }
00383 return INVALID_OBJECT;
00384 }
00385 }
00386 catch(...) {
00387 }
00388 return INVALID_PARENT;
00389 }
00390 return INVALID_ROOT;
00391 }
00392
00393 StatusCode DataSvc::loadObject(IDataDirectory* pDirectory) {
00394 StatusCode status = INVALID_OBJ_ADDR;
00395 DataObject* obj = 0;
00396 if ( 0 == m_dataLoader ) {
00397 return NO_DATA_LOADER;
00398 }
00399 if ( 0 == pDirectory->address() ) {
00400 return INVALID_OBJ_ADDR;
00401 }
00402 try {
00403 RegistryEntry *pEntry = dynamic_cast<RegistryEntry*>(pDirectory);
00404 pEntry->address()->setDirectory( pEntry );
00405 status = m_dataLoader->createObj(pEntry->address(), obj);
00406 if ( status.isSuccess() ) {
00407 obj->setDirectory (pEntry);
00408 pEntry->setObject(obj);
00409 }
00410 }
00411 catch( const GaudiException& exc ) {
00412 throw GaudiException("GaudiException in loadObject() " + pDirectory->name(),
00413 name(), StatusCode::FAILURE, exc);
00414 }
00415 catch( const std::exception& ) {
00416 throw GaudiException("std::exception in loadObject() " + pDirectory->name(),
00417 name(), StatusCode::FAILURE);
00418 }
00419 catch(...) {
00420 throw GaudiException("UNKN exception in loadObject() " + pDirectory->name(),
00421 name(), StatusCode::FAILURE);
00422 }
00423 return status;
00424 }
00425
00427 StatusCode DataSvc::retrieveEntry(RegistryEntry* parentObj, const std::string& path, RegistryEntry*& pEntry) {
00428 int sep = path.find(IDataDirectory::SEPARATOR,1);
00429 StatusCode status = INVALID_ROOT;
00430
00431 pEntry = 0;
00432 if ( sep > 0 ) {
00433 std::string p_path (path,0,sep);
00434 std::string o_path (path,sep,path.length());
00435 RegistryEntry* root_entry = parentObj->findLeaf(p_path);
00436 if ( 0 != root_entry ) {
00437 if ( 0 == root_entry->object() ) {
00438
00439 status = loadObject(root_entry);
00440 if ( !status.isSuccess() ) {
00441 return status;
00442 }
00443 }
00444 status = retrieveEntry (root_entry, o_path, pEntry);
00445 }
00446 return status;
00447 }
00448
00449 if ( 0 == (pEntry=parentObj->findLeaf(path)) )
00450 status = INVALID_OBJ_PATH;
00451 else if ( 0 == pEntry->object() )
00452 status = loadObject(pEntry);
00453 else
00454 status = SUCCESS;
00455 return status;
00456 }
00457
00459 StatusCode DataSvc::retrieveObject(IDataDirectory* pDirectory, const std::string& path, DataObject*& pObject) {
00460 StatusCode status = StatusCode::FAILURE;
00461 pObject = 0;
00462 if ( 0 != pDirectory ) {
00463 if ( path.length() == 0) {
00464 if ( pDirectory->object() == 0 )
00465 status = loadObject(pDirectory);
00466 else
00467 status = StatusCode::SUCCESS;
00468 }
00469 else {
00470 RegistryEntry* parent = dynamic_cast<RegistryEntry*>(pDirectory);
00471 RegistryEntry* result = 0;
00472 status = retrieveEntry(parent, path, result);
00473 pDirectory = result;
00474 }
00475 if ( status.isSuccess() ) {
00476 pObject = pDirectory->object();
00477 }
00478 }
00479 return status;
00480 }
00481
00483 StatusCode DataSvc::retrieveObject(const std::string& fullPath, DataObject*& pObject) {
00484 DataObject* pNullObject = 0;
00485 return retrieveObject(pNullObject, fullPath, pObject);
00486 }
00487
00489 StatusCode DataSvc::retrieveObject(const std::string& parentPath, const std::string& objectPath, DataObject*& pObject) {
00490 DataObject* parent = 0;
00491 StatusCode status = retrieveObject(parentPath, parent);
00492 if ( status.isSuccess() ) {
00493 status = retrieveObject (parent, objectPath, pObject);
00494 }
00495 return status;
00496 }
00497
00499 StatusCode DataSvc::retrieveObject(const std::string& parentPath, int item, DataObject*& pObject) {
00500 DataObject* parent = 0;
00501 StatusCode status = retrieveObject(parentPath, parent);
00502 if ( status.isSuccess() ) {
00503 status = retrieveObject (parent, item, pObject);
00504 }
00505 return status;
00506 }
00507
00509 StatusCode DataSvc::retrieveObject(DataObject* parentObj,const std::string& path,DataObject*& pObject) {
00510 StatusCode status = INVALID_ROOT;
00511 RegistryEntry *root_entry = 0, *entry = 0;
00512 pObject = 0;
00513 if ( checkRoot() ) {
00514 try {
00515 root_entry = (0==parentObj) ? m_root.door() : dynamic_cast<RegistryEntry*>(parentObj->directory());
00516 }
00517 catch (...) {
00518 return INVALID_PARENT;
00519 }
00520 status = retrieveEntry(root_entry,path,entry);
00521 if ( status.isSuccess() ) {
00522 pObject = entry->object();
00523 }
00524 }
00525 return status;
00526 }
00527
00529 StatusCode DataSvc::retrieveObject(DataObject* parentObj, int item, DataObject*& pObject) {
00530 char buffer[32] = "/";
00531 _itoa(item,&buffer[1],10);
00532 return retrieveObject(parentObj, buffer, pObject);
00533 }
00534
00536 StatusCode DataSvc::findObject(IDataDirectory* pDirectory, const std::string& path, DataObject*& pObject) {
00537 pObject = 0;
00538 if ( 0 != pDirectory ) {
00539 if ( path.length() > 0 ) {
00540 pDirectory = pDirectory->find(path);
00541 }
00542 if ( 0 != pDirectory ) {
00543 pObject = pDirectory->object();
00544 }
00545 }
00546 return (0 == pObject) ? OBJ_NOT_LOADED : SUCCESS;
00547 }
00548
00550 StatusCode DataSvc::findObject(const std::string& path, DataObject*& pObject) {
00551 pObject = 0;
00552 if ( checkRoot() ) {
00553 RegistryEntry* entry = m_root->findLeaf(path);
00554 if ( 0 != entry ) {
00555 pObject = entry->object();
00556 return (0 == pObject) ? OBJ_NOT_LOADED : SUCCESS;
00557 }
00558 return INVALID_OBJ_PATH;
00559 }
00560 return INVALID_ROOT;
00561 }
00562
00564 StatusCode DataSvc::findObject(const std::string& parentPath, const std::string& objectPath, DataObject*& pObject) {
00565 DataObject* parent = 0;
00566 StatusCode status = findObject(parentPath, parent);
00567 if ( status.isSuccess() ) {
00568 status = findObject (parent, objectPath, pObject);
00569 }
00570 return status;
00571 }
00572
00574 StatusCode DataSvc::findObject(const std::string& parentPath, int item, DataObject*& pObject) {
00575 DataObject* parent = 0;
00576 StatusCode status = findObject(parentPath, parent);
00577 if ( status.isSuccess() ) {
00578 status = findObject (parent, item, pObject);
00579 }
00580 return status;
00581 }
00582
00584 StatusCode DataSvc::findObject(DataObject* parentObj, int item, DataObject*& pObject) {
00585 char buffer[32] = "/";
00586 _itoa(item,&buffer[1],10);
00587 return findObject(parentObj, buffer, pObject);
00588 }
00589
00591 StatusCode DataSvc::findObject(DataObject* parentObj, const std::string& path, DataObject*& pObject) {
00592 pObject = 0;
00593 if ( checkRoot() ) {
00594 RegistryEntry* node_entry = (0==parentObj)
00595 ? m_root.door()
00596 : dynamic_cast<RegistryEntry*>(parentObj->directory());
00597 if ( 0 != node_entry ) {
00598 RegistryEntry *leaf = node_entry->findLeaf(path);
00599 if ( 0 == leaf ) {
00600 return INVALID_OBJ_PATH;
00601 }
00602 pObject = leaf->object();
00603 return (0 == pObject) ? OBJ_NOT_LOADED : SUCCESS;
00604 }
00605 return INVALID_PARENT;
00606 }
00607 return INVALID_ROOT;
00608 }
00609
00611 StatusCode DataSvc::updateObject(const std::string& updatePath) {
00612 if ( checkRoot() ) {
00613 RegistryEntry* entry = m_root->findLeaf(updatePath);
00614 if ( 0 != entry ) {
00615 if ( 0 != entry->object() ) {
00616 return updateObject( entry->object() );
00617 }
00618 return INVALID_OBJECT;
00619 }
00620 return INVALID_OBJ_PATH;
00621 }
00622 return INVALID_ROOT;
00623 }
00624
00626 StatusCode DataSvc::updateObject(IDataDirectory* pDirectory) {
00627 if ( 0 == pDirectory ) {
00628 return INVALID_OBJ_ADDR;
00629 }
00630 DataObject* toUpdate = pDirectory->object();
00631 if ( 0 == toUpdate ) {
00632 return loadObject(pDirectory);
00633 }
00634 return updateObject(toUpdate);
00635 }
00636
00638 StatusCode DataSvc::updateObject(DataObject* toUpdate) {
00639 StatusCode status = INVALID_OBJ_ADDR;
00640 if ( 0 == m_dataLoader ) {
00641 return NO_DATA_LOADER;
00642 }
00643 if ( 0 == toUpdate ) {
00644 return INVALID_OBJECT;
00645 }
00646 IDataDirectory* pDirectory = toUpdate->directory();
00647 if ( 0 == pDirectory ) {
00648 return INVALID_OBJ_ADDR;
00649 }
00650 try {
00651 status = m_dataLoader->updateObj(pDirectory->address(), toUpdate);
00652 }
00653 catch( const GaudiException& exc ) {
00654 throw GaudiException("GaudiException in updateObject() " + toUpdate->directory()->name(),
00655 name(), StatusCode::FAILURE, exc);
00656 }
00657 catch( const std::exception& ) {
00658 throw GaudiException("std::exception in updateObject() " + toUpdate->directory()->name(),
00659 name(), StatusCode::FAILURE);
00660 }
00661 catch(...) {
00662 throw GaudiException("UNKN exception in updateObject() " + toUpdate->directory()->name(),
00663 name(), StatusCode::FAILURE);
00664 }
00665 return status;
00666 }
00667
00669 StatusCode DataSvc::updateObject(const std::string& parentPath, const std::string& updatePath) {
00670 DataObject* pParent = 0;
00671 StatusCode status = findObject(parentPath, pParent);
00672 if ( status.isSuccess() ) {
00673 status = updateObject( pParent, updatePath);
00674 }
00675 return status;
00676 }
00677
00679 StatusCode DataSvc::updateObject(DataObject* parent, const std::string& updatePath) {
00680 DataObject* pObject = 0;
00681 StatusCode status = findObject(parent, updatePath, pObject);
00682 if ( status.isSuccess() ) {
00683 status = updateObject(pObject);
00684 }
00685 return status;
00686 }
00687
00688
00689 StatusCode DataSvc::linkObject(IDataDirectory* from, const std::string& objPath, DataObject* to) {
00690 try {
00691 RegistryEntry* from_entry = dynamic_cast<RegistryEntry*>(from);
00692 if ( 0 != from_entry ) {
00693
00694 RegistryEntry* to_entry = m_root->findLeaf(to);
00695 if ( 0 == to_entry ) {
00696 return INVALID_OBJECT;
00697 }
00698 else {
00699
00700 StatusCode status = from_entry->add( objPath, to, true);
00701 return status.isSuccess() ? StatusCode::SUCCESS : DOUBL_OBJ_PATH;
00702 }
00703 }
00704 }
00705 catch (...) {
00706 }
00707 return INVALID_PARENT;
00708 }
00709
00711 StatusCode DataSvc::linkObject(const std::string& fullPath, DataObject* to) {
00712 if ( checkRoot() ) {
00713 int sep = fullPath.rfind(IDataDirectory::SEPARATOR);
00714 std::string objPath(fullPath,sep,fullPath.length());
00715 std::string fromPath(fullPath,0,sep-1);
00716 return linkObject( fromPath, objPath, to);
00717 }
00718 return INVALID_ROOT;
00719 }
00720
00722 StatusCode DataSvc::linkObject(const std::string& from, const std::string& objPath, DataObject* to) {
00723 if ( checkRoot() ) {
00724 IDataDirectory* from_entry = m_root->findLeaf(from);
00725 return linkObject( from_entry, objPath, to);
00726 }
00727 return INVALID_ROOT;
00728 }
00729
00731 StatusCode DataSvc::linkObject(DataObject* from, const std::string& objPath, DataObject* to) {
00732 if ( checkRoot() ) {
00733 IDataDirectory* from_entry = m_root->findLeaf(from);
00734 return linkObject( from_entry, objPath, to);
00735 }
00736 return INVALID_ROOT;
00737 }
00738
00740 StatusCode DataSvc::unlinkObject(IDataDirectory* from, const std::string& objPath) {
00741 try {
00742 RegistryEntry* from_entry = dynamic_cast<RegistryEntry*>(from);
00743 if ( 0 != from_entry ) {
00744 return from_entry->remove( objPath );
00745 }
00746 }
00747 catch (...) {
00748 }
00749 return INVALID_PARENT;
00750 }
00751
00753 StatusCode DataSvc::unlinkObject(const std::string& fullPath) {
00754 if ( checkRoot() ) {
00755 IDataDirectory* entry = m_root->findLeaf(fullPath);
00756 if ( 0 != entry ) {
00757 IDataDirectory* from = entry->parent();
00758 int sep = fullPath.rfind(IDataDirectory::SEPARATOR);
00759 std::string objPath(fullPath,sep,fullPath.length());
00760 return unlinkObject(from, objPath);
00761 }
00762 return INVALID_OBJ_PATH;
00763 }
00764 return INVALID_ROOT;
00765 }
00766
00768 StatusCode DataSvc::unlinkObject(const std::string& from, const std::string& objPath) {
00769 if ( checkRoot() ) {
00770 IDataDirectory* from_entry = m_root->findLeaf(from);
00771 return unlinkObject(from_entry, objPath);
00772 }
00773 return INVALID_ROOT;
00774 }
00775
00777 StatusCode DataSvc::unlinkObject(DataObject* from, const std::string& objPath) {
00778 if ( checkRoot() ) {
00779 IDataDirectory* from_entry = m_root->findLeaf(from);
00780 return unlinkObject(from_entry, objPath);
00781 }
00782 return INVALID_ROOT;
00783 }
00784
00786 StatusCode DataSvc::updateRegistryEntry(IOpaqueAddress* pAddress, DataObject* pObj) {
00787 if ( !(0 == pObj || 0 == pAddress) ) {
00788 try {
00789 RegistryEntry* entry = dynamic_cast<RegistryEntry*>(pAddress->directory());
00790 if ( 0 != entry ) {
00791 pObj->setDirectory(entry);
00792 entry->setObject(pObj);
00793 if ( 0 == entry->address() ) {
00794 if ( 0 != pAddress && !entry->isSoft() ) {
00795 pAddress->setDirectory(entry);
00796 }
00797 entry->setAddress(pAddress);
00798 }
00799 return StatusCode::SUCCESS;
00800 }
00801 entry = dynamic_cast<RegistryEntry*>(pObj->directory());
00802 if ( 0 != entry ) {
00803 if ( 0 != pAddress && !entry->isSoft() ) {
00804 pAddress->setDirectory(entry);
00805 }
00806 entry->setAddress(pAddress);
00807 entry->setObject(pObj);
00808 return StatusCode::SUCCESS;
00809 }
00810 }
00811 catch (...) {
00812 }
00813 }
00814 return INVALID_OBJECT;
00815 }
00816
00818 StatusCode DataSvc::addPreLoadItem(const DataStoreItem& item) {
00819 LoadItems::iterator i = std::find(m_preLoads.begin(), m_preLoads.end(), item);
00820 if ( i == m_preLoads.end() ) {
00821 m_preLoads.push_back(item);
00822 }
00823 return StatusCode::SUCCESS;
00824 }
00825
00827 StatusCode DataSvc::addPreLoadItem(const std::string& itemPath) {
00828 return addPreLoadItem( DataStoreItem(itemPath,1) );
00829 }
00830
00832 StatusCode DataSvc::removePreLoadItem(const DataStoreItem& item) {
00833 LoadItems::iterator i = std::remove(m_preLoads.begin(), m_preLoads.end(), item);
00834 if ( i != m_preLoads.end() ) {
00835 m_preLoads.erase(i, m_preLoads.end());
00836 }
00837 return StatusCode::SUCCESS;
00838 }
00839
00841 StatusCode DataSvc::removePreLoadItem(const std::string& itemPath) {
00842 return removePreLoadItem( DataStoreItem(itemPath,1) );
00843 }
00844
00846 StatusCode DataSvc::resetPreLoad() {
00847 m_preLoads.erase(m_preLoads.begin(), m_preLoads.end());
00848 return StatusCode::SUCCESS;
00849 }
00850
00852 StatusCode DataSvc::preLoad(int depth, int load_depth, DataObject* pObject) {
00853
00854 if ( 0 != pObject && depth++ < load_depth ) {
00855 IDataDirectory* dir = pObject->directory();
00856 if ( 0 != dir ) {
00857 for (IDataDirectory::DirIterator i = dir->begin(); i != dir->end(); i++ ) {
00858 DataObject *pObj = 0;
00859 StatusCode status = retrieveObject(pObject, (*i)->name(), pObj);
00860 if ( status.isSuccess() && depth < load_depth ) {
00861 status = preLoad(depth, load_depth, pObj);
00862 }
00863 }
00864 }
00865 }
00866 return StatusCode::SUCCESS;
00867 }
00868
00870 StatusCode DataSvc::preLoad() {
00871 DataObject* pObj = 0;
00872 for ( LoadItems::iterator i = m_preLoads.begin(); i != m_preLoads.end(); i++ ) {
00873 StatusCode sc = retrieveObject( (*i).path(), pObj);
00874 int load_depth = (*i).depth();
00875 if ( sc.isSuccess() && load_depth > 1 ) {
00876 sc = preLoad(1, load_depth, pObj);
00877 }
00878 }
00879 return StatusCode::SUCCESS;
00880 }
00881
00883 StatusCode DataSvc::queryInterface(const IID& riid, void** ppvInterface) {
00884 if ( IID_IDataProviderSvc.versionMatch(riid) ) {
00885 *ppvInterface = (IDataProviderSvc*)this;
00886 }
00887 else if ( IID_IDataManagerSvc.versionMatch(riid) ) {
00888 *ppvInterface = (IDataManagerSvc*)this;
00889 }
00890 else {
00891 return Service::queryInterface(riid, ppvInterface);
00892 }
00893 addRef();
00894 return SUCCESS;
00895 }
00896
00898 StatusCode DataSvc::initialize() {
00899
00900 return Service::initialize();
00901 }
00902
00904 StatusCode DataSvc::finalize() {
00905
00906 setDataLoader(0);
00907 resetPreLoad();
00908 clearStore();
00909 return Service::finalize();
00910 }
00911
00913 CLID DataSvc::rootEventCLID() const {
00914 return( (CLID)m_rootEventCLID );
00915 }
00916
00918 std::string DataSvc::rootEventName() const {
00919 return( m_rootEventName );
00920 }
00921
00923 DataSvc::DataSvc(const std::string& name,ISvcLocator* svc)
00924 : Service(name,svc), m_root(0,0), m_rootEventCLID(CLID_Event),
00925 m_rootEventName( "/Event")
00926 {
00927 m_dataLoader = 0;
00928 m_root.setDataSvc(this);
00929 declareProperty("RootEventCLID", m_rootEventCLID);
00930 declareProperty("RootEventName", m_rootEventName = "/Event");
00931 }
00932
00934 DataSvc::~DataSvc() {
00935 setDataLoader(0);
00936 resetPreLoad();
00937 clearStore();
00938 }
00939