Read about our upcoming Code of Conduct on this issue

Commit c7e89e77 authored by vlad_burin's avatar vlad_burin
Browse files

UBasePropCreator splitted, so extern libraries can use CreatorProperty template class.

Storage, Library updated to handle errors and logging.
GUI little update due to changes in Core

--HG--
branch : MockCompsTest
parent 9e28099c52f7
......@@ -153,6 +153,7 @@ SOURCES += \
HEADERS +=\
../../../Core/Engine/UBasePropCreator.h \
../../../Core/Engine/UCreatorPropTemplate.h \
rdk.qt_global.h \
../../../Deploy/Include/rdk.qt.h \
../../../Core/Engine/Engine.h \
......
......@@ -314,6 +314,10 @@ bool UApplication::IsInit(void) const
///
void UApplication::SetStorageBuildMode(int mode)
{
//
if(StorageBuildMode == mode)
return;
StorageBuildMode = mode;
CloseProject();
RDK::GetCoreLock()->SetStorageBuildMode(StorageBuildMode);
......@@ -324,8 +328,6 @@ void UApplication::SetStorageBuildMode(int mode)
{
MCore_ChannelInit(i,0,(void*)ExceptionHandler);
}
}
///
......@@ -337,8 +339,10 @@ int UApplication::GetStorageBuildMode()
/// -
void UApplication::CreateSaveMockLibs()
{
RDK::GetStorageLock()->CreateMockLibs();
RDK::GetStorageLock()->SaveMockLibs();
RDK::UELockPtr<RDK::UStorage> storage = RDK::GetStorageLock();
if(!storage->CreateMockLibs())
return;
storage->SaveMockLibs();
}
// --------------------------
//
......
......@@ -4,16 +4,6 @@
std::vector<std::string> ForbiddenInputs = {"DataInput0", "DataInput1", "DataInput2","DataInput3" , "DataInput4", "DataInput5"};
std::vector<std::string> ForbiddenOutputs = {"DataOutput0", "DataOutput1", "DataOutput2", "DataOutput3", "DataOutput4", "DataOutput5"};
class ParseException: public std::exception {
private:
std::string message_;
public:
explicit ParseException(const std::string& message){message_=message;}
const char* what() const noexcept override {
return message_.c_str();
}
};
using namespace RDK;
UBasePropCreator::UBasePropCreator()
......
#ifndef UBASEPROPCREATOR_H
#define UBASEPROPCREATOR_H
#include "UStorage.h"
#include "UMockUNet.h"
#include "../../Deploy/Include/rdk.h"
#include "UCreatorPropTemplate.h"
extern std::vector<std::string> ForbiddenInputs;
extern std::vector<std::string> ForbiddenOutputs;
//
//
class UBasePropCreator
{
public:
......@@ -24,24 +22,9 @@ public:
template <template<typename, typename, unsigned int> class PropType, unsigned int TypeInt>
static bool CreateSimpleTypeProperty(RDK::USerStorageXML* serstorage, RDK::UMockUNet* mock_unet);
//
//
template <template<typename, typename, unsigned int> class PropType, unsigned int TypeInt>
static bool CreatePropertyByType(RDK::USerStorageXML* serstorage, RDK::UMockUNet* mock_unet);
};
// CreatePropertyByType. CreateProperty
//
// (std::vector<typename>), UnKnow -
template <template<typename, typename, unsigned int> class PropType, unsigned int TypeInt, typename T>
class CreatorProperty
{
public:
static bool CreatePropertyByType(RDK::USerStorageXML* serstorage, RDK::UMockUNet* mock_unet);
};
// ,
class UnKnow
{
......
#ifndef UCREATORPROPTEMPLATE_H
#define UCREATORPROPTEMPLATE_H
#include "../../Deploy/Include/rdk.h"
// CreatePropertyByType.
// , -
template <template<typename, typename, unsigned int> class PropType, unsigned int TypeInt, typename T>
class CreatorProperty
{
public:
static bool CreatePropertyByType(RDK::USerStorageXML* serstorage, RDK::UMockUNet* mock_unet);
};
#endif // UCREATORPROPTEMPLATE_H
......@@ -7398,8 +7398,10 @@ int UEngine::LoadPredefinedCrPropFunctions(void)
{
if(!Storage)
return 0;
// -
// -
Storage->AddCrPropMockFunc(UBasePropCreator::BaseCrPropMock);
RdkLoadPredefinedCrPropFunctions(Storage);
return 0;
}
......
......@@ -389,7 +389,7 @@ void ULibrary::RemoveClassFromCompletedList(const string &name)
}
/// - XML
bool ULibrary::FillMockLibrary(UMockLibrary* lib)
void ULibrary::FillMockLibrary(UMockLibrary* lib)
{
USerStorageXML ComponentStruct;
ComponentStruct.Create("stub");
......@@ -397,19 +397,38 @@ bool ULibrary::FillMockLibrary(UMockLibrary* lib)
//
for(vector<string>::iterator it = Complete.begin(); it != Complete.end(); ++it)
{
UEPtr<UNet> cont=dynamic_pointer_cast<UNet>(Storage->TakeObject(*it));
UEPtr<UComponent> obj;
try{
obj = Storage->TakeObject(*it);
}
catch(UException &ex)
{
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, ex.what());
continue;
}
UEPtr<UNet> cont=dynamic_pointer_cast<UNet>(obj);
if(!cont)
return false;
continue;
ComponentStruct.Destroy();
if(!ComponentStruct.Destroy())
{
Storage->ReturnObject(cont);
continue;
}
// XML
if(!cont->SaveComponent(&ComponentStruct, true, ptAny|pgPublic))
return false;
{
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Error while saving XML description of class " + *it);
Storage->ReturnObject(cont);
continue;
}
lib->AddNewCompDescription(ComponentStruct);
Storage->ReturnObject(cont);
}
......@@ -634,7 +653,8 @@ UMockLibrary::~UMockLibrary(void)
bool UMockLibrary::AddNewCompDescription(USerStorageXML& descript)
{
std::string added;
descript.Save(added);
if(!descript.Save(added))
return false;
ClassesStructures.push_back(added);
return true;
}
......@@ -677,24 +697,27 @@ bool UMockLibrary::SaveLibraryToFile()
return true;
}
bool UMockLibrary::LoadFromXML(USerStorageXML& xml)
void UMockLibrary::LoadFromXML(USerStorageXML& xml)
{
xml.SelectRoot();
//
for(int i = 0, size = xml.GetNumNodes() ; i < size; i++)
{
xml.SelectNode(i);
if(!xml.SelectNode(i))
continue;
std::string add;
xml.SaveFromNode(add);
ClassesStructures.push_back(add);
if(!xml.SaveFromNode(add))
continue;
ClassesStructures.push_back(add);
xml.SelectUp();
}
}
/// xml
UEPtr<UContainer> UMockLibrary::CreateClassSample(USerStorageXML &xml, UStorage *storage)
{
......@@ -710,17 +733,6 @@ UEPtr<UContainer> UMockLibrary::CreateClassSample(USerStorageXML &xml, UStorage
return 0;
}
/*
if(!cont->LoadComponent(&xml,true))
{
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Error while LoadComponent() from XML file for class \"" +class_name +"\"");
delete mock;
return 0;
}
*/
return cont;
}
......@@ -741,12 +753,9 @@ void UMockLibrary::CreateClassSamples(UStorage *storage)
if(!cont)
return;
CurrentComponentStruct.Load(ClassesStructures[i],"");
std::string class_name=CurrentComponentStruct.GetNodeAttribute("Class");
if(class_name == "UOpenCvDetector")
{
int g= 9;
g++;
}
UploadClass(class_name,cont);
}
catch(UException &ex)
......
......@@ -195,7 +195,7 @@ virtual void CreateClassSamples(UStorage *storage)=0;
//
// --------------------------
/// - XML
bool FillMockLibrary(UMockLibrary* lib);
void FillMockLibrary(UMockLibrary* lib);
// --------------------------
};
......@@ -285,7 +285,7 @@ bool AddNewCompDescription(USerStorageXML& descript);
bool SaveLibraryToFile();
// xml ClassesStructures
bool LoadFromXML(USerStorageXML& xml);
void LoadFromXML(USerStorageXML& xml);
// --------------------------
/// xml
UEPtr<UContainer> CreateClassSample(USerStorageXML &xml, UStorage *storage);
......
......@@ -14,80 +14,68 @@ UMockUNet::UMockUNet(RDK::USerStorageXML *serstorage, UStorage* storage)
{
std::string comp_name = serstorage->GetNodeName();
serstorage->SelectNode(comp_name);
//
this->SetName(comp_name);
std::string class_name = serstorage->GetNodeAttribute("Class");
//
SetStorage(storage);
//
if(!GetStorage())
return;
std::list<funcCrPropMock> funcs = GetStorage()->GetFunctionsCrPropMock();
int size = funcs.size();
size++;
for (std::list<funcCrPropMock>::iterator f = funcs.begin();
f != funcs.end(); ++f)
for (std::list<funcCrPropMock>::iterator f = funcs.begin(); f != funcs.end(); ++f)
{
//
(*f)(serstorage, this);
}
// TODO , -
// UploadClass ( ?)
//
std::map<NameT,UVariable> propers = this->GetPropertiesList();
//
std::map<NameT,UVariable> CreatedProps = this->GetPropertiesList();
// xml-
std::vector<std::pair<std::string,std::string> > PropsNames;
// : Paramenters -> State -> Input -> Output
//
for(int i =0, params = serstorage->GetNumNodes(); i <params; i++)
{
serstorage->SelectNode(i);
std::string prop_type = serstorage->GetNodeName();
for(int j = 0, props = serstorage->GetNumNodes(); j < props; j++)
{
serstorage->SelectNode(j);
std::string prop_name = serstorage->GetNodeName();
std::string type = serstorage->GetNodeAttribute("Type");
PropsNames.push_back(make_pair(prop_name,type));
PropsNames.push_back(make_pair(prop_name, type));
serstorage->SelectUp();
}
serstorage->SelectUp();
}
std::vector<std::string> errors;
errors.clear();
//
//
for(std::vector<std::pair<std::string,std::string> >::iterator p = PropsNames.begin(); p != PropsNames.end(); ++p)
{
if(propers.find((*p).first) == propers.end())
if(CreatedProps.find((*p).first) == CreatedProps.end())
{
std::string temp;
if(std::find(ForbiddenInputs.begin(),ForbiddenInputs.end(),(*p).first) != ForbiddenInputs.end())
continue;
if(std::find(ForbiddenOutputs.begin(),ForbiddenOutputs.end(),(*p).first) != ForbiddenOutputs.end())
continue;
temp = (*p).first + " in " + class_name +" Type: " + (*p).second;
errors.push_back(temp);
if(GetStorage()->GetLogger())
{
GetStorage()->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__,
"In class "+ class_name + ": failed to create property: " + (*p).first + "with type" + (*p).second);
}
}
}
SetStorage(0);
// XML
ClassDesriptionXML.Destroy();
std::string temp;
serstorage->Save(temp);
ClassDesriptionXML.Load(temp,"");
//this->SaveComponent(&ClassDesriptionXML, false, ptAny|pgPublic);
}
UMockUNet* UMockUNet::New(void)
......
......@@ -34,7 +34,7 @@ virtual ~UMockUNet(void);
virtual UMockUNet* New(void);
private:
// ( )
USerStorageXML ClassDesriptionXML;
};
......
......@@ -972,33 +972,15 @@ void UStorage::ClearAllLibsClassesNameArrays(void)
}
}
// runtime-,
// ,
// 'buffer'
void UStorage::GetRTlibsNameList(std::string &buffer) const
void UStorage::GetLibsNameListByType(std::string &buffer, int type) 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);
}
// mock-,
// 'buffer'
void UStorage::GetMocklibsNameList(std::string &buffer) const
{
buffer.clear();
for(size_t i=0;i<CollectionList.size();i++)
{
UEPtr<ULibrary> lib = CollectionList[i];
if(lib && lib->GetType() == 3)
if(lib && lib->GetType() == type)
{
buffer.append(lib->GetName());
buffer.append(",");
......@@ -1347,30 +1329,41 @@ bool UStorage::DelCollection(int index)
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");
if(!LibList.LoadFromFile(lib_list_file,"LibraryList"))
{
if(Logger)
Logger->LogMessage(RDK_EX_ERROR, std::string("Error while loading Library List from file: " + lib_list_file));
return false;
}
USerStorageXML CompDesctips;
//
for(int i = 0, size = LibList.GetNumNodes() ; i < size; i++)
{
LibList.SelectNode(i);
if(!LibList.SelectNode(i))
continue;
std::string lib_name = LibList.GetNodeText();
// -
if(GetCollection(lib_name) != 0)
if(lib_name.empty() || GetCollection(lib_name) != 0)
continue;
UMockLibrary* lib_mock=new UMockLibrary(lib_name, "", lib_path);
//
CompDesctips.LoadFromFile(lib_path+"/"+lib_name+".xml","MockLib");
if(!CompDesctips.LoadFromFile(lib_path+"/"+lib_name+".xml","MockLib"))
{
if(Logger)
Logger->LogMessage(RDK_EX_ERROR, std::string("Error while loading Library Classes Descriptions from file: " + lib_path+"/"+lib_name+".xml"));
delete lib_mock;
continue;
}
lib_mock->LoadFromXML(CompDesctips);
......@@ -1387,18 +1380,24 @@ bool UStorage::InitMockLibs(void)
bool UStorage::CreateMockLibs(void)
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, std::string("Creating Mock Libraries from Static Libraries"));
// -
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()))
{
if(Logger)
Logger->LogMessage(RDK_EX_ERROR, std::string("Error while creating MockLibs path :" + lib_path));
return false;
}
// -
std::string lib_name = lib->GetName()+"_Mock";
......@@ -1424,7 +1423,8 @@ bool UStorage::CreateMockLibs(void)
bool UStorage::SaveMockLibs(void)
{
GetLogger()->LogMessage(RDK_EX_DEBUG, "Starting saving libraries to MockLibs directory");
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, std::string("Starting saving Mock Libraries to files"));
// - ( CollectionList)
USerStorageXML LibList;
......@@ -1439,7 +1439,7 @@ bool UStorage::SaveMockLibs(void)
if(lib && lib->GetType()==3)
{
//
//
UMockLibrary *library = 0;
library = dynamic_cast<UMockLibrary*>(lib.Get());
......@@ -1454,7 +1454,7 @@ bool UStorage::SaveMockLibs(void)
}
}
std::string file_name = "/home/user/Rtv-VideoAnalytics/Bin/MockLibs/0_LibList.xml";
std::string file_name = "../../../MockLibs/0_LibList.xml";
LibList.SaveToFile(file_name);
}
......@@ -1481,6 +1481,18 @@ bool UStorage::DelAllCollections(void)
return true;
}
//
void UStorage::SetBuildMode(int mode)
{
BuildMode = mode;
}
//
int UStorage::GetBuildMode()
{
return BuildMode;
}
//
//
bool UStorage::BuildStorage(void)
......@@ -1490,27 +1502,43 @@ bool UStorage::BuildStorage(void)
{
case 1:
{
BuildStorage(0);
BuildStorage(2);
BuildStorage(0); //
BuildStorage(2); // runtime-
break;
}
case 2:
{
BuildStorage(0); //
// -
InitMockLibs();
BuildStorage(0);
BuildStorage(3);
BuildStorage(2);
if(InitMockLibs())
{
BuildStorage(3); // mock-
}
else
{
if(Logger)
Logger->LogMessage(RDK_EX_ERROR, std::string("Mock Libraries will not be built because of error in Mock Libraries Initialization"));
}
BuildStorage(2); // runtime-
break;
}
case 3:
{
// -
InitMockLibs();
BuildStorage(3);
BuildStorage(2);
if(InitMockLibs())
{
BuildStorage(3); // mock-
}
else
{
if(Logger)
Logger->LogMessage(RDK_EX_ERROR, std::string("Mock Libraries will not be built because of error in Mock Libraries Initialization"));
}
BuildStorage(2); // runtime-
break;
}
}
......@@ -1735,28 +1763,27 @@ void UStorage::DelLookupClass(const NameT &name)
ClassesLookupTable.erase(I);
}
// --------------------------
//
void UStorage::SetBuildMode(int mode)
{
BuildMode = mode;
}
//
int UStorage::GetBuildMode()
{
return BuildMode;
}
// - UMockUnet-
// --------------------------
// - (UMockUnet)
// --------------------------
// - UMockUnet Storage
bool UStorage::AddCrPropMockFunc(funcCrPropMock func_ptr)
{
//
if(func_ptr == 0)
{