test-bus-chat.c revision 89ffcd2ad5bf87866314e96c4179ba622851cd6e
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <assert.h>
#include <stdlib.h>
#include <pthread.h>
#include "log.h"
#include "util.h"
#include "sd-bus.h"
#include "bus-message.h"
int r;
r = sd_bus_open_user(&bus);
if (r < 0) {
goto fail;
}
if (r < 0) {
goto fail;
}
return 0;
fail:
if (bus)
return r;
}
static void* server(void *p) {
int r;
for (;;) {
r = sd_bus_process(bus, &m);
if (r < 0) {
goto fail;
}
if (r == 0) {
if (r < 0) {
goto fail;
}
continue;
}
/* bus_message_dump(m); */
/* sd_bus_message_rewind(m, true); */
const char *hello;
if (r < 0) {
goto fail;
}
if (r < 0) {
goto fail;
}
if (!lowercase) {
r = log_oom();
goto fail;
}
if (r < 0) {
goto fail;
}
break;
const sd_bus_error e = SD_BUS_ERROR_INIT_CONST("org.freedesktop.DBus.Error.UnknownMethod", "Unknown method.");
if (r < 0) {
goto fail;
}
}
if (reply) {
if (r < 0) {
goto fail;
}
}
}
r = 0;
fail:
if (bus)
return INT_TO_PTR(r);
}
static int client(void) {
const char *hello;
int r;
r = sd_bus_open_user(&bus);
if (r < 0) {
goto finish;
}
bus,
"/",
"LowerCase",
&m);
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
if (r < 0) {
goto finish;
}
r = 0;
if (bus) {
bus,
"/",
"Exit",
&q);
if (r < 0) {
goto finish;
}
}
return r;
}
pthread_t t;
void *p;
int q, r;
r = server_init(&bus);
if (r < 0)
return EXIT_FAILURE;
if (r != 0) {
return EXIT_FAILURE;
}
r = client();
q = pthread_join(t, &p);
if (q != 0)
return EXIT_FAILURE;
if (r < 0)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}