Saving and loading of Clone Sources.

This commit is contained in:
brunoherbelin
2020-05-23 15:27:56 +02:00
parent 84ca3b1f82
commit 2cc45edfbd
5 changed files with 39 additions and 8 deletions

View File

@@ -88,6 +88,32 @@ void SessionCreator::loadSession(XMLElement *sessionNode)
// TODO : create other types of source // TODO : create other types of source
} }
// create clones after all sources to potentially clone have been created
sourceNode = sessionNode->FirstChildElement("Source");
for( ; sourceNode ; sourceNode = sourceNode->NextSiblingElement())
{
xmlCurrent_ = sourceNode;
counter++;
const char *pType = xmlCurrent_->Attribute("type");
if (!pType)
continue;
if ( std::string(pType) == "CloneSource") {
XMLElement* originNode = xmlCurrent_->FirstChildElement("origin");
if (originNode) {
std::string sourcename = std::string ( originNode->GetText() );
SourceList::iterator origin = session_->find(sourcename);
if (origin != session_->end()) {
CloneSource *new_clone_source = (*origin)->clone();
new_clone_source->accept(*this);
session_->addSource(new_clone_source);
}
}
}
}
} }
else else
Log::Warning("Session seems empty."); Log::Warning("Session seems empty.");
@@ -244,11 +270,5 @@ void SessionCreator::visit (SessionSource& s)
} }
void SessionCreator::visit (RenderSource& s)
{
}

View File

@@ -47,7 +47,6 @@ public:
void visit (Source& s) override; void visit (Source& s) override;
void visit (MediaSource& s) override; void visit (MediaSource& s) override;
void visit (SessionSource& s) override; void visit (SessionSource& s) override;
void visit (RenderSource& s) override;
static void XMLToNode(tinyxml2::XMLElement *xml, Node &n); static void XMLToNode(tinyxml2::XMLElement *xml, Node &n);
}; };

View File

@@ -354,3 +354,13 @@ void SessionVisitor::visit (RenderSource& s)
{ {
xmlCurrent_->SetAttribute("type", "RenderSource"); xmlCurrent_->SetAttribute("type", "RenderSource");
} }
void SessionVisitor::visit (CloneSource& s)
{
xmlCurrent_->SetAttribute("type", "CloneSource");
XMLElement *origin = xmlDoc_->NewElement("origin");
xmlCurrent_->InsertEndChild(origin);
XMLText *text = xmlDoc_->NewText( s.origin()->name().c_str() );
origin->InsertEndChild( text );
}

View File

@@ -44,6 +44,7 @@ public:
void visit (MediaSource& s) override; void visit (MediaSource& s) override;
void visit (SessionSource& s) override; void visit (SessionSource& s) override;
void visit (RenderSource& s) override; void visit (RenderSource& s) override;
void visit (CloneSource& s) override;
static tinyxml2::XMLElement *NodeToXML(Node &n, tinyxml2::XMLDocument *doc); static tinyxml2::XMLElement *NodeToXML(Node &n, tinyxml2::XMLDocument *doc);
}; };

View File

@@ -138,7 +138,6 @@ class CloneSource : public Source
friend class Source; friend class Source;
public: public:
CloneSource(Source *origin);
~CloneSource(); ~CloneSource();
// implementation of source API // implementation of source API
@@ -151,6 +150,8 @@ public:
inline Source *origin() const { return origin_; } inline Source *origin() const { return origin_; }
protected: protected:
// only Source class can create new CloneSource via clone();
CloneSource(Source *origin);
void init() override; void init() override;
Surface *clonesurface_; Surface *clonesurface_;