]> git.sesse.net Git - casparcg/blob - shell/generate_docs.cpp
* Refactored so that frame_consumers are stored in a frame_consumer_registry instance...
[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
32 #include <protocol/amcp/amcp_command_repository.h>
33 #include <protocol/amcp/AMCPCommandsImpl.h>
34
35 #include <boost/filesystem/fstream.hpp>
36
37 #include <iostream>
38 #include <sstream>
39
40 using namespace caspar;
41
42 static const int WIDTH = 150;
43
44 class mediawiki_paragraph_builder : public core::paragraph_builder
45 {
46         std::wostringstream     out_;
47         std::wostream&          commit_to_;
48 public:
49         mediawiki_paragraph_builder(std::wostream& out)
50                 : commit_to_(out)
51         {
52         }
53
54         ~mediawiki_paragraph_builder()
55         {
56                 commit_to_ << core::wordwrap(out_.str(), WIDTH) << std::endl;
57         }
58
59         spl::shared_ptr<paragraph_builder> text(std::wstring text) override
60         {
61                 out_ << std::move(text);
62                 return shared_from_this();
63         };
64
65         spl::shared_ptr<paragraph_builder> code(std::wstring text) override
66         {
67                 out_ << L"<code>" << std::move(text) << L"</code>";
68                 return shared_from_this();
69         };
70
71         spl::shared_ptr<paragraph_builder> see(std::wstring item) override
72         {
73                 out_ << L"[[#" << item << L"|" << item << L"]]";
74                 return shared_from_this();
75         };
76
77         spl::shared_ptr<paragraph_builder> url(std::wstring url, std::wstring name) override
78         {
79                 out_ << L"[" << std::move(url) << L" " << std::move(name) << L"]";
80                 return shared_from_this();
81         };
82 };
83
84 class mediawiki_definition_list_builder : public core::definition_list_builder
85 {
86         std::wostream& out_;
87 public:
88         mediawiki_definition_list_builder(std::wostream& out)
89                 : out_(out)
90         {
91         }
92
93         ~mediawiki_definition_list_builder()
94         {
95                 out_ << L"\n" << std::endl;
96         }
97
98         spl::shared_ptr<definition_list_builder> item(std::wstring term, std::wstring description) override
99         {
100                 out_ << L"; <code>" << term << L"</code>\n";
101                 out_ << L": " << description << L"\n";
102
103                 return shared_from_this();
104         };
105 };
106
107 class mediawiki_help_sink : public core::help_sink
108 {
109         std::wostream& out_;
110 public:
111         mediawiki_help_sink(std::wostream& out)
112                 : out_(out)
113         {
114         }
115
116         void start_section(std::wstring title)
117         {
118                 out_ << L"=" << title << L"=\n" << std::endl;
119         }
120
121         void syntax(const std::wstring& syntax) override
122         {
123                 out_ << L"Syntax:\n";
124                 out_ << core::indent(core::wordwrap(syntax, WIDTH - 1), L" ") << std::endl;
125         }
126
127         spl::shared_ptr<core::paragraph_builder> para() override
128         {
129                 return spl::make_shared<mediawiki_paragraph_builder>(out_);
130         }
131
132         spl::shared_ptr<core::definition_list_builder> definitions() override
133         {
134                 return spl::make_shared<mediawiki_definition_list_builder>(out_);
135         }
136
137         void example(const std::wstring& code, const std::wstring& caption) override
138         {
139                 out_ << core::indent(core::wordwrap(code, WIDTH - 1), L" ");
140
141                 if (!caption.empty())
142                         out_ << core::wordwrap(L"..." + caption, WIDTH - 1);
143
144                 out_ << std::endl;
145         }
146 private:
147         void begin_item(const std::wstring& name) override 
148         {
149                 out_ << L"==" << name << L"==\n" << std::endl;
150         }
151 };
152
153 void generate_amcp_commands_help(const core::help_repository& help_repo)
154 {
155         boost::filesystem::wofstream file(L"amcp_commands_help.wiki");
156         mediawiki_help_sink sink(file);
157
158         auto print_section = [&](std::wstring title)
159         {
160                 sink.start_section(title);
161                 help_repo.help({ L"AMCP", title }, sink);
162         };
163
164         print_section(L"Basic Commands");
165         print_section(L"Data Commands");
166         print_section(L"Template Commands");
167         print_section(L"Mixer Commands");
168         print_section(L"Thumbnail Commands");
169         print_section(L"Query Commands");
170         file.flush();
171 }
172
173 int main(int argc, char** argv)
174 {
175         //env::configure(L"casparcg.config");
176         //log::set_log_level(L"info");
177
178         spl::shared_ptr<core::system_info_provider_repository> system_info_provider_repo;
179         spl::shared_ptr<core::cg_producer_registry> cg_registry;
180         auto media_info_repo = core::create_in_memory_media_info_repository();
181         spl::shared_ptr<core::help_repository> help_repo;
182         spl::shared_ptr<core::frame_producer_registry> producer_registry;
183         spl::shared_ptr<core::frame_consumer_registry> consumer_registry;
184         std::promise<bool> shutdown_server_now;
185         protocol::amcp::amcp_command_repository repo(
186                         { },
187                         nullptr,
188                         media_info_repo,
189                         system_info_provider_repo,
190                         cg_registry,
191                         help_repo,
192                         producer_registry,
193                         consumer_registry,
194                         shutdown_server_now);
195
196         protocol::amcp::register_commands(repo);
197
198         core::module_dependencies dependencies(system_info_provider_repo, cg_registry, media_info_repo, producer_registry, consumer_registry);
199         initialize_modules(dependencies);
200
201         generate_amcp_commands_help(*help_repo);
202
203         uninitialize_modules();
204         
205         return 0;
206 }