config: move to block/wakeup handler
This commit is contained in:
parent
99378b58db
commit
2f0a800ffd
112
config/config.c
112
config/config.c
|
@ -50,18 +50,27 @@
|
||||||
ret = BadValue; \
|
ret = BadValue; \
|
||||||
goto unwind; }
|
goto unwind; }
|
||||||
|
|
||||||
static DBusConnection *configConnection = NULL;
|
struct config_data {
|
||||||
static int configfd = -1;
|
int fd;
|
||||||
static char busobject[32] = { 0 };
|
DBusConnection *connection;
|
||||||
static char busname[64] = { 0 };
|
char busobject[32];
|
||||||
|
char busname[64];
|
||||||
|
};
|
||||||
|
|
||||||
void
|
static struct config_data *configData;
|
||||||
configDispatch()
|
|
||||||
|
static void
|
||||||
|
configWakeupHandler(pointer blockData, int err, pointer pReadMask)
|
||||||
{
|
{
|
||||||
if (!configConnection)
|
struct config_data *data = blockData;
|
||||||
return;
|
|
||||||
|
|
||||||
dbus_connection_read_write_dispatch(configConnection, 0);
|
if (data->connection && FD_ISSET(data->fd, (fd_set *) pReadMask))
|
||||||
|
dbus_connection_read_write_dispatch(data->connection, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
configBlockHandler(pointer data, struct timeval **tv, pointer pReadMask)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -249,68 +258,78 @@ configMessage(DBusConnection *connection, DBusMessage *message, void *closure)
|
||||||
void
|
void
|
||||||
configInitialise()
|
configInitialise()
|
||||||
{
|
{
|
||||||
DBusConnection *bus = NULL;
|
|
||||||
DBusError error;
|
DBusError error;
|
||||||
DBusObjectPathVTable vtable = { .message_function = configMessage };
|
DBusObjectPathVTable vtable = { .message_function = configMessage };
|
||||||
|
|
||||||
configConnection = NULL;
|
if (!configData)
|
||||||
|
configData = (struct config_data *) xcalloc(sizeof(struct config_data), 1);
|
||||||
|
if (!configData)
|
||||||
|
return;
|
||||||
|
|
||||||
dbus_error_init(&error);
|
dbus_error_init(&error);
|
||||||
bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
|
configData->connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
|
||||||
if (!bus || dbus_error_is_set(&error)) {
|
if (!configData->connection || dbus_error_is_set(&error)) {
|
||||||
ErrorF("[dbus] some kind of error occurred: %s (%s)\n", error.name,
|
ErrorF("[dbus] some kind of error occurred: %s (%s)\n", error.name,
|
||||||
error.message);
|
error.message);
|
||||||
dbus_error_free(&error);
|
dbus_error_free(&error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dbus_connection_get_unix_fd(bus, &configfd)) {
|
if (!dbus_connection_get_unix_fd(configData->connection, &configData->fd)) {
|
||||||
dbus_connection_unref(bus);
|
dbus_connection_unref(configData->connection);
|
||||||
ErrorF("[dbus] couldn't get fd for bus\n");
|
ErrorF("[dbus] couldn't get fd for bus\n");
|
||||||
dbus_error_free(&error);
|
dbus_error_free(&error);
|
||||||
configfd = -1;
|
configData->fd = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(busname, sizeof(busname), "org.x.config.display%d", atoi(display));
|
snprintf(configData->busname, sizeof(configData->busname),
|
||||||
if (!dbus_bus_request_name(bus, busname, 0, &error) ||
|
"org.x.config.display%d", atoi(display));
|
||||||
dbus_error_is_set(&error)) {
|
if (!dbus_bus_request_name(configData->connection, configData->busname,
|
||||||
|
0, &error) || dbus_error_is_set(&error)) {
|
||||||
ErrorF("[dbus] couldn't take over org.x.config: %s (%s)\n",
|
ErrorF("[dbus] couldn't take over org.x.config: %s (%s)\n",
|
||||||
error.name, error.message);
|
error.name, error.message);
|
||||||
dbus_error_free(&error);
|
dbus_error_free(&error);
|
||||||
dbus_connection_unref(bus);
|
dbus_connection_unref(configData->connection);
|
||||||
configfd = -1;
|
configData->fd = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* blocks until we get a reply. */
|
/* blocks until we get a reply. */
|
||||||
dbus_bus_add_match(bus, MATCH_RULE, &error);
|
dbus_bus_add_match(configData->connection, MATCH_RULE, &error);
|
||||||
if (dbus_error_is_set(&error)) {
|
if (dbus_error_is_set(&error)) {
|
||||||
ErrorF("[dbus] couldn't match X.Org rule: %s (%s)\n", error.name,
|
ErrorF("[dbus] couldn't match X.Org rule: %s (%s)\n", error.name,
|
||||||
error.message);
|
error.message);
|
||||||
dbus_error_free(&error);
|
dbus_error_free(&error);
|
||||||
dbus_bus_release_name(bus, busname, &error);
|
dbus_bus_release_name(configData->connection, configData->busname,
|
||||||
dbus_connection_unref(bus);
|
&error);
|
||||||
configfd = -1;
|
dbus_connection_unref(configData->connection);
|
||||||
|
configData->fd = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(busobject, sizeof(busobject), "/org/x/config/%d", atoi(display));
|
snprintf(configData->busobject, sizeof(configData->busobject),
|
||||||
if (!dbus_connection_register_object_path(bus, busobject, &vtable, bus)) {
|
"/org/x/config/%d", atoi(display));
|
||||||
|
if (!dbus_connection_register_object_path(configData->connection,
|
||||||
|
configData->busobject, &vtable,
|
||||||
|
configData->connection)) {
|
||||||
ErrorF("[dbus] couldn't register object path\n");
|
ErrorF("[dbus] couldn't register object path\n");
|
||||||
configfd = -1;
|
configData->fd = -1;
|
||||||
dbus_bus_release_name(bus, busname, &error);
|
dbus_bus_release_name(configData->connection, configData->busname,
|
||||||
dbus_bus_remove_match(bus, MATCH_RULE, &error);
|
&error);
|
||||||
dbus_connection_unref(bus);
|
dbus_bus_remove_match(configData->connection, MATCH_RULE, &error);
|
||||||
|
dbus_connection_unref(configData->connection);
|
||||||
dbus_error_free(&error);
|
dbus_error_free(&error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugF("[dbus] registered object path %s\n", busobject);
|
DebugF("[dbus] registered object path %s\n", configData->busobject);
|
||||||
|
|
||||||
dbus_error_free(&error);
|
dbus_error_free(&error);
|
||||||
configConnection = bus;
|
AddGeneralSocket(configData->fd);
|
||||||
AddGeneralSocket(configfd);
|
|
||||||
|
RegisterBlockAndWakeupHandlers(configBlockHandler, configWakeupHandler,
|
||||||
|
configData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -318,26 +337,25 @@ configFini()
|
||||||
{
|
{
|
||||||
DBusError error;
|
DBusError error;
|
||||||
|
|
||||||
if (configConnection) {
|
if (configData) {
|
||||||
dbus_error_init(&error);
|
dbus_error_init(&error);
|
||||||
dbus_connection_unregister_object_path(configConnection, busobject);
|
dbus_connection_unregister_object_path(configData->connection,
|
||||||
dbus_bus_remove_match(configConnection, MATCH_RULE, &error);
|
configData->busobject);
|
||||||
dbus_bus_release_name(configConnection, busname, &error);
|
dbus_bus_remove_match(configData->connection, MATCH_RULE, &error);
|
||||||
dbus_connection_unref(configConnection);
|
dbus_bus_release_name(configData->connection, configData->busname,
|
||||||
RemoveGeneralSocket(configfd);
|
&error);
|
||||||
configConnection = NULL;
|
dbus_connection_unref(configData->connection);
|
||||||
configfd = -1;
|
RemoveGeneralSocket(configData->fd);
|
||||||
|
RemoveBlockAndWakeupHandlers(configBlockHandler, configWakeupHandler,
|
||||||
|
configData);
|
||||||
|
xfree(configData);
|
||||||
|
configData = NULL;
|
||||||
dbus_error_free(&error);
|
dbus_error_free(&error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* !HAVE_DBUS */
|
#else /* !HAVE_DBUS */
|
||||||
|
|
||||||
void
|
|
||||||
configDispatch()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
configInitialise()
|
configInitialise()
|
||||||
{
|
{
|
||||||
|
|
|
@ -426,9 +426,6 @@ Dispatch(void)
|
||||||
|
|
||||||
nready = WaitForSomething(clientReady);
|
nready = WaitForSomething(clientReady);
|
||||||
|
|
||||||
/* this is an enormous hack and NEEDS TO GO AWAY. */
|
|
||||||
configDispatch();
|
|
||||||
|
|
||||||
#ifdef SMART_SCHEDULE
|
#ifdef SMART_SCHEDULE
|
||||||
if (nready && !SmartScheduleDisable)
|
if (nready && !SmartScheduleDisable)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user