blob: 6beef5a0dcf836723862e88ba0a6508832fd67e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include "ContentManager.hpp"
void ContentManager::SetStaticFilesystem(std::shared_ptr<Filesystem> & static_fs)
{
m_StaticFilesystem = static_fs;
}
void ContentManager::SetTemplateSystem(std::shared_ptr<TemplateManager> & tmgr)
{
m_TemplateManager = tmgr;
}
bool ContentManager::RegisterModule(std::shared_ptr<Content> ctnt)
{
std::string const & basePath = ctnt->GetUriBasePath();
Redirections const & rs = ctnt->GetRedirections();
m_ContentModules[basePath] = ctnt;
for (auto & redirect : rs)
{
m_ContentModules[redirect] = ctnt;
}
return false;
}
bool ContentManager::InitAll(void)
{
bool ret = true;
for (auto & content : m_ContentModules)
{
if (content.second->Init() == false)
{
ret = false;
}
}
return ret;
}
void ContentManager::ShutdownAll(void)
{
std::unordered_map<std::shared_ptr<Content>, bool> shutdownModules;
for (auto & content : m_ContentModules)
{
auto const & search = shutdownModules.find(content.second);
if (search != shutdownModules.end())
{
continue;
}
else
{
content.second->Shutdown();
shutdownModules[content.second] = true;
}
}
m_ContentModules.clear();
}
bool ContentManager::Render(char const * basePath, RequestResponse & rr, std::string & out)
{
if (m_ContentModules.find(basePath) == m_ContentModules.end())
{
return false;
}
RenderData rd;
auto & cntm = m_ContentModules[basePath];
auto & main = cntm->GetMainTemplate();
if (m_ContentModules[basePath]->Render(rr, rd) == false)
{
return false;
}
if (m_TemplateManager->RenderTemplate(main, rd, out) == false)
{
return false;
}
return true;
}
ContentModules const & ContentManager::GetAllModules() const
{
return m_ContentModules;
}
|