service/cecd: Migrate to ServiceFramework

This commit is contained in:
NarcolepticK 2018-06-30 23:27:57 -04:00
parent 4564fc5baa
commit 363d6fdb89
9 changed files with 148 additions and 140 deletions

View File

@ -3,64 +3,62 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/hle/ipc.h" #include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/hle/service/cecd/cecd.h" #include "core/hle/service/cecd/cecd.h"
#include "core/hle/service/cecd/cecd_ndm.h" #include "core/hle/service/cecd/cecd_ndm.h"
#include "core/hle/service/cecd/cecd_s.h" #include "core/hle/service/cecd/cecd_s.h"
#include "core/hle/service/cecd/cecd_u.h" #include "core/hle/service/cecd/cecd_u.h"
#include "core/hle/service/service.h"
namespace Service { namespace Service {
namespace CECD { namespace CECD {
static Kernel::SharedPtr<Kernel::Event> cecinfo_event; void Module::Interface::GetCecStateAbbreviated(Kernel::HLERequestContext& ctx) {
static Kernel::SharedPtr<Kernel::Event> change_state_event; IPC::RequestParser rp(ctx, 0x0E, 0, 0);
void GetCecStateAbbreviated(Service::Interface* self) { IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
u32* cmd_buff = Kernel::GetCommandBuffer(); rb.Push(RESULT_SUCCESS);
rb.Push<u32>(static_cast<u32>(CecStateAbbreviated::CEC_STATE_ABBREV_IDLE));
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
cmd_buff[2] = static_cast<u32>(CecStateAbbreviated::CEC_STATE_ABBREV_IDLE);
LOG_WARNING(Service_CECD, "(STUBBED) called"); LOG_WARNING(Service_CECD, "(STUBBED) called");
} }
void GetCecInfoEventHandle(Service::Interface* self) { void Module::Interface::GetCecInfoEventHandle(Kernel::HLERequestContext& ctx) {
u32* cmd_buff = Kernel::GetCommandBuffer(); IPC::RequestParser rp(ctx, 0x0F, 0, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
cmd_buff[3] = Kernel::g_handle_table.Create(cecinfo_event).Unwrap(); // Event handle rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(cecd->cecinfo_event);
LOG_WARNING(Service_CECD, "(STUBBED) called"); LOG_WARNING(Service_CECD, "(STUBBED) called");
} }
void GetChangeStateEventHandle(Service::Interface* self) { void Module::Interface::GetChangeStateEventHandle(Kernel::HLERequestContext& ctx) {
u32* cmd_buff = Kernel::GetCommandBuffer(); IPC::RequestParser rp(ctx, 0x10, 0, 0);
cmd_buff[1] = RESULT_SUCCESS.raw; // No error IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
cmd_buff[3] = Kernel::g_handle_table.Create(change_state_event).Unwrap(); // Event handle rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(cecd->change_state_event);
LOG_WARNING(Service_CECD, "(STUBBED) called"); LOG_WARNING(Service_CECD, "(STUBBED) called");
} }
void Init() { Module::Interface::Interface(std::shared_ptr<Module> cecd, const char* name, u32 max_session)
AddService(new CECD_NDM); : ServiceFramework(name, max_session), cecd(std::move(cecd)) {}
AddService(new CECD_S);
AddService(new CECD_U);
cecinfo_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "CECD::cecinfo_event"); Module::Module() {
change_state_event = using namespace Kernel;
Kernel::Event::Create(Kernel::ResetType::OneShot, "CECD::change_state_event"); cecinfo_event = Event::Create(Kernel::ResetType::OneShot, "CECD::cecinfo_event");
change_state_event = Event::Create(Kernel::ResetType::OneShot, "CECD::change_state_event");
} }
void Shutdown() { void InstallInterfaces(SM::ServiceManager& service_manager) {
cecinfo_event = nullptr; auto cecd = std::make_shared<Module>();
change_state_event = nullptr; std::make_shared<CECD_NDM>(cecd)->InstallAsService(service_manager);
std::make_shared<CECD_S>(cecd)->InstallAsService(service_manager);
std::make_shared<CECD_U>(cecd)->InstallAsService(service_manager);
} }
} // namespace CECD } // namespace CECD
} // namespace Service } // namespace Service

View File

@ -4,10 +4,10 @@
#pragma once #pragma once
#include "core/hle/kernel/event.h"
#include "core/hle/service/service.h"
namespace Service { namespace Service {
class Interface;
namespace CECD { namespace CECD {
enum class CecStateAbbreviated { enum class CecStateAbbreviated {
@ -20,6 +20,17 @@ enum class CecStateAbbreviated {
/// OVER_BOSS and those listed here /// OVER_BOSS and those listed here
}; };
class Module final {
public:
Module();
~Module() = default;
class Interface : public ServiceFramework<Interface> {
public:
Interface(std::shared_ptr<Module> cecd, const char* name, u32 max_session);
~Interface() = default;
protected:
/** /**
* GetCecStateAbbreviated service function * GetCecStateAbbreviated service function
* Inputs: * Inputs:
@ -28,7 +39,7 @@ enum class CecStateAbbreviated {
* 1: ResultCode * 1: ResultCode
* 2: CecStateAbbreviated * 2: CecStateAbbreviated
*/ */
void GetCecStateAbbreviated(Service::Interface* self); void GetCecStateAbbreviated(Kernel::HLERequestContext& ctx);
/** /**
* GetCecInfoEventHandle service function * GetCecInfoEventHandle service function
@ -38,7 +49,7 @@ void GetCecStateAbbreviated(Service::Interface* self);
* 1: ResultCode * 1: ResultCode
* 3: Event Handle * 3: Event Handle
*/ */
void GetCecInfoEventHandle(Service::Interface* self); void GetCecInfoEventHandle(Kernel::HLERequestContext& ctx);
/** /**
* GetChangeStateEventHandle service function * GetChangeStateEventHandle service function
@ -48,13 +59,19 @@ void GetCecInfoEventHandle(Service::Interface* self);
* 1: ResultCode * 1: ResultCode
* 3: Event Handle * 3: Event Handle
*/ */
void GetChangeStateEventHandle(Service::Interface* self); void GetChangeStateEventHandle(Kernel::HLERequestContext& ctx);
private:
std::shared_ptr<Module> cecd;
};
private:
Kernel::SharedPtr<Kernel::Event> cecinfo_event;
Kernel::SharedPtr<Kernel::Event> change_state_event;
};
/// Initialize CECD service(s) /// Initialize CECD service(s)
void Init(); void InstallInterfaces(SM::ServiceManager& service_manager);
/// Shutdown CECD service(s)
void Shutdown();
} // namespace CECD } // namespace CECD
} // namespace Service } // namespace Service

View File

@ -2,21 +2,23 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "core/hle/service/cecd/cecd.h"
#include "core/hle/service/cecd/cecd_ndm.h" #include "core/hle/service/cecd/cecd_ndm.h"
namespace Service { namespace Service {
namespace CECD { namespace CECD {
static const Interface::FunctionInfo FunctionTable[] = { CECD_NDM::CECD_NDM(std::shared_ptr<Module> cecd)
: Module::Interface(std::move(cecd), "cecd:ndm", DefaultMaxSessions) {
static const FunctionInfo functions[] = {
// clang-format off
{0x00010000, nullptr, "Initialize"}, {0x00010000, nullptr, "Initialize"},
{0x00020000, nullptr, "Deinitialize"}, {0x00020000, nullptr, "Deinitialize"},
{0x00030000, nullptr, "ResumeDaemon"}, {0x00030000, nullptr, "ResumeDaemon"},
{0x00040040, nullptr, "SuspendDaemon"}, {0x00040040, nullptr, "SuspendDaemon"},
// clang-format on
}; };
CECD_NDM::CECD_NDM() { RegisterHandlers(functions);
Register(FunctionTable);
} }
} // namespace CECD } // namespace CECD

View File

@ -4,18 +4,14 @@
#pragma once #pragma once
#include "core/hle/service/service.h" #include "core/hle/service/cecd/cecd.h"
namespace Service { namespace Service {
namespace CECD { namespace CECD {
class CECD_NDM : public Interface { class CECD_NDM final : public Module::Interface {
public: public:
CECD_NDM(); explicit CECD_NDM(std::shared_ptr<Module> cecd);
std::string GetPortName() const override {
return "cecd:ndm";
}
}; };
} // namespace CECD } // namespace CECD

View File

@ -2,14 +2,16 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "core/hle/service/cecd/cecd.h"
#include "core/hle/service/cecd/cecd_s.h" #include "core/hle/service/cecd/cecd_s.h"
namespace Service { namespace Service {
namespace CECD { namespace CECD {
static const Interface::FunctionInfo FunctionTable[] = { CECD_S::CECD_S(std::shared_ptr<Module> cecd)
: Module::Interface(std::move(cecd), "cecd:s", DefaultMaxSessions) {
static const FunctionInfo functions[] = {
// cecd:u shared commands // cecd:u shared commands
// clang-format off
{0x000100C2, nullptr, "OpenRawFile"}, {0x000100C2, nullptr, "OpenRawFile"},
{0x00020042, nullptr, "ReadRawFile"}, {0x00020042, nullptr, "ReadRawFile"},
{0x00030104, nullptr, "ReadMessage"}, {0x00030104, nullptr, "ReadMessage"},
@ -21,15 +23,15 @@ static const Interface::FunctionInfo FunctionTable[] = {
{0x000A00C4, nullptr, "GetSystemInfo"}, {0x000A00C4, nullptr, "GetSystemInfo"},
{0x000B0040, nullptr, "RunCommand"}, {0x000B0040, nullptr, "RunCommand"},
{0x000C0040, nullptr, "RunCommandAlt"}, {0x000C0040, nullptr, "RunCommandAlt"},
{0x000E0000, GetCecStateAbbreviated, "GetCecStateAbbreviated"}, {0x000E0000, &CECD_S::GetCecStateAbbreviated, "GetCecStateAbbreviated"},
{0x000F0000, GetCecInfoEventHandle, "GetCecInfoEventHandle"}, {0x000F0000, &CECD_S::GetCecInfoEventHandle, "GetCecInfoEventHandle"},
{0x00100000, GetChangeStateEventHandle, "GetChangeStateEventHandle"}, {0x00100000, &CECD_S::GetChangeStateEventHandle, "GetChangeStateEventHandle"},
{0x00110104, nullptr, "OpenAndWrite"}, {0x00110104, nullptr, "OpenAndWrite"},
{0x00120104, nullptr, "OpenAndRead"}, {0x00120104, nullptr, "OpenAndRead"},
// clang-format on
}; };
CECD_S::CECD_S() { RegisterHandlers(functions);
Register(FunctionTable);
} }
} // namespace CECD } // namespace CECD

View File

@ -4,18 +4,14 @@
#pragma once #pragma once
#include "core/hle/service/service.h" #include "core/hle/service/cecd/cecd.h"
namespace Service { namespace Service {
namespace CECD { namespace CECD {
class CECD_S : public Interface { class CECD_S final : public Module::Interface {
public: public:
CECD_S(); explicit CECD_S(std::shared_ptr<Module> cecd);
std::string GetPortName() const override {
return "cecd:s";
}
}; };
} // namespace CECD } // namespace CECD

View File

@ -2,14 +2,16 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "core/hle/service/cecd/cecd.h"
#include "core/hle/service/cecd/cecd_u.h" #include "core/hle/service/cecd/cecd_u.h"
namespace Service { namespace Service {
namespace CECD { namespace CECD {
static const Interface::FunctionInfo FunctionTable[] = { CECD_U::CECD_U(std::shared_ptr<Module> cecd)
: Module::Interface(std::move(cecd), "cecd:u", DefaultMaxSessions) {
static const FunctionInfo functions[] = {
// cecd:u shared commands // cecd:u shared commands
// clang-format off
{0x000100C2, nullptr, "OpenRawFile"}, {0x000100C2, nullptr, "OpenRawFile"},
{0x00020042, nullptr, "ReadRawFile"}, {0x00020042, nullptr, "ReadRawFile"},
{0x00030104, nullptr, "ReadMessage"}, {0x00030104, nullptr, "ReadMessage"},
@ -21,15 +23,15 @@ static const Interface::FunctionInfo FunctionTable[] = {
{0x000A00C4, nullptr, "GetSystemInfo"}, {0x000A00C4, nullptr, "GetSystemInfo"},
{0x000B0040, nullptr, "RunCommand"}, {0x000B0040, nullptr, "RunCommand"},
{0x000C0040, nullptr, "RunCommandAlt"}, {0x000C0040, nullptr, "RunCommandAlt"},
{0x000E0000, GetCecStateAbbreviated, "GetCecStateAbbreviated"}, {0x000E0000, &CECD_U::GetCecStateAbbreviated, "GetCecStateAbbreviated"},
{0x000F0000, GetCecInfoEventHandle, "GetCecInfoEventHandle"}, {0x000F0000, &CECD_U::GetCecInfoEventHandle, "GetCecInfoEventHandle"},
{0x00100000, GetChangeStateEventHandle, "GetChangeStateEventHandle"}, {0x00100000, &CECD_U::GetChangeStateEventHandle, "GetChangeStateEventHandle"},
{0x00110104, nullptr, "OpenAndWrite"}, {0x00110104, nullptr, "OpenAndWrite"},
{0x00120104, nullptr, "OpenAndRead"}, {0x00120104, nullptr, "OpenAndRead"},
// clang-format on
}; };
CECD_U::CECD_U() { RegisterHandlers(functions);
Register(FunctionTable);
} }
} // namespace CECD } // namespace CECD

View File

@ -4,18 +4,14 @@
#pragma once #pragma once
#include "core/hle/service/service.h" #include "core/hle/service/cecd/cecd.h"
namespace Service { namespace Service {
namespace CECD { namespace CECD {
class CECD_U : public Interface { class CECD_U final : public Module::Interface {
public: public:
CECD_U(); explicit CECD_U(std::shared_ptr<Module> cecd);
std::string GetPortName() const override {
return "cecd:u";
}
}; };
} // namespace CECD } // namespace CECD

View File

@ -239,7 +239,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm) {
APT::InstallInterfaces(*sm); APT::InstallInterfaces(*sm);
BOSS::Init(); BOSS::Init();
CAM::InstallInterfaces(*sm); CAM::InstallInterfaces(*sm);
CECD::Init(); CECD::InstallInterfaces(*sm);
CFG::InstallInterfaces(*sm); CFG::InstallInterfaces(*sm);
DLP::InstallInterfaces(*sm); DLP::InstallInterfaces(*sm);
FRD::InstallInterfaces(*sm); FRD::InstallInterfaces(*sm);
@ -268,7 +268,6 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm) {
/// Shutdown ServiceManager /// Shutdown ServiceManager
void Shutdown() { void Shutdown() {
CECD::Shutdown();
BOSS::Shutdown(); BOSS::Shutdown();
FS::ArchiveShutdown(); FS::ArchiveShutdown();