Skip to content

Commit

Permalink
Updated to libmodule 4.0.0 API. Require it. Ready for clightd 3.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Jan 26, 2019
1 parent ba398b2 commit 0d2fa2f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Arch/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pkgdesc="Bus interface to change screen brightness and capture frames from webca
arch=('i686' 'x86_64')
url="https://github.com/FedeDP/${_gitname}"
license=('GPL')
depends=('systemd>=221' 'linux-api-headers' 'libx11' 'libxrandr' 'libxext' 'polkit' 'libxss' 'ddcutil' 'libmodule>=3.1.0')
depends=('systemd>=221' 'linux-api-headers' 'libx11' 'libxrandr' 'libxext' 'polkit' 'libxss' 'ddcutil' 'libmodule>=4.0.0')
makedepends=('git' 'cmake')
optdepends=('clight-git: user service to automagically change screen backlight matching ambient brightness.')
provides=('clightd')
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(clightd VERSION 3.1 LANGUAGES C)
project(clightd VERSION 3.2 LANGUAGES C)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

Expand All @@ -23,7 +23,7 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)

# Required dependencies
pkg_check_modules(REQ_LIBS REQUIRED libudev libmodule>=3.1.0 polkit-gobject-1)
pkg_check_modules(REQ_LIBS REQUIRED libudev libmodule>=4.0.0 polkit-gobject-1)
pkg_search_module(LOGIN_LIBS REQUIRED libelogind libsystemd>=221)
target_link_libraries(${PROJECT_NAME}
m
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## 3.2
- [x] Port to libmodule 4.0.0 (do not require it though)
- [x] Port to libmodule 4.0.0

## 3.3
- [ ] add support for GetSensorData android app
Expand Down
23 changes: 8 additions & 15 deletions src/modules/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ typedef struct {
double verse;
} smooth_client;

static map_ret_code destroy_client(void *userdata, void *client);
static int dtor_client(void *client);
static int method_setallbrightness(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
static int method_getallbrightness(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
static int method_raiseallbrightness(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
Expand Down Expand Up @@ -132,6 +132,7 @@ static bool evaluate(void) {

static void init(void) {
running_clients = map_new();
map_set_dtor(running_clients, dtor_client);
int r = sd_bus_add_object_vtable(bus,
NULL,
object_path,
Expand Down Expand Up @@ -165,22 +166,17 @@ static void receive(const msg_t *msg, const void *userdata) {
timerfd_settime(sc->smooth_fd, 0, &timerValue, NULL);
} else {
m_log("Reached target backlight: %s%.2lf.\n", sc->verse > 0 ? "+" : (sc->verse < 0 ? "-" : ""), sc->target_pct);
destroy_client(NULL, sc);
map_remove(running_clients, sc->d.sn);
}
}
}

static void destroy(void) {
map_iterate(running_clients, destroy_client, NULL);
map_free(running_clients);
}

static map_ret_code destroy_client(void *userdata, void *client) {
static int dtor_client(void *client) {
smooth_client *sc = (smooth_client *)client;

/* Deregister this sc from running map */
map_remove(running_clients, sc->d.sn);

/* Free all resources */
m_deregister_fd(sc->smooth_fd); // this will automatically close it!
free(sc->d.sn);
Expand Down Expand Up @@ -228,11 +224,7 @@ static int add_backlight_sn(double target_pct, int is_smooth, double smooth_step
reset_backlight_struct(sc, target_pct, is_smooth, smooth_step, smooth_wait, verse);
sc->d.sn = strdup(sn);
sc->d.reached_target = false;
#if MODULE_VERSION_MAJ == 3
map_put(running_clients, sc->d.sn, sc, false);
#else
map_put(running_clients, sc->d.sn, sc, false, false);
#endif
map_put(running_clients, sc->d.sn, sc, false, true);
}

if (dev) {
Expand Down Expand Up @@ -274,8 +266,9 @@ static int method_setallbrightness(sd_bus_message *m, void *userdata, sd_bus_err
verse = *((int *)userdata);
}

/* stop previously running clients and remove them from map */
map_iterate(running_clients, destroy_client, NULL);
/* Clear map */
map_clear(running_clients);
map_set_dtor(running_clients, dtor_client);
add_backlight_sn(target_pct, is_smooth, smooth_step, smooth_wait, verse, backlight_interface, true);
DDCUTIL_LOOP({
add_backlight_sn(target_pct, is_smooth, smooth_step, smooth_wait, verse, dinfo->sn, false);
Expand Down
12 changes: 4 additions & 8 deletions src/modules/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef struct {
sd_bus_slot *slot; // vtable's slot
} idle_client_t;

static map_ret_code destroy_clients(void *userdata, void *client);
static map_ret_code dtor_client(void *client);
static map_ret_code leave_idle(void *userdata, void *client);
static time_t get_idle_time(const idle_client_t *c);
static map_ret_code find_free_client(void *out, void *client);
Expand Down Expand Up @@ -79,6 +79,7 @@ static bool evaluate(void) {

static void init(void) {
clients = map_new();
map_set_dtor(clients, dtor_client);
int r = sd_bus_add_object_vtable(bus,
NULL,
object_path,
Expand Down Expand Up @@ -127,7 +128,6 @@ static void receive(const msg_t *msg, const void *userdata) {
}

static void destroy(void) {
map_iterate(clients, destroy_clients, NULL);
map_free(clients);
}

Expand All @@ -143,7 +143,7 @@ static map_ret_code leave_idle(void *userdata, void *client) {
return MAP_OK;
}

static map_ret_code destroy_clients(void *userdata, void *client) {
static map_ret_code dtor_client(void *client) {
idle_client_t *c = (idle_client_t *)client;
if (c->in_use) {
destroy_client(c);
Expand Down Expand Up @@ -224,11 +224,7 @@ static int method_get_client(sd_bus_message *m, void *userdata, sd_bus_error *re
m_register_fd(c->fd, true, c);
c->sender = strdup(sd_bus_message_get_sender(m));
snprintf(c->path, sizeof(c->path) - 1, "%s/Client%u", object_path, c->id);
#if MODULE_VERSION_MAJ == 3
map_put(clients, c->path, c, true); // store client in hashmap
#else
map_put(clients, c->path, c, true, false);
#endif
map_put(clients, c->path, c, true, true);
sd_bus_add_object_vtable(bus,
&c->slot,
c->path,
Expand Down

0 comments on commit 0d2fa2f

Please sign in to comment.