From 06a3b13134e29b75971970aa45ba14576a4f6ced Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 10 Aug 2009 16:58:31 -0400 Subject: Change services identification mechanism Let services identify themselves voiluntarily as the first operation instead of polling from the monitor. Also consolidate some common functions and make them available as monitor helpers. --- server/providers/data_provider_be.c | 92 +++++-------------------------------- 1 file changed, 11 insertions(+), 81 deletions(-) (limited to 'server/providers/data_provider_be.c') diff --git a/server/providers/data_provider_be.c b/server/providers/data_provider_be.c index 49885edc..46f8db51 100644 --- a/server/providers/data_provider_be.c +++ b/server/providers/data_provider_be.c @@ -34,11 +34,6 @@ #include #include -/* Needed for res_init() */ -#include -#include -#include - #include "popt.h" #include "util/util.h" #include "confdb/confdb.h" @@ -53,14 +48,9 @@ #define BE_CONF_ENTRY "config/domains/%s" -static int service_identity(DBusMessage *message, struct sbus_connection *conn); -static int service_pong(DBusMessage *message, struct sbus_connection *conn); -static int service_res_init(DBusMessage *message, struct sbus_connection *conn); - struct sbus_method monitor_be_methods[] = { - { MON_CLI_METHOD_IDENTITY, service_identity }, - { MON_CLI_METHOD_PING, service_pong }, - { MON_CLI_METHOD_RES_INIT, service_res_init }, + { MON_CLI_METHOD_PING, monitor_common_pong }, + { MON_CLI_METHOD_RES_INIT, monitor_common_res_init }, { NULL, NULL } }; @@ -102,75 +92,6 @@ static struct bet_data bet_data[] = { {BET_MAX, NULL, NULL} }; - - -static int service_identity(DBusMessage *message, struct sbus_connection *conn) -{ - dbus_uint16_t version = DATA_PROVIDER_VERSION; - struct be_ctx *ctx; - DBusMessage *reply; - dbus_bool_t ret; - void *user_data; - - user_data = sbus_conn_get_private_data(conn); - if (!user_data) return EINVAL; - ctx = talloc_get_type(user_data, struct be_ctx); - if (!ctx) return EINVAL; - - DEBUG(4,("Sending ID reply: (%s,%d)\n", ctx->identity, version)); - - reply = dbus_message_new_method_return(message); - if (!reply) return ENOMEM; - - ret = dbus_message_append_args(reply, - DBUS_TYPE_STRING, &ctx->identity, - DBUS_TYPE_UINT16, &version, - DBUS_TYPE_INVALID); - if (!ret) { - dbus_message_unref(reply); - return EIO; - } - - /* send reply back */ - sbus_conn_send_reply(conn, reply); - dbus_message_unref(reply); - - return EOK; -} - -static int service_pong(DBusMessage *message, struct sbus_connection *conn) -{ - DBusMessage *reply; - dbus_bool_t ret; - - reply = dbus_message_new_method_return(message); - if (!reply) return ENOMEM; - - ret = dbus_message_append_args(reply, DBUS_TYPE_INVALID); - if (!ret) { - dbus_message_unref(reply); - return EIO; - } - - /* send reply back */ - sbus_conn_send_reply(conn, reply); - dbus_message_unref(reply); - - return EOK; -} - -static int service_res_init(DBusMessage *message, struct sbus_connection *conn) -{ - int ret; - - ret = res_init(); - if(ret != 0) { - return EIO; - } - - return service_pong(message, conn); -} - static int be_identity(DBusMessage *message, struct sbus_connection *conn) { dbus_uint16_t version = DATA_PROVIDER_VERSION; @@ -704,6 +625,15 @@ static int mon_cli_init(struct be_ctx *ctx) return ret; } + /* Identify ourselves to the monitor */ + ret = monitor_common_send_id(ctx->mon_conn, + ctx->identity, + DATA_PROVIDER_VERSION); + if (ret != EOK) { + DEBUG(0, ("Failed to identify to the monitor!\n")); + return ret; + } + return EOK; } -- cgit