summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/ldn/ldn.cpp
blob: f2d638c30eb4e4e8df46efe6a63661f5a16d585b (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "core/core.h"
#include "core/hle/service/cmif_serialization.h"
#include "core/hle/service/ldn/ldn.h"
#include "core/hle/service/ldn/monitor_service.h"
#include "core/hle/service/ldn/sf_monitor_service.h"
#include "core/hle/service/ldn/sf_service.h"
#include "core/hle/service/ldn/sf_service_monitor.h"
#include "core/hle/service/ldn/system_local_communication_service.h"
#include "core/hle/service/ldn/user_local_communication_service.h"

namespace Service::LDN {

class IMonitorServiceCreator final : public ServiceFramework<IMonitorServiceCreator> {
public:
    explicit IMonitorServiceCreator(Core::System& system_) : ServiceFramework{system_, "ldn:m"} {
        // clang-format off
        static const FunctionInfo functions[] = {
            {0, C<&IMonitorServiceCreator::CreateMonitorService>, "CreateMonitorService"}
        };
        // clang-format on

        RegisterHandlers(functions);
    }

private:
    Result CreateMonitorService(OutInterface<IMonitorService> out_interface) {
        LOG_DEBUG(Service_LDN, "called");

        *out_interface = std::make_shared<IMonitorService>(system);
        R_SUCCEED();
    }
};

class ISystemServiceCreator final : public ServiceFramework<ISystemServiceCreator> {
public:
    explicit ISystemServiceCreator(Core::System& system_) : ServiceFramework{system_, "ldn:s"} {
        // clang-format off
        static const FunctionInfo functions[] = {
            {0, C<&ISystemServiceCreator::CreateSystemLocalCommunicationService>, "CreateSystemLocalCommunicationService"},
        };
        // clang-format on

        RegisterHandlers(functions);
    }

private:
    Result CreateSystemLocalCommunicationService(
        OutInterface<ISystemLocalCommunicationService> out_interface) {
        LOG_DEBUG(Service_LDN, "called");

        *out_interface = std::make_shared<ISystemLocalCommunicationService>(system);
        R_SUCCEED();
    }
};

class IUserServiceCreator final : public ServiceFramework<IUserServiceCreator> {
public:
    explicit IUserServiceCreator(Core::System& system_) : ServiceFramework{system_, "ldn:u"} {
        // clang-format off
        static const FunctionInfo functions[] = {
            {0, C<&IUserServiceCreator::CreateUserLocalCommunicationService>, "CreateUserLocalCommunicationService"},
        };
        // clang-format on

        RegisterHandlers(functions);
    }

private:
    Result CreateUserLocalCommunicationService(
        OutInterface<IUserLocalCommunicationService> out_interface) {
        LOG_DEBUG(Service_LDN, "called");

        *out_interface = std::make_shared<IUserLocalCommunicationService>(system);
        R_SUCCEED();
    }
};

class ISfServiceCreator final : public ServiceFramework<ISfServiceCreator> {
public:
    explicit ISfServiceCreator(Core::System& system_, bool is_system_, const char* name_)
        : ServiceFramework{system_, name_}, is_system{is_system_} {
        // clang-format off
        static const FunctionInfo functions[] = {
            {0, C<&ISfServiceCreator::CreateNetworkService>, "CreateNetworkService"},
            {8, C<&ISfServiceCreator::CreateNetworkServiceMonitor>, "CreateNetworkServiceMonitor"},
        };
        // clang-format on

        RegisterHandlers(functions);
    }

private:
    Result CreateNetworkService(OutInterface<ISfService> out_interface, u32 input,
                                u64 reserved_input) {
        LOG_WARNING(Service_LDN, "(STUBBED) called reserved_input={} input={}", reserved_input,
                    input);

        *out_interface = std::make_shared<ISfService>(system);
        R_SUCCEED();
    }

    Result CreateNetworkServiceMonitor(OutInterface<ISfServiceMonitor> out_interface,
                                       u64 reserved_input) {
        LOG_WARNING(Service_LDN, "(STUBBED) called reserved_input={}", reserved_input);

        *out_interface = std::make_shared<ISfServiceMonitor>(system);
        R_SUCCEED();
    }

    bool is_system{};
};

class ISfMonitorServiceCreator final : public ServiceFramework<ISfMonitorServiceCreator> {
public:
    explicit ISfMonitorServiceCreator(Core::System& system_) : ServiceFramework{system_, "lp2p:m"} {
        // clang-format off
        static const FunctionInfo functions[] = {
            {0, C<&ISfMonitorServiceCreator::CreateMonitorService>, "CreateMonitorService"},
        };
        // clang-format on

        RegisterHandlers(functions);
    }

private:
    Result CreateMonitorService(OutInterface<ISfMonitorService> out_interface, u64 reserved_input) {
        LOG_INFO(Service_LDN, "called, reserved_input={}", reserved_input);

        *out_interface = std::make_shared<ISfMonitorService>(system);
        R_SUCCEED();
    }
};

void LoopProcess(Core::System& system) {
    auto server_manager = std::make_unique<ServerManager>(system);

    server_manager->RegisterNamedService("ldn:m", std::make_shared<IMonitorServiceCreator>(system));
    server_manager->RegisterNamedService("ldn:s", std::make_shared<ISystemServiceCreator>(system));
    server_manager->RegisterNamedService("ldn:u", std::make_shared<IUserServiceCreator>(system));

    server_manager->RegisterNamedService(
        "lp2p:app", std::make_shared<ISfServiceCreator>(system, false, "lp2p:app"));
    server_manager->RegisterNamedService(
        "lp2p:sys", std::make_shared<ISfServiceCreator>(system, true, "lp2p:sys"));
    server_manager->RegisterNamedService("lp2p:m",
                                         std::make_shared<ISfMonitorServiceCreator>(system));

    ServerManager::RunServer(std::move(server_manager));
}

} // namespace Service::LDN