]> git.sesse.net Git - casparcg/blob - shell/generate_docs.cpp
[CG] Created producer that wraps a CG producer in a way that it can be treated as...
[casparcg] / shell / generate_docs.cpp
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Helge Norberg, helge.norberg@svt.se
20 */
21
22 #include "included_modules.h"
23
24 #include <common/env.h>
25 #include <common/log.h>
26
27 #include <core/producer/media_info/in_memory_media_info_repository.h>
28 #include <core/help/help_repository.h>
29 #include <core/help/help_sink.h>
30 #include <core/help/util.h>
31 #include <core/consumer/syncto/syncto_consumer.h>
32 #include <core/producer/text/text_producer.h>
33 #include <core/producer/scene/xml_scene_producer.h>
34 #include <core/producer/cg_proxy.h>
35
36 #include <protocol/amcp/amcp_command_repository.h>
37 #include <protocol/amcp/AMCPCommandsImpl.h>
38
39 #include <boost/filesystem/fstream.hpp>
40
41 #include <iostream>
42 #include <sstream>
43
44 using namespace caspar;
45
46 static const int WIDTH = 150;
47
48 class mediawiki_paragraph_builder : public core::paragraph_builder
49 {
50         std::wostringstream     out_;
51         std::wostream&          commit_to_;
52 public:
53         mediawiki_paragraph_builder(std::wostream& out)
54                 : commit_to_(out)
55         {
56         }
57
58         ~mediawiki_paragraph_builder()
59         {
60                 commit_to_ << core::wordwrap(out_.str(), WIDTH) << std::endl;
61         }
62
63         spl::shared_ptr<paragraph_builder> text(std::wstring text) override
64         {
65                 out_ << std::move(text);
66                 return shared_from_this();
67         };
68
69         spl::shared_ptr<paragraph_builder> code(std::wstring text) override
70         {
71                 out_ << L"<code>" << std::move(text) << L"</code>";
72                 return shared_from_this();
73         };
74
75         spl::shared_ptr<paragraph_builder> strong(std::wstring text) override
76         {
77                 out_ << L"'''" << std::move(text) << L"'''";
78                 return shared_from_this();
79         };
80
81         spl::shared_ptr<paragraph_builder> see(std::wstring item) override
82         {
83                 out_ << L"[[#" << item << L"|" << item << L"]]";
84                 return shared_from_this();
85         };
86
87         spl::shared_ptr<paragraph_builder> url(std::wstring url, std::wstring name) override
88         {
89                 out_ << L"[" << std::move(url) << L" " << std::move(name) << L"]";
90                 return shared_from_this();
91         };
92 };
93
94 class mediawiki_definition_list_builder : public core::definition_list_builder
95 {
96         std::wostream& out_;
97 public:
98         mediawiki_definition_list_builder(std::wostream& out)
99                 : out_(out)
100         {
101         }
102
103         ~mediawiki_definition_list_builder()
104         {
105                 out_ << std::endl;
106         }
107
108         spl::shared_ptr<definition_list_builder> item(std::wstring term, std::wstring description) override
109         {
110                 out_ << L"; <code>" << term << L"</code>\n";
111                 out_ << L": " << description << L"\n";
112
113                 return shared_from_this();
114         };
115 };
116
117 class mediawiki_help_sink : public core::help_sink
118 {
119         std::wostream& out_;
120 public:
121         mediawiki_help_sink(std::wostream& out)
122                 : out_(out)
123         {
124         }
125
126         void start_section(std::wstring title)
127         {
128                 out_ << L"=" << title << L"=\n" << std::endl;
129         }
130
131         void syntax(const std::wstring& syntax) override
132         {
133                 out_ << L"Syntax:\n";
134                 out_ << core::indent(core::wordwrap(syntax, WIDTH - 1), L" ") << std::endl;
135         }
136
137         spl::shared_ptr<core::paragraph_builder> para() override
138         {
139                 return spl::make_shared<mediawiki_paragraph_builder>(out_);
140         }
141
142         spl::shared_ptr<core::definition_list_builder> definitions() override
143         {
144                 return spl::make_shared<mediawiki_definition_list_builder>(out_);
145         }
146
147         void example(const std::wstring& code, const std::wstring& caption) override
148         {
149                 out_ << core::indent(core::wordwrap(code, WIDTH - 1), L" ");
150
151                 if (!caption.empty())
152                         out_ << core::wordwrap(L"..." + caption, WIDTH - 1);
153
154                 out_ << std::endl;
155         }
156 private:
157         void begin_item(const std::wstring& name) override
158         {
159                 out_ << L"==" << name << L"==\n" << std::endl;
160         }
161 };
162
163 void generate_amcp_commands_help(const core::help_repository& help_repo)
164 {
165         boost::filesystem::wofstream file(L"amcp_commands_help.wiki");
166         mediawiki_help_sink sink(file);
167
168         auto print_section = [&](std::wstring title)
169         {
170                 sink.start_section(title);
171                 help_repo.help({ L"AMCP", title }, sink);
172         };
173
174         print_section(L"Basic Commands");
175         print_section(L"Data Commands");
176         print_section(L"Template Commands");
177         print_section(L"Mixer Commands");
178         print_section(L"Thumbnail Commands");
179         print_section(L"Query Commands");
180         file.flush();
181 }
182
183 void generate_producers_help(const core::help_repository& help_repo)
184 {
185         boost::filesystem::wofstream file(L"producers_help.wiki");
186         mediawiki_help_sink sink(file);
187
188         sink.start_section(L"Producers (Input Modules)");
189         help_repo.help({ L"producer" }, sink);
190
191         file.flush();
192 }
193
194 void generate_consumers_help(const core::help_repository& help_repo)
195 {
196         boost::filesystem::wofstream file(L"consumers_help.wiki");
197         mediawiki_help_sink sink(file);
198
199         sink.start_section(L"Consumers (Output Modules)");
200         help_repo.help({ L"consumer" }, sink);
201
202         file.flush();
203 }
204
205 int main(int argc, char** argv)
206 {
207         if (intercept_command_line_args(argc, argv))
208         {
209                 return 0;
210         }
211
212         env::configure(L"casparcg.config");
213         spl::shared_ptr<core::system_info_provider_repository> system_info_provider_repo;
214         spl::shared_ptr<core::cg_producer_registry> cg_registry;
215         auto media_info_repo = core::create_in_memory_media_info_repository();
216         spl::shared_ptr<core::help_repository> help_repo;
217         auto producer_registry = spl::make_shared<core::frame_producer_registry>(help_repo);
218         auto consumer_registry = spl::make_shared<core::frame_consumer_registry>(help_repo);
219         std::promise<bool> shutdown_server_now;
220         protocol::amcp::amcp_command_repository repo(
221                         { },
222                         nullptr,
223                         media_info_repo,
224                         system_info_provider_repo,
225                         cg_registry,
226                         help_repo,
227                         producer_registry,
228                         consumer_registry,
229                         nullptr,
230                         shutdown_server_now);
231
232         protocol::amcp::register_commands(repo);
233
234         core::module_dependencies dependencies(system_info_provider_repo, cg_registry, media_info_repo, producer_registry, consumer_registry);
235         initialize_modules(dependencies);
236         core::init_cg_proxy_as_producer(dependencies);
237         core::scene::init(dependencies);
238         core::syncto::init(dependencies);
239
240         generate_amcp_commands_help(*help_repo);
241         generate_producers_help(*help_repo);
242         generate_consumers_help(*help_repo);
243
244         uninitialize_modules();
245
246         return 0;
247 }