summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/client_port.cpp
blob: 9a9cd4bfda9c8922b2e34efff68c104103b8c355 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include "common/assert.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/server_port.h"
#include "core/hle/kernel/server_session.h"
#include "core/hle/service/service.h"

namespace Kernel {

ClientPort::ClientPort() {}
ClientPort::~ClientPort() {}

Kernel::SharedPtr<ClientPort> ClientPort::CreateForHLE(u32 max_sessions, std::unique_ptr<Service::Interface> hle_interface) {
    SharedPtr<ClientPort> client_port(new ClientPort);
    client_port->max_sessions = max_sessions;
    client_port->active_sessions = 0;
    client_port->name = hle_interface->GetPortName();
    client_port->hle_interface = std::move(hle_interface);

    return client_port;
}

void ClientPort::AddWaitingSession(SharedPtr<ServerSession> server_session) {
    // A port that has an associated HLE interface doesn't have a server port.
    if (hle_interface != nullptr)
        return;

    server_port->pending_sessions.push_back(server_session);
    // Wake the threads waiting on the ServerPort
    server_port->WakeupAllWaitingThreads();
}

ResultCode ClientPort::HandleSyncRequest() {
    // Forward the request to the associated HLE interface if it exists
    if (hle_interface != nullptr)
        return hle_interface->HandleSyncRequest();

    return RESULT_SUCCESS;
}

} // namespace