request.h (5095B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2024 GNUnet e.V. 4 5 GNUnet is free software: you can redistribute it and/or modify it 6 under the terms of the GNU Affero General Public License as published 7 by the Free Software Foundation, either version 3 of the License, 8 or (at your option) any later version. 9 10 GNUnet is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Affero General Public License for more details. 14 15 You should have received a copy of the GNU Affero General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 SPDX-License-Identifier: AGPL3.0-or-later 19 */ 20 /* 21 * @author Tobias Frisch 22 * @file request.h 23 */ 24 25 #ifndef REQUEST_H_ 26 #define REQUEST_H_ 27 28 #include <gio/gio.h> 29 30 #ifndef MESSENGER_APPLICATION_NO_PORTAL 31 #include <libportal/portal.h> 32 #else 33 typedef enum XdpBackgroundFlags { 34 XDP_BACKGROUND_FLAG_ACTIVATABLE = 1, 35 XDP_BACKGROUND_FLAG_AUTOSTART = 2, 36 XDP_BACKGROUND_FLAG_NONE = 0, 37 } XdpBackgroundFlags; 38 39 typedef enum XdpCameraFlags { 40 XDP_CAMERA_FLAG_NONE = 0, 41 } XdpCameraFlags; 42 43 typedef enum XdpOutputType { 44 XDP_OUTPUT_NONE = 0, 45 XDP_OUTPUT_MONITOR = 1, 46 XDP_OUTPUT_WINDOW = 2, 47 XDP_OUTPUT_VIRTUAL = 4, 48 } XdpOutputType; 49 50 typedef enum XdpScreencastFlags { 51 XDP_SCREENCAST_FLAG_NONE = 0, 52 XDP_SCREENCAST_FLAG_MULTIPLE = 1, 53 } XdpScreencastFlags; 54 55 typedef enum XdpCursorMode { 56 XDP_CURSOR_MODE_HIDDEN = 1, 57 XDP_CURSOR_MODE_EMBEDDED = 2, 58 XDP_CURSOR_MODE_METADATA = 4, 59 } XdpCursorMode; 60 61 typedef enum XdpPersistMode { 62 XDP_PERSIST_MODE_NONE = 0, 63 XDP_PERSIST_MODE_TRANSIENT = 1, 64 XDP_PERSIST_MODE_PERSISTENT = 2, 65 } XdpPersistMode; 66 #endif 67 68 #include "application.h" 69 70 typedef void (*MESSENGER_RequestCallback)( 71 MESSENGER_Application *application, 72 gboolean success, 73 gboolean error, 74 gpointer user_data 75 ); 76 77 typedef struct MESSENGER_Request { 78 MESSENGER_Application *application; 79 MESSENGER_RequestCallback callback; 80 GCancellable *cancellable; 81 gpointer user_data; 82 83 #ifdef MESSENGER_APPLICATION_NO_PORTAL 84 guint timeout; 85 #endif 86 } MESSENGER_Request; 87 88 /** 89 * Creates a new request for the messsenger 90 * application for a certain permission. 91 * 92 * The request object will automatically be 93 * added to the list of the messenger application. 94 * 95 * @param application Messenger application 96 * @param cancellable Cancellable object (optional) 97 * @param user_data User data (optional) 98 * @return New request object 99 */ 100 MESSENGER_Request* 101 request_new(MESSENGER_Application *application, 102 MESSENGER_RequestCallback callback, 103 GCancellable *cancellable, 104 gpointer user_data); 105 106 /** 107 * Creates a new request for the messsenger 108 * application for a background permission. 109 * 110 * @param application Messenger application 111 * @param flags Background flags 112 * @param callback Callback 113 * @param user_data User data 114 * @return New background request object 115 */ 116 MESSENGER_Request* 117 request_new_background(MESSENGER_Application *application, 118 XdpBackgroundFlags flags, 119 MESSENGER_RequestCallback callback, 120 gpointer user_data); 121 122 /** 123 * Creates a new request for the messsenger 124 * application for a camera permission. 125 * 126 * @param application Messenger application 127 * @param flags Camera flags 128 * @param callback Callback 129 * @param user_data User data 130 * @return New camera request object 131 */ 132 MESSENGER_Request* 133 request_new_camera(MESSENGER_Application *application, 134 XdpCameraFlags flags, 135 MESSENGER_RequestCallback callback, 136 gpointer user_data); 137 138 /** 139 * Creates a new request for the messsenger 140 * application for a screencast permission. 141 * 142 * @param application Messenger application 143 * @param outputs Output types 144 * @param flags Screencast flags 145 * @param cursor_mode Cursor mode 146 * @param persist_mode Persist mode 147 * @param callback Callback 148 * @param user_data User data 149 * @return New camera request object 150 */ 151 MESSENGER_Request* 152 request_new_screencast(MESSENGER_Application *application, 153 XdpOutputType outputs, 154 XdpScreencastFlags flags, 155 XdpCursorMode cursor_mode, 156 XdpPersistMode persist_mode, 157 MESSENGER_RequestCallback callback, 158 gpointer user_data); 159 160 /** 161 * Cancel a request object if possible. 162 * 163 * @param request Request object 164 */ 165 void 166 request_cancel(MESSENGER_Request *request); 167 168 /** 169 * Cleanup a request object and its owned 170 * resources. 171 * 172 * @param request Request object 173 */ 174 void 175 request_cleanup(MESSENGER_Request *request); 176 177 /** 178 * Drop a request object from the messenger 179 * application list of requests. 180 * 181 * @param request Request object 182 */ 183 void 184 request_drop(MESSENGER_Request *request); 185 186 /** 187 * Delete a request object and its owned 188 * resources. 189 * 190 * @param request Request object 191 */ 192 void 193 request_delete(MESSENGER_Request *request); 194 195 #endif /* REQUEST_H_ */