~dandrader/mir/cross-compile-parallel

« back to all changes in this revision

Viewing changes to examples/basic_server.cpp

  • Committer: Tarmac
  • Author(s): Alan Griffiths
  • Date: 2013-09-26 01:19:16 UTC
  • mfrom: (1081.4.22 mir3)
  • Revision ID: tarmac-20130926011916-jmm6x87uckd04y8s
frontend, config: Mechanism for connecting via a socket pair.

Approved by PS Jenkins bot, Kevin DuBois, Alexandros Frantzis.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17
17
 */
18
18
 
 
19
#include "server_configuration.h"
 
20
 
 
21
#include "mir/abnormal_exit.h"
 
22
#include "mir/frontend/connector.h"
 
23
#include "mir/options/option.h"
 
24
#include "mir/report_exception.h"
19
25
#include "mir/run_mir.h"
20
 
#include "mir/report_exception.h"
21
 
#include "server_configuration.h"
22
26
 
23
27
#include <iostream>
24
28
 
 
29
namespace
 
30
{
 
31
char const* const launch_child_opt = "launch-client";
 
32
 
 
33
struct ServerConfiguration : mir::examples::ServerConfiguration
 
34
{
 
35
    ServerConfiguration(int argc, char const** argv) :
 
36
        mir::examples::ServerConfiguration(argc, argv)
 
37
    {
 
38
        namespace po = boost::program_options;
 
39
 
 
40
        add_options()
 
41
            (launch_child_opt, po::value<std::string>(), "system() command to launch client");
 
42
    }
 
43
 
 
44
    void launch_client()
 
45
    {
 
46
        if (the_options()->is_set(launch_child_opt))
 
47
        {
 
48
            char buffer[128] = {0};
 
49
            sprintf(buffer, "fd://%d", the_connector()->client_socket_fd());
 
50
            setenv("MIR_SOCKET", buffer, 1);
 
51
            auto ignore = system((the_options()->get(launch_child_opt, "") + "&").c_str());
 
52
            (void)ignore;
 
53
        }
 
54
    }
 
55
 
 
56
    using mir::examples::ServerConfiguration::the_options;
 
57
};
 
58
}
 
59
 
25
60
int main(int argc, char const* argv[])
26
61
try
27
62
{
28
 
    mir::examples::ServerConfiguration config(argc, argv);
 
63
    ServerConfiguration config(argc, argv);
29
64
 
30
 
    run_mir(config, [](mir::DisplayServer&) {/* empty init */});
 
65
    run_mir(config, [&](mir::DisplayServer&){ config.launch_client(); });
31
66
    return 0;
32
67
}
33
68
catch (...)