~alan-griffiths/miral/mru-window-visiblity

« back to all changes in this revision

Viewing changes to miral/internal_client.cpp

  • Committer: Alan Griffiths
  • Date: 2017-02-14 16:52:21 UTC
  • mfrom: (507.1.11 miral1)
  • Revision ID: alan@octopull.co.uk-20170214165221-shgvy4478ovf05k2
Introduce libmirclientcpp-dev as a package containing the C++ wrapper around parts of libmirclient-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <mutex>
29
29
#include <thread>
30
30
 
 
31
// both_versions.h assumes the old symbol is generated for Mir < 0.26, which isn't true here.
 
32
#ifndef __clang__
 
33
    #define MIRAL_BOTH_VERSIONS(old_sym, old_version, new_sym, new_version)\
 
34
        extern "C" __attribute__((alias(#new_sym))) void old_sym();\
 
35
        __asm__(".symver " #old_sym"," #old_sym "@" #old_version);\
 
36
        __asm__(".symver " #new_sym"," #new_sym "@@" #new_version);
 
37
#else
 
38
    #define MIRAL_BOTH_VERSIONS(old_sym, old_version, new_sym, new_version)\
 
39
        __asm__(".symver " #new_sym"," #old_sym "@" #old_version);\
 
40
        __asm__(".symver " #new_sym"," #new_sym "@@@" #new_version);
 
41
#endif
 
42
 
31
43
namespace
32
44
{
33
45
class InternalClientRunner
34
46
{
35
47
public:
36
48
    InternalClientRunner(std::string name,
37
 
         std::function<void(miral::toolkit::Connection connection)> client_code,
 
49
         std::function<void(mir::client::Connection connection)> client_code,
38
50
         std::function<void(std::weak_ptr<mir::scene::Session> const session)> connect_notification);
39
51
 
40
52
    void run(mir::Server& server);
47
59
    std::condition_variable mutable cv;
48
60
    mir::Fd fd;
49
61
    std::weak_ptr<mir::scene::Session> session;
50
 
    miral::toolkit::Connection connection;
51
 
    std::function<void(miral::toolkit::Connection connection)> const client_code;
 
62
    mir::client::Connection connection;
 
63
    std::function<void(mir::client::Connection connection)> const client_code;
52
64
    std::function<void(std::weak_ptr<mir::scene::Session> const session)> connect_notification;
53
65
};
54
66
}
62
74
 
63
75
InternalClientRunner::InternalClientRunner(
64
76
    std::string const name,
65
 
    std::function<void(miral::toolkit::Connection connection)> client_code,
 
77
    std::function<void(mir::client::Connection connection)> client_code,
66
78
    std::function<void(std::weak_ptr<mir::scene::Session> const session)> connect_notification) :
67
79
    name(name),
68
80
    client_code(std::move(client_code)),
83
95
    char connect_string[64] = {0};
84
96
    sprintf(connect_string, "fd://%d", fd.operator int());
85
97
 
86
 
    connection = miral::toolkit::Connection{mir_connect_sync(connect_string, name.c_str())};
 
98
    connection = mir::client::Connection{mir_connect_sync(connect_string, name.c_str())};
87
99
 
88
100
    std::unique_lock<decltype(mutex)> lock{mutex};
89
101
    cv.wait(lock, [&] { return !!session.lock(); });
103
115
    }
104
116
}
105
117
 
 
118
MIRAL_BOTH_VERSIONS(
 
119
    _ZN5miral21StartupInternalClientC1ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFvNS_7toolkit10ConnectionEEES7_IFvSt8weak_ptrIN3mir5scene7SessionEEEE, MIRAL_1.0,
 
120
    _ZN5miral21StartupInternalClientC1ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFvN3mir6client10ConnectionEEES7_IFvSt8weak_ptrINS8_5scene7SessionEEEE, MIRAL_1.2)
106
121
miral::StartupInternalClient::StartupInternalClient(
107
122
    std::string name,
108
 
    std::function<void(toolkit::Connection connection)> client_code,
 
123
    std::function<void(mir::client::Connection connection)> client_code,
109
124
    std::function<void(std::weak_ptr<mir::scene::Session> const session)> connect_notification) :
110
125
    internal_client(std::make_shared<Self>(std::move(name), std::move(client_code), std::move(connect_notification)))
111
126
{
135
150
    self->server = &server;
136
151
}
137
152
 
 
153
 
 
154
MIRAL_BOTH_VERSIONS(
 
155
    _ZNK5miral22InternalClientLauncher6launchERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt8functionIFvNS_7toolkit10ConnectionEEERKS9_IFvSt8weak_ptrIN3mir5scene7SessionEEEE, MIRAL_1.0,
 
156
    _ZNK5miral22InternalClientLauncher6launchERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt8functionIFvN3mir6client10ConnectionEEERKS9_IFvSt8weak_ptrINSA_5scene7SessionEEEE, MIRAL_1.2)
138
157
void miral::InternalClientLauncher::launch(
139
158
    std::string const& name,
140
 
    std::function<void(toolkit::Connection connection)> const& client_code,
 
159
    std::function<void(mir::client::Connection connection)> const& client_code,
141
160
    std::function<void(std::weak_ptr<mir::scene::Session> const session)> const& connect_notification) const
142
161
{
143
162
    self->runner = std::make_unique<InternalClientRunner>(name, client_code, connect_notification);