Commit b9ba3ef8 authored by Aleksandr Bakhshiev's avatar Aleksandr Bakhshiev
Browse files

Merge with RunTimeLibsTest

--HG--
branch : DataSrcs
......@@ -1613,7 +1613,7 @@ int UEngine::Storage_CreateClass(const char* stringid, const char *class_name, c
if(!library)
return RDK_E_STORAGE_COLLECTION_NOT_FOUND;
if(!Storage->AddClassToCollection(class_name, sample,library))
if(!Storage->AddClassToCollection(class_name, "", false, sample,collection_name))
return RDK_E_STORAGE_ADD_COLLECTION_FAIL;
AccessCache.clear();
......@@ -7356,6 +7356,7 @@ void UEngine::CreateEnvironment(bool isinit, list<UContainer*>* external_classes
}
Logger->LogMessage(RDK_EX_DEBUG, "Build storage has been started...");
Storage->InitRTlibs();
Storage->BuildStorage();
Logger->LogMessage(RDK_EX_DEBUG, "Build storage has been finished");
}
......
......@@ -205,7 +205,9 @@ int ULibrary::Upload(UStorage *storage)
CreateClassSamples(Storage);
count=int(Complete.size());
Storage=0;
// Storage RunTime
if(Type != 2)
Storage=0;
return count;
}
// --------------------------
......@@ -385,8 +387,8 @@ void ULibrary::RemoveClassFromCompletedList(const string &name)
// --------------------------
//
// --------------------------
URuntimeLibrary::URuntimeLibrary(const string &name, const string &version)
: ULibrary(name,version,2)
URuntimeLibrary::URuntimeLibrary(const string &name, const string &version, const string& path)
: ULibrary(name,version,2), LibPath(path)
{
}
......@@ -400,40 +402,120 @@ URuntimeLibrary::~URuntimeLibrary(void)
// --------------------------
//
// --------------------------
///
const USerStorageXML& URuntimeLibrary::GetClassesStructure(void) const
{
return ClassesStructure;
}
bool URuntimeLibrary::SetClassesStructure(const USerStorageXML& xml)
///
const std::string& URuntimeLibrary::GetLibPath() const
{
ClassesStructure=xml;
return true;
return LibPath;
}
bool URuntimeLibrary::SetClassesStructure(const std::string &buffer)
///
bool URuntimeLibrary::LoadCompDescriptions()
{
ClassesStructure.Load(buffer,"Library");
return true;
// xml
// ClassesStructures
std::vector<std::string> comp_descriptions;
if(RDK::FindFilesList(LibPath,"*.xml",true,comp_descriptions))
return false;
ClassesStructures.resize(comp_descriptions.size());
for(int i = 0 ; i < comp_descriptions.size(); i++)
{
//
CurrentComponentStruct.LoadFromFile(LibPath+"/"+comp_descriptions[i],"");
//
CurrentComponentStruct.Save(ClassesStructures[i]);
}
return true;
}
///
bool URuntimeLibrary::AddClassStructure(const std::string &buffer)
/// ( )
bool URuntimeLibrary::AddNewClass(const std::string &new_class_name, const std::string &new_comp_name, UContainer *newclass)
{
return true;
UEPtr<UContainer> p = newclass;
UEPtr<UNet> cont = dynamic_pointer_cast<UNet>(p);
if(!cont)
return false;
std::string buff;
// XML .
// Destroy() , . Create
CurrentComponentStruct.Create("stub");
CurrentComponentStruct.Destroy();
// XML RTname
if(!cont->SaveComponent(&CurrentComponentStruct, true, ptPubParameter))
return false;
CurrentComponentStruct.SelectNode(cont->GetName());
CurrentComponentStruct.RenameNode(new_comp_name);
CurrentComponentStruct.SetNodeAttribute("RTname", new_class_name);
CurrentComponentStruct.Save(buff);
CurrentComponentStruct.SaveToFile(LibPath+"/"+new_class_name+".xml");
UEPtr<UContainer> cont_1 = CreateClassSample(Storage, CurrentComponentStruct);
if(!cont_1)
return false;
if(!UploadClass(new_class_name, cont_1))
{
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "UploadClass failed while uploading \""+new_class_name + "\" class");
return false;
}
ClassesStructures.push_back(buff);
return true;
}
bool URuntimeLibrary::AddClassStructure(const USerStorageXML& xml)
/// Storage
bool URuntimeLibrary::DelClass(const std::string &class_name)
{
return true;
}
if(class_name.empty())
return false;
// .
if(Storage->CheckClass(class_name))
{
//
if(Storage->FindCollection(class_name).Get()!= static_cast<ULibrary*>(this))
{
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "\""+class_name + "\" class exists in another library. Not in \"" + Name +"\"");
return false;
}
//
Storage->DelClass(Storage->FindClassId(class_name));
}
//
for(vector<string>::iterator it = ClassesStructures.begin(); it != ClassesStructures.end(); ++it)
{
CurrentComponentStruct.Load(*it,"");
std::string search_name = CurrentComponentStruct.GetNodeAttribute("RTname");
if(class_name == search_name)
{
ClassesStructures.erase(it);
std::string xml_path = LibPath +"/" + search_name + ".xml";
RDK::RemoveFile(xml_path.c_str());
break;
}
}
return true;
}
///
bool URuntimeLibrary::UpdateClassesStructure(void)
bool URuntimeLibrary::DeleteOwnDirectory(void)
{
return true;
return (!RDK::DeleteDirectory(LibPath.c_str()));
}
// --------------------------
......@@ -444,17 +526,22 @@ UEPtr<UContainer> URuntimeLibrary::CreateClassSample(UStorage *storage, USerStor
UEPtr<UNet> cont;
if(!storage)
return 0;
return 0;
std::string class_name=xml.GetNodeAttribute("Class");
cont=dynamic_pointer_cast<UNet>(storage->TakeObject(class_name));
if(!cont)
return 0;
return 0;
if(!cont->LoadComponent(&xml,true))
{
storage->ReturnObject(cont);
return 0;
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Error while LoadComponent() from XML file for class \"" +class_name +"\"");
storage->ReturnObject(cont);
return 0;
}
return cont;
......@@ -464,22 +551,29 @@ UEPtr<UContainer> URuntimeLibrary::CreateClassSample(UStorage *storage, USerStor
// .
void URuntimeLibrary::CreateClassSamples(UStorage *storage)
{
ClassesStructure.SelectRoot();
int num_classes=ClassesStructure.GetNumNodes();
for(int i=0;i<num_classes;i++)
{
try
{
ClassesStructure.SelectNode(i);
UEPtr<UContainer> cont=CreateClassSample(storage, ClassesStructure);
UploadClass(std::string("T")+cont->GetName(),cont);
}
catch(UException &)
{
ClassesStructure.SelectUp();
}
ClassesStructure.SelectUp();
}
int num_classes = ClassesStructures.size();
for(int i=0;i<num_classes;i++)
{
try
{
CurrentComponentStruct.Load(ClassesStructures[i],"");
UEPtr<UContainer> cont=CreateClassSample(storage, CurrentComponentStruct);
if(!cont)
return;
std::string class_name=CurrentComponentStruct.GetNodeAttribute("RTname");
UploadClass(class_name,cont);
}
catch(UException &ex)
{
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, ex.what());
}
}
}
// --------------------------
......
......@@ -64,9 +64,12 @@ vector<string> Complete;
//
vector<string> Incomplete;
private: //
//
UStorage *Storage;
private: //
//
//UStorage *Storage;
// ,
//map<string, UComponent*> ClassSamples;
......@@ -190,31 +193,41 @@ protected: //
protected: //
protected: //
///
USerStorageXML ClassesStructure;
///
std::string LibPath;
/// XML
USerStorageXML CurrentComponentStruct;
/// (xml)
vector<string> ClassesStructures;
public: //
// --------------------------
//
// --------------------------
URuntimeLibrary(const string &name, const string &version);
URuntimeLibrary(const string &name, const string &version, const string& path);
virtual ~URuntimeLibrary(void);
// --------------------------
// --------------------------
//
// --------------------------
///
const USerStorageXML& GetClassesStructure(void) const;
bool SetClassesStructure(const USerStorageXML& xml);
bool SetClassesStructure(const std::string &buffer);
///
bool AddClassStructure(const std::string &buffer);
bool AddClassStructure(const USerStorageXML& xml);
///
const std::string& GetLibPath() const;
/// (, )
bool AddNewClass(const std::string &new_class_name, const std::string &new_comp_name, UContainer *newclass);
/// Storage
bool DelClass(const std::string &class_name);
///
bool LoadCompDescriptions(void);
///
bool UpdateClassesStructure(void);
///
bool DeleteOwnDirectory(void);
// --------------------------
// --------------------------
......
......@@ -117,6 +117,13 @@ UStorage::~UStorage(void)
{
ClearObjectsStorage(true);
ClearClassesStorage(true);
//
for(int i =0; i < CollectionList.size();i++)
{
DelCollection(i);
}
}
catch(EObjectStorageNotEmpty &ex)
{
......@@ -225,10 +232,14 @@ UId UStorage::AddClass(UEPtr<UComponentAbstractFactory> factory, const string &c
//
void UStorage::DelClass(const UId &classid, bool force)
{
UObjectsStorageCIterator temp=ObjectsStorage.find(classid);
UObjectsStorageIterator temp=ObjectsStorage.find(classid);
if(!force)
{
FreeObjectsStorageByClass(classid);
//
if(temp != ObjectsStorage.end() && temp->second.empty())
ObjectsStorage.erase(temp);
if(temp != ObjectsStorage.end() && temp->second.size() > 0)
throw EObjectStorageNotEmpty(classid);
}
......@@ -569,7 +580,7 @@ size_t UStorage::CalcNumObjects(const string &classname) const
}
//
//
void UStorage::FreeObjectsStorage(bool force)
{
for(UObjectsStorageIterator instances=ObjectsStorage.begin(),iend=ObjectsStorage.end();
......@@ -649,6 +660,79 @@ void UStorage::FreeObjectsStorage(bool force)
}
}
//
void UStorage::FreeObjectsStorageByClass(const UId &classid)
{
UObjectsStorageIterator instances=ObjectsStorage.find(classid);
if(instances==ObjectsStorage.end())
return;
std::string object_class_name=FindClassName(instances->first);
if(instances->second.empty())
return;
size_t size=instances->second.size();
size_t count=0;
if(Logger)
Logger->LogMessageEx(RDK_EX_DEBUG, __FUNCTION__, std::string("Destroy objects of class ")+object_class_name+" has begun");
for(list<UInstancesStorageElement>::iterator I=instances->second.begin(); I != instances->second.end();)
{
std::string object_name=I->Object->GetName();
if(I->UseFlag)
{
if(Logger)
Logger->LogMessageEx(RDK_EX_ERROR, __FUNCTION__, std::string("Can't destroy objects by name ")+object_name+": object in use!");
}
if(!I->UseFlag)
{
list<UInstancesStorageElement>::iterator K;
if(Logger)
Logger->LogMessageEx(RDK_EX_DEBUG, __FUNCTION__, std::string("Destroy objects by name ")+object_name);
K=I; ++K;
UEPtr<UContainer> object=I->Object;
PopObject(instances,I);
RDK_SYS_TRY
{
try
{
UVirtualMethodFactory* virtual_factory=FindVirualMethodFactory(object);
if(virtual_factory)
{
virtual_factory->FreeComponent();
}
delete object;
++count;
}
catch(...)
{
if(Logger)
Logger->LogMessageEx(RDK_EX_FATAL, __FUNCTION__, std::string("Exception raised when object ")+object_name);
}
}
RDK_SYS_CATCH
{
if(Logger)
Logger->ProcessException(RDK::UExceptionWrapperSEH(GET_SYSTEM_EXCEPTION_DATA));
}
I=K;
}
else
{
++I;
if(Logger)
Logger->LogMessageEx(RDK_EX_DEBUG, __FUNCTION__, std::string("Destroy objects by name ")+object_name+" FAILED! Object in use.");
}
}
if(Logger)
Logger->LogMessageEx(RDK_EX_DEBUG, __FUNCTION__, std::string("Destroy objects of class ")+object_class_name+std::string(" has finished: ")+sntoa(count)+std::string("/")+sntoa(size));
}
//
void UStorage::ClearObjectsStorage(bool force)
{
......@@ -673,7 +757,7 @@ void UStorage::ClearObjectsStorage(bool force)
FreeObjectsStorage(force);
}
//
//
void UStorage::ClearObjectsStorageByClass(const UId &classid)
{
UObjectsStorageIterator instances=ObjectsStorage.find(classid);
......@@ -877,62 +961,313 @@ const string& UStorage::GetCollectionVersion(int index)
{
return CollectionList[index]->GetVersion();
}
/*
//
bool UStorage::AddClass(UContainer *newclass)
{
UId classid=newclass->GetClass();
if(!AddClass(newclass,classid) == ForbiddenId)
return false;
return true;
} */
// runtime-,
// 'buffer'
void UStorage::GetRTlibsNameList(std::string &buffer) const
{
buffer.clear();
for(size_t i=0;i<CollectionList.size();i++)
{
UEPtr<ULibrary> lib = CollectionList[i];
if(lib && lib->GetType() == 2)
{
buffer.append(lib->GetName());
buffer.append(",");
}
}
if(!buffer.empty())
buffer.erase(buffer.length()-1);
}
///
bool UStorage::AddClassToCollection(const std::string &new_class_name, UContainer *newclass, URuntimeLibrary *library)
bool UStorage::AddClassToCollection(const std::string &new_class_name, const std::string &new_comp_name, bool force_replace, UContainer *newclass, const std::string &lib_name)
{
library->UploadClass(std::string("T")+newclass->GetName(),newclass);
return true;
if(new_class_name.empty())
return false;
//
URuntimeLibrary *library = 0;
for(size_t i=0;i<CollectionList.size();i++)
{
UEPtr<ULibrary> lib = CollectionList[i];
if(lib && lib->GetName() == lib_name)
{
library = dynamic_cast<URuntimeLibrary*>(lib.Get());
}
}
// runtime
if(!library || (library->GetType()!=2))
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library \"" +library->GetName() +"\" doesn't exist or it isn't runtime library");
return false;
}
//
if(CheckClass(new_class_name))
{
//
if(force_replace)
{
//
URuntimeLibrary *lib = static_cast<URuntimeLibrary*>(FindCollection(new_class_name).Get());
if(!lib)
return false;
try
{
//
if(!lib->DelClass(new_class_name))
return false;
}
catch(EObjectStorageNotEmpty &ex)
{
if(Logger)
Logger->LogMessage(RDK_EX_ERROR, __FUNCTION__, ex.what());
return false;
}
catch(EClassIdNotExist &ex)
{
if(Logger)
Logger->LogMessage(RDK_EX_ERROR, __FUNCTION__, ex.what());
return false;
}
//
// AddNewClass Logger
if(!library->AddNewClass(new_class_name, new_comp_name, newclass))
return false;
}
else
{
return false;
}
}
else
{ // AddNewClass Logger
if(!library->AddNewClass(new_class_name, new_comp_name, newclass))
return false;
}
return true;
}
/// RT
bool UStorage::DelClassFromCollection(const std::string &class_name, const std::string &lib_name)
{
URuntimeLibrary *library = 0;
for(size_t i=0;i<CollectionList.size();i++)
{
UEPtr<ULibrary> lib = CollectionList[i];
if(lib && lib->GetName() == lib_name)
{
library = static_cast<URuntimeLibrary*>(lib.Get());
}
}
// runtime
if(!library || (library->GetType()!=2))
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library \"" +library->GetName() +"\" doesn't exist or it isn't runtime library");
return false;
}
//
try
{
if(!library->DelClass(class_name))
return false;
}
catch(EObjectStorageNotEmpty &ex)
{
if(Logger)
Logger->LogMessageEx(RDK_EX_ERROR, __FUNCTION__, ex.what());
return false;
}
catch(EClassIdNotExist &ex)
{
if(Logger)
Logger->LogMessageEx(RDK_EX_ERROR, __FUNCTION__, ex.what());
return false;
}
return true;
}
///
bool UStorage::CreateRuntimeCollection(const std::string &lib_name)
{
URuntimeLibrary* lib=new URuntimeLibrary(lib_name,"");
return AddCollection(lib);
if(lib_name.empty())
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Empty lib name");
return false;
}
if(GetCollection(lib_name) != 0)
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library with name \"" + lib_name + "\" already exists");
return false;
}
//