Commit ce9e77e8 authored by vlad_burin's avatar vlad_burin
Browse files

UMockUNet little code updates.

UMockLibrary created and functions for working with them in Storage added:
Storage now can create MockLibs from all StaticLibs, save all MockLibs, load
MockLibs from XML-files. (UploadClass need to be done).
BuildStorage(int) in Storage created:
Now you can choose which type of libraries to build.
In main BuildStorage BuildMode must be selected.

--HG--
branch : MockCompsTest
parent 58eb89dfebaa
......@@ -15,6 +15,7 @@ See file license.txt for more information
#include "ULibrary.h"
#include "UNet.h"
#include "UMockUNet.h"
#include "UComponentFactory.h"
namespace RDK {
......@@ -206,8 +207,8 @@ int ULibrary::Upload(UStorage *storage)
count=int(Complete.size());
// Storage RunTime
if(Type != 2)
Storage=0;
// if(Type != 2)
// Storage=0;
return count;
}
// --------------------------
......@@ -379,10 +380,37 @@ void ULibrary::RemoveClassFromCompletedList(const string &name)
if(I == Incomplete.end())
Incomplete.push_back(name);
}
// --------------------------
/// - XML
bool ULibrary::FillMockLibrary(UMockLibrary* lib)
{
USerStorageXML ComponentStruct;
ComponentStruct.Create("stub");
//
for(vector<string>::iterator it = Complete.begin(); it != Complete.end(); ++it)
{
UEPtr<UNet> cont=dynamic_pointer_cast<UNet>(Storage->TakeObject(*it));
if(!cont)
return false;
ComponentStruct.Destroy();
// XML
if(!cont->SaveComponent(&ComponentStruct, true, ptAny|pgPublic))
return false;
lib->AddNewCompDescription(ComponentStruct);
Storage->ReturnObject(cont);
}
Storage->FreeObjectsStorage();
return true;
}
// --------------------------
// --------------------------
//
......@@ -403,7 +431,6 @@ URuntimeLibrary::~URuntimeLibrary(void)
//
// --------------------------
///
const std::string& URuntimeLibrary::GetLibPath() const
{
......@@ -579,6 +606,96 @@ void URuntimeLibrary::CreateClassSamples(UStorage *storage)
// --------------------------
// -
// --------------------------
//
// --------------------------
UMockLibrary::UMockLibrary(const string &name, const string &version, const string& path)
: ULibrary(name,version,3), LibPath(path)
{
}
UMockLibrary::~UMockLibrary(void)
{
}
// ClassesStructures
bool UMockLibrary::AddNewCompDescription(USerStorageXML& descript)
{
std::string added;
descript.Save(added);
ClassesStructures.push_back(added);
return true;
}
bool UMockLibrary::SaveLibraryToFile()
{
// ,
if(RDK::CreateNewDirectory("../../../MockLibs/"))
return false;
std::string all_comps;
//
for(std::vector<std::string>::iterator it = ClassesStructures.begin(); it != ClassesStructures.end(); ++it)
{
all_comps += (*it)+"\n";
}
CurrentComponentStruct.Create("a");
CurrentComponentStruct.Destroy();
CurrentComponentStruct.Create("MockLib");
CurrentComponentStruct.SelectRoot();
CurrentComponentStruct.SetNodeAttribute("name", Name);
CurrentComponentStruct.SetNodeAttribute("version", Version);
CurrentComponentStruct.SetNodeAttribute("revision", std::to_string(Revision));
// XML
USerStorageXML CompStruct;
CompStruct.Load(all_comps,"");
// XML
CurrentComponentStruct.LoadToNode(CompStruct,true);
std::string file_name = LibPath + "/" + Name + ".xml";
CurrentComponentStruct.SaveToFile(file_name);
return true;
}
bool UMockLibrary::LoadFromXML(USerStorageXML& xml)
{
xml.SelectRoot();
//
for(int i = 0, size = xml.GetNumNodes() ; i < size; i++)
{
xml.SelectNode(i);
std::string add;
xml.SaveFromNode(add);
ClassesStructures.push_back(add);
xml.SelectUp();
}
}
/// xml
UEPtr<UContainer> UMockLibrary::CreateClassSample(UStorage *storage, USerStorageXML &xml)
{}
// ClassSamples .
// .
void UMockLibrary::CreateClassSamples(UStorage *storage)
{}
}
#endif
......
......@@ -23,6 +23,8 @@ See file license.txt for more information
namespace RDK {
class UMockLibrary;
class RDK_LIB_TYPE ULibrary//: public ULibrary
{
protected: //
......@@ -46,6 +48,7 @@ RDK::UEPtr<RDK::UVersion> CoreVersion;
/// 0 - ( )
/// 1 - ( dll)
/// 2 - ,
/// 3 - - ( -)
int Type;
///
......@@ -123,6 +126,7 @@ const UEPtr<RDK::UVersion> GetCoreVersion(void) const;
/// 0 - ( )
/// 1 - ( dll)
/// 2 - ,
/// 3 - - ( -)
int GetType(void) const;
///
......@@ -183,6 +187,13 @@ virtual void RemoveClassFromCompletedList(const string &name);
/// ClassSamples .
/// .
virtual void CreateClassSamples(UStorage *storage)=0;
// --------------------------
//
// --------------------------
/// - XML
bool FillMockLibrary(UMockLibrary* lib);
// --------------------------
};
......@@ -241,6 +252,49 @@ virtual void CreateClassSamples(UStorage *storage);
};
class RDK_LIB_TYPE UMockLibrary: public ULibrary
{
protected: //
protected: //
protected: //
///
std::string LibPath;
/// XML
USerStorageXML CurrentComponentStruct;
/// (xml)
vector<string> ClassesStructures;
public: //
// --------------------------
//
// --------------------------
UMockLibrary(const string &name, const string &version, const string& path);
virtual ~UMockLibrary(void);
// ClassesStructures
bool AddNewCompDescription(USerStorageXML& descript);
//
bool SaveLibraryToFile();
// xml ClassesStructures
bool LoadFromXML(USerStorageXML& xml);
// --------------------------
/// xml
UEPtr<UContainer> CreateClassSample(UStorage *storage, USerStorageXML &xml);
// ClassSamples .
// .
virtual void CreateClassSamples(UStorage *storage);
// --------------------------
};
/// T class_name
/// component_name
///
......
This diff is collapsed.
......@@ -43,7 +43,7 @@ bool CreatePropertyByType(RDK::USerStorageXML* serstorage, UMockUNet* mock_unet)
// CreatePropertyByType. CreateProperty
//
// (std::vector<typename>), int -
// (std::vector<typename>), UnKnow -
template <template<typename, typename, unsigned int> class PropType, unsigned int TypeInt, typename T>
class CreatorProperty
{
......@@ -51,10 +51,11 @@ public:
static bool CreatePropertyByType(RDK::USerStorageXML* serstorage, UMockUNet* mock_unet);
};
// ,
// ,
class UnKnow
{
private:
UnKnow() {};
};
}
......
......@@ -106,7 +106,8 @@ bool UInstancesStorageElement::operator != (const UInstancesStorageElement &valu
// --------------------------
//
// --------------------------
UStorage::UStorage(void)
UStorage::UStorage(void):
BuildMode(1)
{
LastClassId=0;
}
......@@ -1209,6 +1210,10 @@ void UStorage::InitRTlibs(void)
// RTlibs
std::string lib_path = "../../../RTlibs";
// ,
if(RDK::CreateNewDirectory("../../../RTlibs/"))
return;
// xml
// ClassesStructures
std::vector<std::string> lib_names;
......@@ -1313,6 +1318,117 @@ bool UStorage::DelCollection(int index)
return true;
}
bool UStorage::InitMockLibs(void)
{
// -
std::string lib_path = "../../../MockLibs/";
std::string lib_list_file = "../../../MockLibs/0_LibList.xml";
USerStorageXML LibList;
LibList.LoadFromFile(lib_list_file,"LibraryList");
USerStorageXML CompDesctips;
//
for(int i = 0, size = LibList.GetNumNodes() ; i < size; i++)
{
LibList.SelectNode(i);
std::string lib_name = LibList.GetNodeText();
// -
if(GetCollection(lib_name) != 0)
continue;
UMockLibrary* lib_mock=new UMockLibrary(lib_name, "", lib_path);
//
CompDesctips.LoadFromFile(lib_path+"/"+lib_name+".xml","MockLib");
lib_mock->LoadFromXML(CompDesctips);
if(!AddCollection(lib_mock))
{
delete lib_mock;
}
LibList.SelectUp();
}
return true;
}
bool UStorage::CreateMockLibs(void)
{
// -
for(size_t i=0;i<CollectionList.size();i++)
{
UEPtr<ULibrary> lib=CollectionList[i];
if(lib && lib->GetType()==0)
{
//
std::string lib_path = "../../../MockLibs/";
// ,
if(RDK::CreateNewDirectory(lib_path.c_str()))
return false;
// -
std::string lib_name = lib->GetName()+"_Mock";
// -
if(GetCollection(lib_name) != 0)
continue;
UMockLibrary* lib_mock=new UMockLibrary(lib_name, "", lib_path);
//
lib->FillMockLibrary(lib_mock);
if(!AddCollection(lib_mock))
{
delete lib_mock;
}
}
}
return true;
}
bool UStorage::SaveMockLibs(void)
{
GetLogger()->LogMessage(RDK_EX_DEBUG, "Starting saving libraries to MockLibs directory");
// - ( CollectionList)
USerStorageXML LibList;
LibList.Create("LibraryList");
std::string lib_name = "";
//
for(size_t i=0;i<CollectionList.size();i++)
{
UEPtr<ULibrary> lib=CollectionList[i];
if(lib && lib->GetType()==3)
{
//
UMockLibrary *library = 0;
library = dynamic_cast<UMockLibrary*>(lib.Get());
library->SaveLibraryToFile();
LibList.AddNode("library");
LibList.SetNodeText(lib->GetName());
LibList.SelectUp();
}
}
std::string file_name = "/home/user/Rtv-VideoAnalytics/Bin/MockLibs/0_LibList.xml";
LibList.SaveToFile(file_name);
}
//
// .
bool UStorage::DelCollection(const string &name)
......@@ -1340,50 +1456,86 @@ bool UStorage::DelAllCollections(void)
//
bool UStorage::BuildStorage(void)
{
for(size_t i=0;i<CollectionList.size();i++)
switch (BuildMode)
{
UEPtr<ULibrary> lib=CollectionList[i];
if(lib)
{
GetLogger()->LogMessage(RDK_EX_DEBUG, lib->GetName()+std::string(": collection version is ")+lib->GetVersion()+std::string(" (")+sntoa(lib->GetRevision())+")");
case 1:
{
BuildStorage(0);
BuildStorage(2);
break;
}
if(lib->GetCoreVersion())
{
if(!lib->GetCoreVersion()->IsEqualFull(GetGlobalVersion()))
{
Logger->LogMessage(RDK_EX_FATAL, lib->GetName()+std::string(" collection SKIPPED: application core version ")+GetGlobalVersion().ToStringFull()+std::string(" is incompatible lib core version ")+lib->GetCoreVersion()->ToStringFull());
continue;
}
}
else
Logger->LogMessage(RDK_EX_WARNING, lib->GetName()+std::string(" core version compatibility DOES NOT checked."));
Logger->LogMessage(RDK_EX_DEBUG, std::string("Adding components from ")+lib->GetName()+" collection...");
unsigned long long total_used_memory_before(0);
unsigned long long largest_free_block_before(0);
ReadUsedMemoryInfo(total_used_memory_before, largest_free_block_before);
CollectionList[i]->Upload(this);
unsigned long long total_used_memory_after(0);
unsigned long long largest_free_block_after(0);
if(ReadUsedMemoryInfo(total_used_memory_after, largest_free_block_after))
Logger->LogMessage(RDK_EX_DEBUG, lib->GetName()+std::string(" eats ")+sntoa(total_used_memory_after-total_used_memory_before)+std::string(" bytes of RAM. Largest RAM block decreased to ")+sntoa(largest_free_block_before-largest_free_block_after)+" bytes");
Logger->LogMessage(RDK_EX_DEBUG, std::string("Successfully added [")+sntoa(lib->GetComplete().size())+std::string("]: ")+concat_strings(lib->GetComplete(),std::string(",")));
if(!lib->GetIncomplete().empty())
Logger->LogMessage(RDK_EX_DEBUG, std::string("Failed to add [")+sntoa(lib->GetIncomplete().size())+std::string("]: ")+concat_strings(lib->GetIncomplete(),std::string(",")));
CompletedClassNames.insert(CompletedClassNames.end(),
lib->GetComplete().begin(),
lib->GetComplete().end());
IncompletedClassNames.insert(IncompletedClassNames.end(),
lib->GetIncomplete().begin(),
lib->GetIncomplete().end());
}
case 2:
{
BuildStorage(0);
BuildStorage(3);
BuildStorage(2);
break;
}
case 3:
{
BuildStorage(3);
BuildStorage(2);
break;
}
}
return true;
}
//
// :
// 0 - ( )
// 1 - ( dll)
// 2 - ,
// 3 - - ( -)
bool UStorage::BuildStorage(int lib_type)
{
for(size_t i=0;i<CollectionList.size();i++)
{
UEPtr<ULibrary> lib=CollectionList[i];
if(lib && lib->GetType()==lib_type)
{
GetLogger()->LogMessage(RDK_EX_DEBUG, lib->GetName()+std::string(": collection version is ")+lib->GetVersion()+std::string(" (")+sntoa(lib->GetRevision())+")");
if(lib->GetCoreVersion())
{
if(!lib->GetCoreVersion()->IsEqualFull(GetGlobalVersion()))
{
Logger->LogMessage(RDK_EX_FATAL, lib->GetName()+std::string(" collection SKIPPED: application core version ")+GetGlobalVersion().ToStringFull()+std::string(" is incompatible lib core version ")+lib->GetCoreVersion()->ToStringFull());
continue;
}
}
else
Logger->LogMessage(RDK_EX_WARNING, lib->GetName()+std::string(" core version compatibility DOES NOT checked."));
Logger->LogMessage(RDK_EX_DEBUG, std::string("Adding components from ")+lib->GetName()+" collection...");
unsigned long long total_used_memory_before(0);
unsigned long long largest_free_block_before(0);
ReadUsedMemoryInfo(total_used_memory_before, largest_free_block_before);
CollectionList[i]->Upload(this);
unsigned long long total_used_memory_after(0);
unsigned long long largest_free_block_after(0);
if(ReadUsedMemoryInfo(total_used_memory_after, largest_free_block_after))
Logger->LogMessage(RDK_EX_DEBUG, lib->GetName()+std::string(" eats ")+sntoa(total_used_memory_after-total_used_memory_before)+std::string(" bytes of RAM. Largest RAM block decreased to ")+sntoa(largest_free_block_before-largest_free_block_after)+" bytes");
Logger->LogMessage(RDK_EX_DEBUG, std::string("Successfully added [")+sntoa(lib->GetComplete().size())+std::string("]: ")+concat_strings(lib->GetComplete(),std::string(",")));
if(!lib->GetIncomplete().empty())
Logger->LogMessage(RDK_EX_DEBUG, std::string("Failed to add [")+sntoa(lib->GetIncomplete().size())+std::string("]: ")+concat_strings(lib->GetIncomplete(),std::string(",")));
CompletedClassNames.insert(CompletedClassNames.end(),
lib->GetComplete().begin(),
lib->GetComplete().end());
IncompletedClassNames.insert(IncompletedClassNames.end(),
lib->GetIncomplete().begin(),
lib->GetIncomplete().end());
}
}
return true;
}
/// ,
///
void UStorage::DelAbandonedClasses(void)
......
......@@ -128,6 +128,14 @@ UObjectsStorage ObjectsStorage;
// Id
UId LastClassId;
// :
// 1 - . , . ( )
// 2 - . , -, .
// , - .
// ( -, ) - .
// 3 - . -, . ( )
int BuildMode;
protected: //
......@@ -309,10 +317,10 @@ void GetRTlibsNameList(std::string &buffer) const;
// RT-
///
/// Engine . CollectionList
/// Engine . CollectionList ( )
void InitRTlibs(void);
/// runtime-
/// runtime- ( )
virtual bool LoadRuntimeCollection(const std::string &lib_name);
/// ( )
......@@ -339,6 +347,18 @@ virtual bool AddCollection(ULibrary *library, bool force_build=false);
// .
virtual bool DelCollection(int index);
// MockLibs CollectionList
// ( )
bool InitMockLibs(void);
// - ( )
//
bool CreateMockLibs(void);
// - Rtv-VideoAnalytics/Bin/MockLibs XML
//
bool SaveMockLibs(void);
//
// .
bool DelCollection(const string &name);
......@@ -350,6 +370,14 @@ virtual bool DelAllCollections(void);
//
virtual bool BuildStorage(void);
//
// :
// 0 - ( )
// 1 - ( dll)
// 2 - ,
// 3 - - ( -)
virtual bool BuildStorage(int lib_type);
/// ,
///
virtual void DelAbandonedClasses(void);
......
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