libctru  v2.4.1
srv.h
Go to the documentation of this file.
1 /**
2  * @file srv.h
3  * @brief Service API.
4  */
5 #pragma once
6 
7 /// Initializes the service API.
8 Result srvInit(void);
9 
10 /// Exits the service API.
11 void srvExit(void);
12 
13 /**
14  * @brief Makes srvGetServiceHandle non-blocking for the current thread (or blocking, the default), in case of unavailable (full) requested services.
15  * @param blocking Whether srvGetServiceHandle should be non-blocking.
16  * srvGetServiceHandle will always block if the service hasn't been registered yet,
17  * use srvIsServiceRegistered to check whether that is the case or not.
18  */
19 void srvSetBlockingPolicy(bool nonBlocking);
20 
21 /**
22  * @brief Gets the current service API session handle.
23  * @return The current service API session handle.
24  */
26 
27 /**
28  * @brief Retrieves a service handle, retrieving from the environment handle list if possible.
29  * @param out Pointer to write the handle to.
30  * @param name Name of the service.
31  * @return 0 if no error occured,
32  * 0xD8E06406 if the caller has no right to access the service,
33  * 0xD0401834 if the requested service port is full and srvGetServiceHandle is non-blocking (see @ref srvSetBlockingPolicy).
34  */
35 Result srvGetServiceHandle(Handle* out, const char* name);
36 
37 /// Registers the current process as a client to the service API.
39 
40 /**
41  * @brief Enables service notificatios, returning a notification semaphore.
42  * @param semaphoreOut Pointer to output the notification semaphore to.
43  */
45 
46 /**
47  * @brief Registers the current process as a service.
48  * @param out Pointer to write the service handle to.
49  * @param name Name of the service.
50  * @param maxSessions Maximum number of sessions the service can handle.
51  */
52 Result srvRegisterService(Handle* out, const char* name, int maxSessions);
53 
54 /**
55  * @brief Unregisters the current process as a service.
56  * @param name Name of the service.
57  */
58 Result srvUnregisterService(const char* name);
59 
60 /**
61  * @brief Retrieves a service handle.
62  * @param out Pointer to output the handle to.
63  * @param name Name of the service.
64  * * @return 0 if no error occured,
65  * 0xD8E06406 if the caller has no right to access the service,
66  * 0xD0401834 if the requested service port is full and srvGetServiceHandle is non-blocking (see @ref srvSetBlockingPolicy).
67  */
68 Result srvGetServiceHandleDirect(Handle* out, const char* name);
69 
70 /**
71  * @brief Registers a port.
72  * @param name Name of the port.
73  * @param clientHandle Client handle of the port.
74  */
75 Result srvRegisterPort(const char* name, Handle clientHandle);
76 
77 /**
78  * @brief Unregisters a port.
79  * @param name Name of the port.
80  */
81 Result srvUnregisterPort(const char* name);
82 
83 /**
84  * @brief Retrieves a port handle.
85  * @param out Pointer to output the handle to.
86  * @param name Name of the port.
87  */
88 Result srvGetPort(Handle* out, const char* name);
89 
90 /**
91  * @brief Waits for a port to be registered.
92  * @param name Name of the port to wait for registration.
93  */
94 Result srvWaitForPortRegistered(const char* name);
95 
96 /**
97  * @brief Subscribes to a notification.
98  * @param notificationId ID of the notification.
99  */
100 Result srvSubscribe(u32 notificationId);
101 
102 /**
103  * @brief Unsubscribes from a notification.
104  * @param notificationId ID of the notification.
105  */
106 Result srvUnsubscribe(u32 notificationId);
107 
108 /**
109  * @brief Receives a notification.
110  * @param notificationIdOut Pointer to output the ID of the received notification to.
111  */
112 Result srvReceiveNotification(u32* notificationIdOut);
113 
114 /**
115  * @brief Publishes a notification to subscribers.
116  * @param notificationId ID of the notification.
117  * @param flags Flags to publish with. (bit 0 = only fire if not fired, bit 1 = do not report an error if there are more than 16 pending notifications)
118  */
119 Result srvPublishToSubscriber(u32 notificationId, u32 flags);
120 
121 /**
122  * @brief Publishes a notification to subscribers and retrieves a list of all processes that were notified.
123  * @param processIdCountOut Pointer to output the number of process IDs to.
124  * @param processIdsOut Pointer to output the process IDs to. Should have size "60 * sizeof(u32)".
125  * @param notificationId ID of the notification.
126  */
127 Result srvPublishAndGetSubscriber(u32* processIdCountOut, u32* processIdsOut, u32 notificationId);
128 
129 /**
130  * @brief Checks whether a service is registered.
131  * @param registeredOut Pointer to output the registration status to.
132  * @param name Name of the service to check.
133  */
134 Result srvIsServiceRegistered(bool* registeredOut, const char* name);
135 
136 /**
137  * @brief Checks whether a port is registered.
138  * @param registeredOut Pointer to output the registration status to.
139  * @param name Name of the port to check.
140  */
141 Result srvIsPortRegistered(bool* registeredOut, const char* name);
Result srvSubscribe(u32 notificationId)
Subscribes to a notification.
Result srvRegisterPort(const char *name, Handle clientHandle)
Registers a port.
Result srvPublishAndGetSubscriber(u32 *processIdCountOut, u32 *processIdsOut, u32 notificationId)
Publishes a notification to subscribers and retrieves a list of all processes that were notified.
Result srvGetServiceHandleDirect(Handle *out, const char *name)
Retrieves a service handle.
void srvExit(void)
Exits the service API.
Result srvEnableNotification(Handle *semaphoreOut)
Enables service notificatios, returning a notification semaphore.
Result srvUnregisterService(const char *name)
Unregisters the current process as a service.
Result srvIsServiceRegistered(bool *registeredOut, const char *name)
Checks whether a service is registered.
Result srvGetServiceHandle(Handle *out, const char *name)
Retrieves a service handle, retrieving from the environment handle list if possible.
Result srvUnregisterPort(const char *name)
Unregisters a port.
Result srvIsPortRegistered(bool *registeredOut, const char *name)
Checks whether a port is registered.
Result srvPublishToSubscriber(u32 notificationId, u32 flags)
Publishes a notification to subscribers.
void srvSetBlockingPolicy(bool nonBlocking)
Makes srvGetServiceHandle non-blocking for the current thread (or blocking, the default),...
Handle * srvGetSessionHandle(void)
Gets the current service API session handle.
Result srvInit(void)
Initializes the service API.
Result srvWaitForPortRegistered(const char *name)
Waits for a port to be registered.
Result srvUnsubscribe(u32 notificationId)
Unsubscribes from a notification.
Result srvRegisterService(Handle *out, const char *name, int maxSessions)
Registers the current process as a service.
Result srvGetPort(Handle *out, const char *name)
Retrieves a port handle.
Result srvRegisterClient(void)
Registers the current process as a client to the service API.
Result srvReceiveNotification(u32 *notificationIdOut)
Receives a notification.
u32 Handle
Resource handle.
Definition: types.h:41
s32 Result
Function result.
Definition: types.h:42
uint32_t u32
32-bit unsigned integer
Definition: types.h:23