annotate Applications/Wasm/StartupParametersBuilder.cpp @ 1310:9bea7e15b519 broker

- first pass at changes to cope with the refactoring of the loading system - global loader-related data accessible through ILoadersContext::ILock - many changes in legacy loaders (CT, RTSTRUCT, DOSE) + loader cache - NOT FINISHED! there are shared_from_this calls in ctors! this will crash!
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 09 Mar 2020 14:53:22 +0100
parents 86930bc676c6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
1 #include "StartupParametersBuilder.h"
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
2 #include <iostream>
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
3 #include <cstdio>
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
4 #include "emscripten/html5.h"
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
5
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
6 namespace OrthancStone
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
7 {
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
8 void StartupParametersBuilder::Clear()
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
9 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
10 startupParameters_.clear();
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
11 }
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
12
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
13 void StartupParametersBuilder::SetStartupParameter(
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
14 const char* name,
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
15 const char* value)
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
16 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
17 startupParameters_.push_back(std::make_tuple(name, value));
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
18 }
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
19
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
20 void StartupParametersBuilder::GetStartupParameters(
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
21 boost::program_options::variables_map& parameters,
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
22 const boost::program_options::options_description& options)
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
23 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
24 std::vector<std::string> argvStrings(startupParameters_.size() + 1);
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
25 // argv mirrors pointers to the internal argvStrings buffers.
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
26 // ******************************************************
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
27 // THIS IS HIGHLY DANGEROUS SO BEWARE!!!!!!!!!!!!!!
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
28 // ******************************************************
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
29 std::vector<const char*> argv(startupParameters_.size() + 1);
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
30
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
31 int argCounter = 0;
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
32 argvStrings[argCounter] = "dummy.exe";
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
33 argv[argCounter] = argvStrings[argCounter].c_str();
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
34
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
35 argCounter++;
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
36
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
37 std::string cmdLine = "";
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
38 for ( StartupParameters::const_iterator it = startupParameters_.begin();
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
39 it != startupParameters_.end();
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
40 it++)
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
41 {
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
42 std::stringstream argSs;
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
43
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
44 argSs << "--" << std::get<0>(*it);
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
45 if(std::get<1>(*it).length() > 0)
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
46 argSs << "=" << std::get<1>(*it);
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
47
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
48 argvStrings[argCounter] = argSs.str();
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
49 cmdLine = cmdLine + " " + argvStrings[argCounter];
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
50 std::cout << cmdLine << std::endl;
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
51 argv[argCounter] = argvStrings[argCounter].c_str();
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
52 argCounter++;
664
9631a10ed3af fix previous merge
Alain Mazy <alain@mazy.be>
parents: 658
diff changeset
53 }
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
54
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
55
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
56 std::cout << "simulated cmdLine = \"" << cmdLine.c_str() << "\"\n";
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
57
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
58 try
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
59 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
60 boost::program_options::store(
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
61 boost::program_options::command_line_parser(argCounter, argv.data()).
658
63982c8c294a merge am-dev -> default
Alain Mazy <alain@mazy.be>
parents: 603 657
diff changeset
62 options(options).allow_unregistered().run(), parameters);
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
63 boost::program_options::notify(parameters);
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
64 }
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
65 catch (boost::program_options::error& e)
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
66 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
67 std::cerr << "Error while parsing the command-line arguments: " <<
664
9631a10ed3af fix previous merge
Alain Mazy <alain@mazy.be>
parents: 658
diff changeset
68 e.what() << std::endl;
9631a10ed3af fix previous merge
Alain Mazy <alain@mazy.be>
parents: 658
diff changeset
69 }
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
70 }
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
71 }