meta: restructure project for a modular architechture for more interfaces
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I16f88f649bddad572e0d44cee7e0edec6a6a6964
This commit is contained in:
parent
c89f4b5d02
commit
087f28d726
22 changed files with 2494 additions and 0 deletions
103
include/inhibit-interface.h
Normal file
103
include/inhibit-interface.h
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#ifndef INHIBIT_INTERFACE_H
|
||||
#define INHIBIT_INTERFACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_INTERFACES 16
|
||||
#define MAX_INHIBITS_PER_INTERFACE 64
|
||||
#define INHIBIT_ID_LEN 64
|
||||
|
||||
typedef enum {
|
||||
INHIBIT_TYPE_SCREENSAVER = 1 << 0,
|
||||
INHIBIT_TYPE_SUSPEND = 1 << 1,
|
||||
INHIBIT_TYPE_IDLE = 1 << 2,
|
||||
INHIBIT_TYPE_ALL =
|
||||
INHIBIT_TYPE_SCREENSAVER | INHIBIT_TYPE_SUSPEND | INHIBIT_TYPE_IDLE
|
||||
} InhibitType;
|
||||
|
||||
typedef enum {
|
||||
INHIBIT_FLAG_NONE = 0,
|
||||
INHIBIT_FLAG_FORWARDED = 1 << 0,
|
||||
INHIBIT_FLAG_LOOP_DETECTED = 1 << 1
|
||||
} InhibitFlags;
|
||||
|
||||
typedef struct {
|
||||
char id[INHIBIT_ID_LEN];
|
||||
InhibitType type;
|
||||
char app_name[256];
|
||||
char reason[1024];
|
||||
InhibitFlags flags;
|
||||
uint64_t cookie;
|
||||
void *interface_data;
|
||||
} InhibitEntry;
|
||||
|
||||
typedef struct {
|
||||
InhibitEntry entry;
|
||||
int interface_idx;
|
||||
char forwarded_to[MAX_INTERFACES][INHIBIT_ID_LEN];
|
||||
int num_forwarded;
|
||||
} TrackedInhibit;
|
||||
|
||||
typedef struct InhibitInterface InhibitInterface;
|
||||
|
||||
typedef void (*InhibitEventCallback)(InhibitInterface *source,
|
||||
const InhibitEntry *entry, int is_inhibit);
|
||||
|
||||
struct InhibitInterface {
|
||||
const char *name;
|
||||
int enabled;
|
||||
|
||||
int (*init)(InhibitInterface *iface);
|
||||
void (*cleanup)(InhibitInterface *iface);
|
||||
|
||||
int (*inhibit)(InhibitInterface *iface, InhibitType type,
|
||||
const char *app_name, const char *reason,
|
||||
InhibitEntry *out_entry);
|
||||
|
||||
int (*uninhibit)(InhibitInterface *iface, const InhibitEntry *entry);
|
||||
|
||||
int (*poll)(InhibitInterface *iface);
|
||||
|
||||
void (*set_callback)(InhibitInterface *iface, InhibitEventCallback cb);
|
||||
|
||||
void *private_data;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
InhibitInterface *interfaces[MAX_INTERFACES];
|
||||
int num_interfaces;
|
||||
TrackedInhibit inhibits[MAX_INTERFACES * MAX_INHIBITS_PER_INTERFACE];
|
||||
int num_inhibits;
|
||||
InhibitEventCallback event_callback;
|
||||
} InhibitManager;
|
||||
|
||||
int inhibit_manager_init(InhibitManager *mgr);
|
||||
void inhibit_manager_cleanup(InhibitManager *mgr);
|
||||
int inhibit_manager_register(InhibitManager *mgr, InhibitInterface *iface);
|
||||
void inhibit_manager_set_callback(InhibitManager *mgr, InhibitEventCallback cb);
|
||||
|
||||
int inhibit_manager_forward_inhibit(InhibitManager *mgr,
|
||||
InhibitInterface *source,
|
||||
const InhibitEntry *entry);
|
||||
|
||||
int inhibit_manager_forward_uninhibit(InhibitManager *mgr,
|
||||
InhibitInterface *source,
|
||||
const InhibitEntry *entry);
|
||||
|
||||
TrackedInhibit *inhibit_manager_find(InhibitManager *mgr,
|
||||
InhibitInterface *source, const char *id);
|
||||
|
||||
int inhibit_manager_add_tracked(InhibitManager *mgr, InhibitInterface *source,
|
||||
const InhibitEntry *entry);
|
||||
|
||||
void inhibit_manager_remove_tracked(InhibitManager *mgr,
|
||||
InhibitInterface *source, const char *id);
|
||||
|
||||
void inhibit_manager_poll_all(InhibitManager *mgr);
|
||||
|
||||
const char *inhibit_type_to_string(InhibitType type);
|
||||
InhibitType inhibit_type_from_string(const char *str);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue