2016-05-22 18:22:49 +02:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-12-08 04:09:20 +01:00
|
|
|
#include <memory>
|
2016-05-22 18:22:49 +02:00
|
|
|
#include <string>
|
2019-12-08 04:09:20 +01:00
|
|
|
|
2016-05-22 18:22:49 +02:00
|
|
|
#include "common/common_types.h"
|
2021-04-22 06:43:25 +02:00
|
|
|
#include "core/hle/kernel/k_synchronization_object.h"
|
2017-05-30 01:45:42 +02:00
|
|
|
#include "core/hle/result.h"
|
2016-05-22 18:22:49 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-04-14 02:48:37 +02:00
|
|
|
class KClientSession;
|
2018-08-28 18:30:33 +02:00
|
|
|
class KernelCore;
|
2018-10-06 09:47:33 +02:00
|
|
|
class ServerPort;
|
2016-05-22 19:30:13 +02:00
|
|
|
|
2021-04-22 06:43:25 +02:00
|
|
|
class KClientPort final : public KSynchronizationObject {
|
|
|
|
KERNEL_AUTOOBJECT_TRAITS(KClientPort, KSynchronizationObject);
|
|
|
|
|
2016-05-22 18:22:49 +02:00
|
|
|
public:
|
2021-04-22 06:43:25 +02:00
|
|
|
explicit KClientPort(KernelCore& kernel);
|
|
|
|
virtual ~KClientPort() override;
|
2019-11-25 02:15:51 +01:00
|
|
|
|
2016-05-22 18:22:49 +02:00
|
|
|
friend class ServerPort;
|
2016-12-01 05:28:31 +01:00
|
|
|
|
2021-04-22 06:43:25 +02:00
|
|
|
void Initialize(s32 max_sessions_, std::string&& name_);
|
2016-06-15 01:03:30 +02:00
|
|
|
|
2019-11-25 02:15:51 +01:00
|
|
|
std::shared_ptr<ServerPort> GetServerPort() const;
|
2018-10-06 08:49:01 +02:00
|
|
|
|
2016-06-15 01:03:30 +02:00
|
|
|
/**
|
2016-12-14 18:33:49 +01:00
|
|
|
* Creates a new Session pair, adds the created ServerSession to the associated ServerPort's
|
|
|
|
* list of pending sessions, and signals the ServerPort, causing any threads
|
|
|
|
* waiting on it to awake.
|
2016-12-05 19:59:57 +01:00
|
|
|
* @returns ClientSession The client endpoint of the created Session pair, or error code.
|
2016-06-15 01:03:30 +02:00
|
|
|
*/
|
2021-04-14 02:48:37 +02:00
|
|
|
ResultVal<KClientSession*> Connect();
|
2016-06-15 01:03:30 +02:00
|
|
|
|
2018-08-07 04:09:31 +02:00
|
|
|
/**
|
|
|
|
* Signifies that a previously active connection has been closed,
|
|
|
|
* decreasing the total number of active connections to this port.
|
|
|
|
*/
|
|
|
|
void ConnectionClosed();
|
2016-12-05 17:02:08 +01:00
|
|
|
|
2021-04-22 06:43:25 +02:00
|
|
|
// Overridden virtual functions.
|
|
|
|
virtual void Destroy() override;
|
|
|
|
virtual bool IsSignaled() const override;
|
|
|
|
|
|
|
|
// DEPRECATED
|
|
|
|
|
|
|
|
std::string GetTypeName() const override {
|
|
|
|
return "ClientPort";
|
|
|
|
}
|
|
|
|
std::string GetName() const override {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr HandleType HANDLE_TYPE = HandleType::ClientPort;
|
|
|
|
HandleType GetHandleType() const override {
|
|
|
|
return HANDLE_TYPE;
|
|
|
|
}
|
2021-01-16 09:25:29 +01:00
|
|
|
|
2016-06-18 00:09:43 +02:00
|
|
|
private:
|
2019-11-25 02:15:51 +01:00
|
|
|
std::shared_ptr<ServerPort> server_port; ///< ServerPort associated with this client port.
|
2021-04-22 06:43:25 +02:00
|
|
|
s32 max_sessions = 0; ///< Maximum number of simultaneous sessions the port can have
|
|
|
|
std::atomic<s32> num_sessions = 0; ///< Number of currently open sessions to this port
|
|
|
|
std::string name; ///< Name of client port (optional)
|
2016-05-22 18:22:49 +02:00
|
|
|
};
|
|
|
|
|
2018-01-20 08:48:02 +01:00
|
|
|
} // namespace Kernel
|