summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar german772023-04-25 23:33:05 -0600
committerGravatar Narr the Reg2023-04-25 23:36:24 -0600
commit5e16fe4579e10cf21af9fada603d8d585f683caf (patch)
tree1b417a71dbce8a99f0903fc7f8f25491468cb284 /src
parentservice: nfc: Create mifare interface (diff)
downloadyuzu-5e16fe4579e10cf21af9fada603d8d585f683caf.tar.gz
yuzu-5e16fe4579e10cf21af9fada603d8d585f683caf.tar.xz
yuzu-5e16fe4579e10cf21af9fada603d8d585f683caf.zip
core: service: Add FunctionInfoTyped to allow expanding existing interfaces
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/service.h20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index 0f79a1b7e..45b2c43b7 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -142,7 +142,8 @@ template <typename Self>
142class ServiceFramework : public ServiceFrameworkBase { 142class ServiceFramework : public ServiceFrameworkBase {
143protected: 143protected:
144 /// Contains information about a request type which is handled by the service. 144 /// Contains information about a request type which is handled by the service.
145 struct FunctionInfo : FunctionInfoBase { 145 template <typename T>
146 struct FunctionInfoTyped : FunctionInfoBase {
146 // TODO(yuriks): This function could be constexpr, but clang is the only compiler that 147 // TODO(yuriks): This function could be constexpr, but clang is the only compiler that
147 // doesn't emit an ICE or a wrong diagnostic because of the static_cast. 148 // doesn't emit an ICE or a wrong diagnostic because of the static_cast.
148 149
@@ -155,12 +156,13 @@ protected:
155 * the request 156 * the request
156 * @param name_ human-friendly name for the request. Used mostly for logging purposes. 157 * @param name_ human-friendly name for the request. Used mostly for logging purposes.
157 */ 158 */
158 FunctionInfo(u32 expected_header_, HandlerFnP<Self> handler_callback_, const char* name_) 159 FunctionInfoTyped(u32 expected_header_, HandlerFnP<T> handler_callback_, const char* name_)
159 : FunctionInfoBase{ 160 : FunctionInfoBase{
160 expected_header_, 161 expected_header_,
161 // Type-erase member function pointer by casting it down to the base class. 162 // Type-erase member function pointer by casting it down to the base class.
162 static_cast<HandlerFnP<ServiceFrameworkBase>>(handler_callback_), name_} {} 163 static_cast<HandlerFnP<ServiceFrameworkBase>>(handler_callback_), name_} {}
163 }; 164 };
165 using FunctionInfo = FunctionInfoTyped<Self>;
164 166
165 /** 167 /**
166 * Initializes the handler with no functions installed. 168 * Initializes the handler with no functions installed.
@@ -175,8 +177,8 @@ protected:
175 : ServiceFrameworkBase(system_, service_name_, max_sessions_, Invoker) {} 177 : ServiceFrameworkBase(system_, service_name_, max_sessions_, Invoker) {}
176 178
177 /// Registers handlers in the service. 179 /// Registers handlers in the service.
178 template <std::size_t N> 180 template <typename T = Self, std::size_t N>
179 void RegisterHandlers(const FunctionInfo (&functions)[N]) { 181 void RegisterHandlers(const FunctionInfoTyped<T> (&functions)[N]) {
180 RegisterHandlers(functions, N); 182 RegisterHandlers(functions, N);
181 } 183 }
182 184
@@ -184,13 +186,14 @@ protected:
184 * Registers handlers in the service. Usually prefer using the other RegisterHandlers 186 * Registers handlers in the service. Usually prefer using the other RegisterHandlers
185 * overload in order to avoid needing to specify the array size. 187 * overload in order to avoid needing to specify the array size.
186 */ 188 */
187 void RegisterHandlers(const FunctionInfo* functions, std::size_t n) { 189 template <typename T = Self>
190 void RegisterHandlers(const FunctionInfoTyped<T>* functions, std::size_t n) {
188 RegisterHandlersBase(functions, n); 191 RegisterHandlersBase(functions, n);
189 } 192 }
190 193
191 /// Registers handlers in the service. 194 /// Registers handlers in the service.
192 template <std::size_t N> 195 template <typename T = Self, std::size_t N>
193 void RegisterHandlersTipc(const FunctionInfo (&functions)[N]) { 196 void RegisterHandlersTipc(const FunctionInfoTyped<T> (&functions)[N]) {
194 RegisterHandlersTipc(functions, N); 197 RegisterHandlersTipc(functions, N);
195 } 198 }
196 199
@@ -198,7 +201,8 @@ protected:
198 * Registers handlers in the service. Usually prefer using the other RegisterHandlers 201 * Registers handlers in the service. Usually prefer using the other RegisterHandlers
199 * overload in order to avoid needing to specify the array size. 202 * overload in order to avoid needing to specify the array size.
200 */ 203 */
201 void RegisterHandlersTipc(const FunctionInfo* functions, std::size_t n) { 204 template <typename T = Self>
205 void RegisterHandlersTipc(const FunctionInfoTyped<T>* functions, std::size_t n) {
202 RegisterHandlersBaseTipc(functions, n); 206 RegisterHandlersBaseTipc(functions, n);
203 } 207 }
204 208