@@ -1,3 +1,4 @@
|
||||
/.qtcreator
|
||||
/build/
|
||||
/build-*/
|
||||
compile_commands.json
|
||||
|
||||
@@ -183,13 +183,6 @@ else()
|
||||
set(DN_WITH_SINGLE_INSTANCE FALSE)
|
||||
endif()
|
||||
|
||||
# TODO(p): Comments shouldn't change the signature.
|
||||
file(SHA256 "${PROJECT_SOURCE_DIR}/ipc/common.lxdr" DN_IPC_LXDR_H1)
|
||||
file(SHA256 "${PROJECT_SOURCE_DIR}/ipc/instance.lxdr" DN_IPC_LXDR_H2)
|
||||
string(SHA256 DN_IPC_LXDR_COMBINED "${DN_IPC_LXDR_H1}${DN_IPC_LXDR_H2}")
|
||||
string(SUBSTRING "${DN_IPC_LXDR_COMBINED}" 0 12 DN_IPC_LXDR_PREFIX)
|
||||
set(DN_IPC_BUILD_ID "dawn ${PROJECT_VERSION} ${DN_IPC_LXDR_PREFIX}")
|
||||
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/dawn-config.h.in"
|
||||
"${PROJECT_BINARY_DIR}/dawn-config.h"
|
||||
|
||||
@@ -21,4 +21,3 @@
|
||||
|
||||
#cmakedefine01 DN_WITH_WAYLAND
|
||||
#cmakedefine01 DN_WITH_SINGLE_INSTANCE
|
||||
#define DN_IPC_BUILD_ID "@DN_IPC_BUILD_ID@"
|
||||
|
||||
+5
-7
@@ -50,8 +50,7 @@ map_open_error(OpenResult r)
|
||||
} // namespace
|
||||
|
||||
struct InstanceHost::Impl {
|
||||
Impl(int listen_fd, App &app, const QString &build_id,
|
||||
const QString &session, InstanceHost *host);
|
||||
Impl(int listen_fd, App &app, const QString &session, InstanceHost *host);
|
||||
void watch_read(int fd);
|
||||
void watch_write(int fd, bool enable);
|
||||
void unwatch(int fd);
|
||||
@@ -65,12 +64,11 @@ struct InstanceHost::Impl {
|
||||
unique_ptr<ipc::Server> server_;
|
||||
};
|
||||
|
||||
InstanceHost::Impl::Impl(int listen_fd, App &app, const QString &build_id,
|
||||
const QString &session, InstanceHost *host)
|
||||
InstanceHost::Impl::Impl(int listen_fd, App &app, const QString &session,
|
||||
InstanceHost *host)
|
||||
: app_(app), host_(host)
|
||||
{
|
||||
ipc::Server::Config cfg;
|
||||
cfg.build_id = build_id.toUtf8().toStdString();
|
||||
cfg.session = session.toUtf8().toStdString();
|
||||
cfg.on_request = [this](const ipc::instance::RequestView &req,
|
||||
ipc::instance::Response &response) {
|
||||
@@ -159,9 +157,9 @@ InstanceHost::Impl::on_request(
|
||||
}
|
||||
|
||||
InstanceHost::InstanceHost(
|
||||
int listen_fd, App &app, QString build_id, QString session, QObject *parent)
|
||||
int listen_fd, App &app, QString session, QObject *parent)
|
||||
: QObject(parent),
|
||||
impl_(make_unique<Impl>(listen_fd, app, build_id, session, this))
|
||||
impl_(make_unique<Impl>(listen_fd, app, session, this))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -22,8 +22,8 @@ class InstanceHost : public QObject {
|
||||
public:
|
||||
// Takes ownership of listen_fd. Forwards Open requests to
|
||||
// app.open.
|
||||
InstanceHost(int listen_fd, App &app, QString build_id,
|
||||
QString session, QObject *parent = nullptr);
|
||||
InstanceHost(int listen_fd, App &app, QString session,
|
||||
QObject *parent = nullptr);
|
||||
~InstanceHost() override;
|
||||
|
||||
private:
|
||||
|
||||
+7
-11
@@ -109,14 +109,13 @@ report_mismatch(dn::ipc::BlockingClient::HelloStatus status, bool &reported)
|
||||
enum class Remote : uint8_t { Done, Failed, Isolated };
|
||||
|
||||
Remote
|
||||
try_remote_open(const QString &build_id, const QString &session,
|
||||
const QStringList &paths, bool &reported_mismatch)
|
||||
try_remote_open(const QString &session, const QStringList &paths,
|
||||
bool &reported_mismatch)
|
||||
{
|
||||
using HelloStatus = dn::ipc::BlockingClient::HelloStatus;
|
||||
HelloStatus status = HelloStatus::Unavailable;
|
||||
auto client =
|
||||
dn::ipc::BlockingClient::connect(build_id.toUtf8().toStdString(),
|
||||
session.toUtf8().toStdString(), &status);
|
||||
auto client = dn::ipc::BlockingClient::connect(
|
||||
session.toUtf8().toStdString(), &status);
|
||||
if (client) {
|
||||
if (handoff_open(*client, paths))
|
||||
return Remote::Done;
|
||||
@@ -200,11 +199,10 @@ main(int argc, char **argv)
|
||||
#if DN_WITH_SINGLE_INSTANCE
|
||||
unique_ptr<dn::InstanceHost> host;
|
||||
if (parser.isSet(new_instance_opt)) {
|
||||
const QString build_id = QString::fromUtf8(DN_IPC_BUILD_ID);
|
||||
const QString session = instance_session();
|
||||
bool reported_mismatch = false;
|
||||
switch (
|
||||
try_remote_open(build_id, session, to_open, reported_mismatch)) {
|
||||
try_remote_open(session, to_open, reported_mismatch)) {
|
||||
case Remote::Done:
|
||||
return 0;
|
||||
case Remote::Failed:
|
||||
@@ -215,8 +213,7 @@ main(int argc, char **argv)
|
||||
|
||||
const auto listen = dn::ipc::Endpoint::listen("instance");
|
||||
if (listen.status == dn::ipc::Endpoint::ListenStatus::InUse) {
|
||||
switch (try_remote_open(
|
||||
build_id, session, to_open, reported_mismatch)) {
|
||||
switch (try_remote_open(session, to_open, reported_mismatch)) {
|
||||
case Remote::Done:
|
||||
return 0;
|
||||
case Remote::Failed:
|
||||
@@ -227,8 +224,7 @@ main(int argc, char **argv)
|
||||
} else if (listen.status == dn::ipc::Endpoint::ListenStatus::Ok) {
|
||||
// Notifiers armed; Qt delivers them only in exec().
|
||||
// A Hello during init may time out (250ms) and isolate.
|
||||
host = make_unique<dn::InstanceHost>(
|
||||
listen.fd, app, build_id, session);
|
||||
host = make_unique<dn::InstanceHost>(listen.fd, app, session);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -153,8 +153,8 @@ BlockingClient::BlockingClient(BlockingClient &&) noexcept = default;
|
||||
BlockingClient &BlockingClient::operator=(BlockingClient &&) noexcept = default;
|
||||
BlockingClient::~BlockingClient() = default;
|
||||
optional<BlockingClient>
|
||||
BlockingClient::connect(string_view build_id, string_view session,
|
||||
HelloStatus *status, chrono::milliseconds timeout)
|
||||
BlockingClient::connect(string_view session, HelloStatus *status,
|
||||
chrono::milliseconds timeout)
|
||||
{
|
||||
using clock = chrono::steady_clock;
|
||||
chrono::milliseconds left = timeout;
|
||||
@@ -174,7 +174,6 @@ BlockingClient::connect(string_view build_id, string_view session,
|
||||
|
||||
instance::Hello hello;
|
||||
hello.protocol_version = uint32_t(instance::kInstanceProtocolVersion);
|
||||
hello.build_id = string(build_id);
|
||||
hello.session = string(session);
|
||||
|
||||
instance::Frame hello_frame;
|
||||
@@ -405,8 +404,7 @@ Server::handle_payload(Conn &c, span<const byte> payload)
|
||||
|
||||
instance::Frame reply;
|
||||
const instance::HelloView &h = hello->hello;
|
||||
if (h.protocol_version != cfg_.protocol_version ||
|
||||
h.build_id != cfg_.build_id) {
|
||||
if (h.protocol_version != cfg_.protocol_version) {
|
||||
instance::HelloReplyVersionMismatch mismatch;
|
||||
mismatch.server_protocol_version = cfg_.protocol_version;
|
||||
reply.payload.value = instance::PayloadHelloReply{
|
||||
|
||||
@@ -37,12 +37,11 @@ public:
|
||||
|
||||
// Connect to the "instance" endpoint and complete Hello.
|
||||
// protocol_version sent is kInstanceProtocolVersion.
|
||||
// build_id and session are compared exactly by the server.
|
||||
// The session is compared exactly by the server.
|
||||
// timeout covers connect plus handshake (default kHelloTimeout).
|
||||
// On failure returns nullopt and writes *status when non-null.
|
||||
static std::optional<BlockingClient> connect(
|
||||
std::string_view build_id, std::string_view session,
|
||||
HelloStatus *status,
|
||||
std::string_view session, HelloStatus *status,
|
||||
std::chrono::milliseconds timeout = kHelloTimeout);
|
||||
|
||||
// Send one Open request (id = 1). Wait for a terminal Response
|
||||
@@ -73,7 +72,6 @@ private:
|
||||
class Server {
|
||||
public:
|
||||
struct Config {
|
||||
std::string build_id;
|
||||
std::string session;
|
||||
uint32_t protocol_version =
|
||||
instance::kInstanceProtocolVersion;
|
||||
|
||||
Reference in New Issue
Block a user