From 935bcdbd204bfc1d601fd5d12851ded188b69266 Mon Sep 17 00:00:00 2001
From: Starlet <antherynx.studio@mail.com>
Date: Fri, 16 Mar 2018 05:36:35 -0400
Subject: [PATCH] Convert ACT to the new service framework (#3521)

* Convert ACT to the new service framework

* Fix clang-format

* le updates to fix stuff

* Fixed one last thing.

* Well, I fucked up.

* Quick hotfix
---
 src/core/hle/service/act/act.cpp   | 12 ++++++++---
 src/core/hle/service/act/act.h     | 16 ++++++++++++++-
 src/core/hle/service/act/act_a.cpp | 32 ++++++++++++++----------------
 src/core/hle/service/act/act_a.h   | 10 +++-------
 src/core/hle/service/act/act_u.cpp | 24 ++++++++++------------
 src/core/hle/service/act/act_u.h   | 10 +++-------
 src/core/hle/service/service.cpp   |  2 +-
 7 files changed, 57 insertions(+), 49 deletions(-)

diff --git a/src/core/hle/service/act/act.cpp b/src/core/hle/service/act/act.cpp
index 9600036c0..dbe5617b9 100644
--- a/src/core/hle/service/act/act.cpp
+++ b/src/core/hle/service/act/act.cpp
@@ -9,9 +9,15 @@
 namespace Service {
 namespace ACT {
 
-void Init() {
-    AddService(new ACT_A);
-    AddService(new ACT_U);
+Module::Interface::Interface(std::shared_ptr<Module> act, const char* name)
+    : ServiceFramework(name, 1 /* Placeholder */), act(std::move(act)) {}
+
+Module::Interface::~Interface() = default;
+
+void InstallInterfaces(SM::ServiceManager& service_manager) {
+    auto act = std::make_shared<Module>();
+    std::make_shared<ACT_A>(act)->InstallAsService(service_manager);
+    std::make_shared<ACT_U>(act)->InstallAsService(service_manager);
 }
 
 } // namespace ACT
diff --git a/src/core/hle/service/act/act.h b/src/core/hle/service/act/act.h
index 1425291aa..a5805a5ff 100644
--- a/src/core/hle/service/act/act.h
+++ b/src/core/hle/service/act/act.h
@@ -4,11 +4,25 @@
 
 #pragma once
 
+#include "core/hle/service/service.h"
+
 namespace Service {
 namespace ACT {
 
 /// Initializes all ACT services
-void Init();
+class Module final {
+public:
+    class Interface : public ServiceFramework<Interface> {
+    public:
+        Interface(std::shared_ptr<Module> act, const char* name);
+        ~Interface();
+
+    private:
+        std::shared_ptr<Module> act;
+    };
+};
+
+void InstallInterfaces(SM::ServiceManager& service_manager);
 
 } // namespace ACT
 } // namespace Service
diff --git a/src/core/hle/service/act/act_a.cpp b/src/core/hle/service/act/act_a.cpp
index 5c523368f..cd8ca40dd 100644
--- a/src/core/hle/service/act/act_a.cpp
+++ b/src/core/hle/service/act/act_a.cpp
@@ -2,28 +2,26 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include "core/hle/service/act/act.h"
 #include "core/hle/service/act/act_a.h"
 
 namespace Service {
 namespace ACT {
 
-const Interface::FunctionInfo FunctionTable[] = {
-    // act:u shared commands
-    {0x00010084, nullptr, "Initialize"},
-    {0x00020040, nullptr, "GetErrorCode"},
-    {0x000600C2, nullptr, "GetAccountDataBlock"},
-    {0x000B0042, nullptr, "AcquireEulaList"},
-    {0x000D0040, nullptr, "GenerateUuid"},
-    // act:a
-    {0x041300C2, nullptr, "UpdateMiiImage"},
-    {0x041B0142, nullptr, "AgreeEula"},
-    {0x04210042, nullptr, "UploadMii"},
-    {0x04230082, nullptr, "ValidateMailAddress"},
-};
-
-ACT_A::ACT_A() {
-    Register(FunctionTable);
+ACT_A::ACT_A(std::shared_ptr<Module> act) : Module::Interface(std::move(act), "act:a") {
+    const FunctionInfo functions[] = {
+        // act:u shared commands
+        {0x00010084, nullptr, "Initialize"},
+        {0x00020040, nullptr, "GetErrorCode"},
+        {0x000600C2, nullptr, "GetAccountDataBlock"},
+        {0x000B0042, nullptr, "AcquireEulaList"},
+        {0x000D0040, nullptr, "GenerateUuid"},
+        // act:a
+        {0x041300C2, nullptr, "UpdateMiiImage"},
+        {0x041B0142, nullptr, "AgreeEula"},
+        {0x04210042, nullptr, "UploadMii"},
+        {0x04230082, nullptr, "ValidateMailAddress"},
+    };
+    RegisterHandlers(functions);
 }
 
 } // namespace ACT
diff --git a/src/core/hle/service/act/act_a.h b/src/core/hle/service/act/act_a.h
index e3adb03e5..4b5f37fbb 100644
--- a/src/core/hle/service/act/act_a.h
+++ b/src/core/hle/service/act/act_a.h
@@ -4,18 +4,14 @@
 
 #pragma once
 
-#include "core/hle/service/service.h"
+#include "core/hle/service/act/act.h"
 
 namespace Service {
 namespace ACT {
 
-class ACT_A final : public Service::Interface {
+class ACT_A final : public Module::Interface {
 public:
-    ACT_A();
-
-    std::string GetPortName() const override {
-        return "act:a";
-    }
+    explicit ACT_A(std::shared_ptr<Module> act);
 };
 
 } // namespace ACT
diff --git a/src/core/hle/service/act/act_u.cpp b/src/core/hle/service/act/act_u.cpp
index cf98aa1d6..eda253b78 100644
--- a/src/core/hle/service/act/act_u.cpp
+++ b/src/core/hle/service/act/act_u.cpp
@@ -2,24 +2,22 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
-#include "core/hle/service/act/act.h"
 #include "core/hle/service/act/act_u.h"
 
 namespace Service {
 namespace ACT {
 
-const Interface::FunctionInfo FunctionTable[] = {
-    // clang-format off
-    {0x00010084, nullptr, "Initialize"},
-    {0x00020040, nullptr, "GetErrorCode"},
-    {0x000600C2, nullptr, "GetAccountDataBlock"},
-    {0x000B0042, nullptr, "AcquireEulaList"},
-    {0x000D0040, nullptr, "GenerateUuid"},
-    // clang-format on
-};
-
-ACT_U::ACT_U() {
-    Register(FunctionTable);
+ACT_U::ACT_U(std::shared_ptr<Module> act) : Module::Interface(std::move(act), "act:u") {
+    static const FunctionInfo functions[] = {
+        // clang-format off
+        {0x00010084, nullptr, "Initialize"},
+        {0x00020040, nullptr, "GetErrorCode"},
+        {0x000600C2, nullptr, "GetAccountDataBlock"},
+        {0x000B0042, nullptr, "AcquireEulaList"},
+        {0x000D0040, nullptr, "GenerateUuid"},
+        // clang-format on
+    };
+    RegisterHandlers(functions);
 }
 
 } // namespace ACT
diff --git a/src/core/hle/service/act/act_u.h b/src/core/hle/service/act/act_u.h
index 9d8538fbf..82214f496 100644
--- a/src/core/hle/service/act/act_u.h
+++ b/src/core/hle/service/act/act_u.h
@@ -4,18 +4,14 @@
 
 #pragma once
 
-#include "core/hle/service/service.h"
+#include "core/hle/service/act/act.h"
 
 namespace Service {
 namespace ACT {
 
-class ACT_U final : public Interface {
+class ACT_U final : public Module::Interface {
 public:
-    ACT_U();
-
-    std::string GetPortName() const override {
-        return "act:u";
-    }
+    explicit ACT_U(std::shared_ptr<Module> act);
 };
 
 } // namespace ACT
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 534a65706..5d3d8ad8e 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -236,7 +236,7 @@ void Init() {
 
     FS::InstallInterfaces(*SM::g_service_manager);
     FS::ArchiveInit();
-    ACT::Init();
+    ACT::InstallInterfaces(*SM::g_service_manager);
     AM::InstallInterfaces(*SM::g_service_manager);
     APT::InstallInterfaces(*SM::g_service_manager);
     BOSS::Init();