Add session boilerplate

This commit is contained in:
Simon Ser 2019-12-09 12:55:12 +01:00
parent 03599925b6
commit a9e904a0c8
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
3 changed files with 51 additions and 0 deletions

View File

@ -8,6 +8,10 @@ struct xdpw_request {
sd_bus_slot *slot;
};
struct xdpw_session {
sd_bus_slot *slot;
};
enum {
PORTAL_RESPONSE_SUCCESS = 0,
PORTAL_RESPONSE_CANCELLED = 1,
@ -19,4 +23,7 @@ int init_screenshot(sd_bus *bus);
struct xdpw_request *request_create(sd_bus *bus, const char *object_path);
void request_destroy(struct xdpw_request *req);
struct xdpw_session *session_create(sd_bus *bus, const char *object_path);
void session_destroy(struct xdpw_session *req);
#endif

View File

@ -26,6 +26,7 @@ executable(
files([
'main.c',
'request.c',
'session.c',
'screenshot.c',
]),
dependencies: [

43
session.c Normal file
View File

@ -0,0 +1,43 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xdpw.h"
static const char interface_name[] = "org.freedesktop.impl.portal.Session";
static int method_close(sd_bus_message *msg, void *data,
sd_bus_error *ret_error) {
// struct xdpw_session *session = data;
// TODO
printf("Session.Close\n");
return 0;
}
static const sd_bus_vtable session_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_METHOD("Close", "", "", method_close, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END
};
struct xdpw_session *session_create(sd_bus *bus, const char *object_path) {
struct xdpw_session *req = calloc(1, sizeof(struct xdpw_session));
if (sd_bus_add_object_vtable(bus, &req->slot, object_path, interface_name,
session_vtable, NULL) < 0) {
free(req);
fprintf(stderr, "sd_bus_add_object_vtable failed: %s\n",
strerror(-errno));
return NULL;
}
return req;
}
void session_destroy(struct xdpw_session *req) {
if (req == NULL) {
return;
}
sd_bus_slot_unref(req->slot);
free(req);
}