plugins/resource-native/libmurphy-resource/attribute.c \
plugins/resource-native/libmurphy-resource/rset.c \
plugins/resource-native/libmurphy-resource/string_array.c \
- plugins/resource-native/libmurphy-resource/message.c
+ plugins/resource-native/libmurphy-resource/message.c \
+ plugins/resource-native/libmurphy-resource/resource-log.c
libmurphy_resource_la_CFLAGS = \
$(AM_CFLAGS)
goto failed;
if (status != 0)
- mrp_log_error("Resource query failed (%u): %s", status, strerror(status));
+ mrp_res_error("Resource query failed (%u): %s", status, strerror(status));
else {
dim = 0;
goto failed;
if (!(rdef[dim].attrs = mrp_attribute_array_dup(n_attrs, attrs))) {
- mrp_log_error("failed to duplicate attributes");
+ mrp_res_error("failed to duplicate attributes");
goto failed;
}
return arr;
failed:
- mrp_log_error("malformed reply to resource query");
+ mrp_res_error("malformed reply to resource query");
free_resource_set(arr);
return NULL;
if (!fetch_status(msg, pcursor, &status) || (status == 0 &&
!fetch_mrp_str_array(msg, pcursor, RESPROTO_CLASS_NAME, &arr)))
{
- mrp_log_error("ignoring malformed response to class query");
+ mrp_res_error("ignoring malformed response to class query");
return NULL;
}
if (status) {
- mrp_log_error("class query failed with error code %u", status);
+ mrp_res_error("class query failed with error code %u", status);
mrp_res_free_string_array(arr);
return NULL;
}
if (!fetch_status(msg, pcursor, &status) || (status == 0 &&
!fetch_resource_set_id(msg, pcursor, &rset_id)))
{
- mrp_log_error("ignoring malformed response to resource set creation");
+ mrp_res_error("ignoring malformed response to resource set creation");
goto error;
}
if (status) {
- mrp_log_error("creation of resource set failed. error code %u",status);
+ mrp_res_error("creation of resource set failed. error code %u",status);
goto error;
}
if (!fetch_resource_set_id(msg, pcursor, &rset_id) ||
!fetch_status(msg, pcursor, &status))
{
- mrp_log_error("ignoring malformed response to resource set");
+ mrp_res_error("ignoring malformed response to resource set");
goto error;
}
if (status) {
- mrp_log_error("acquiring of resource set failed. error code %u",status);
+ mrp_res_error("acquiring of resource set failed. error code %u",status);
goto error;
}
rset = mrp_htbl_lookup(cx->priv->rset_mapping, u_to_p(rset_id));
if (!rset) {
- mrp_log_error("no rset found!");
+ mrp_res_error("no rset found!");
goto error;
}
#ifndef __MURPHY_RESOURCE_API_H__
#define __MURPHY_RESOURCE_API_H__
+#include <stdarg.h>
+
#include <murphy/common.h>
typedef struct mrp_res_context_private_s mrp_res_context_private_t;
*/
void mrp_res_free_string_array(mrp_res_string_array_t *arr);
+
+/**
+ * Prototype for an external logger.
+ *
+ * @param level log level.
+ * @param file source file (__FILE__) he log message originated from.
+ * @param line source line (__LINE__) the log message originated from.
+ * @param func function (__func__) the log message originated from.
+ *
+ * @return none.
+ */
+typedef void (*mrp_res_logger_t) (mrp_log_level_t level, const char *file,
+ int line, const char *func,
+ const char *format, va_list args);
+
+/**
+ * Set an external logger for the resource library. All log messages
+ * produced by the library will be handed to this function. If you
+ * want to suppress all logs by the library, set the logger to NULL.
+ *
+ * @param logger the logger function to use.
+ *
+ * @return pointer to the previously active logger function.
+ */
+
+mrp_res_logger_t mrp_res_set_logger(mrp_res_logger_t logger);
+
+
#endif /* __MURPHY_RESOURCE_API_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2012, 2013 Intel Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdarg.h>
+#include <murphy/common/log.h>
+
+#include "resource-api.h"
+#include "resource-private.h"
+
+static void default_logger(mrp_log_level_t level, const char *file,
+ int line, const char *func,
+ const char *format, va_list args)
+{
+ va_list ap;
+
+ va_copy(ap, args);
+ mrp_log_msgv(level, file, line, func, format, ap);
+ va_end(ap);
+}
+
+
+static mrp_res_logger_t __res_logger = default_logger;
+
+mrp_res_logger_t mrp_res_set_logger(mrp_res_logger_t logger)
+{
+ mrp_res_logger_t old = __res_logger;
+
+ __res_logger = logger;
+
+ return old;
+}
+
+
+void mrp_res_log_msg(mrp_log_level_t level, const char *file,
+ int line, const char *func, const char *format, ...)
+{
+ va_list ap;
+
+ if (__res_logger != NULL) {
+ va_start(ap, format);
+ __res_logger(level, file, line, func, format, ap);
+ va_end(ap);
+ }
+}
#ifndef __MURPHY_RESOURCE_API_PRIVATE_H__
#define __MURPHY_RESOURCE_API_PRIVATE_H__
+#include <stdarg.h>
+
+#include <murphy/common/log.h>
+
#include "resource-api.h"
typedef struct {
uint32_t p_to_u(const void *p);
void *u_to_p(uint32_t u);
+/*
+ * logging macros
+ */
+
+#define __LOCATION__ __FILE__,__LINE__,__FUNCTION__
+
+#define mrp_res_info(format, args...) \
+ mrp_res_log_msg(MRP_LOG_INFO, __LOCATION__, format, ## args)
+
+#define mrp_res_warning(format, args...) \
+ mrp_res_log_msg(MRP_LOG_WARNING, __LOCATION__, format, ## args)
+
+#define mrp_res_error(format, args...) \
+ mrp_res_log_msg(MRP_LOG_ERROR, __LOCATION__, format, ## args)
+
+void mrp_res_log_msg(mrp_log_level_t level, const char *file, int line,
+ const char *func, const char *format, ...);
#endif /* __MURPHY_RESOURCE_API_PRIVATE_H__ */
uint32_t i;
mrp_res_resource_set_t *rset;
- printf("Resource event (request no %u):\n", seqno);
+ mrp_res_info("Resource event (request no %u):", seqno);
if (!fetch_resource_set_id(msg, pcursor, &rset_id) ||
!fetch_resource_set_state(msg, pcursor, &state) ||
!fetch_resource_set_mask(msg, pcursor, 0, &grant) ||
!fetch_resource_set_mask(msg, pcursor, 1, &advice)) {
- mrp_log_error("failed to fetch data from message");
+ mrp_res_error("failed to fetch data from message");
goto malformed;
}
rset = mrp_htbl_lookup(cx->priv->rset_mapping, u_to_p(rset_id));
if (!rset) {
- mrp_log_error("resource event outside the resource set lifecycle");
+ mrp_res_error("resource event outside the resource set lifecycle");
goto malformed;
}
if ((tag != RESPROTO_RESOURCE_ID || type != MRP_MSG_FIELD_UINT32) ||
!fetch_resource_name(msg, pcursor, &resnam)) {
- mrp_log_error("failed to read resource from message");
+ mrp_res_error("failed to read resource from message");
goto malformed;
}
res = get_resource_by_name(rset, resnam);
if (!res) {
- mrp_log_error("resource doesn't exist in resource set");
+ mrp_res_error("resource doesn't exist in resource set");
goto malformed;
}
resid = value.u32;
- mrp_log_info("data for '%s': %d", res->name, resid);
+ mrp_res_info("data for '%s': %d", res->name, resid);
n_attrs = fetch_attribute_array(msg, pcursor, ATTRIBUTE_MAX + 1, attrs);
if (n_attrs < 0) {
- mrp_log_error("failed to read attributes from message");
+ mrp_res_error("failed to read attributes from message");
goto malformed;
}
#endif
}
- mrp_log_info("advice = 0x%08x, grant = 0x%08x, mandatory = 0x%08x, all = 0x%08x",
+ mrp_res_info("advice = 0x%08x, grant = 0x%08x, mandatory = 0x%08x, all = 0x%08x",
advice, grant, mandatory, all);
if (grant) {
return;
malformed:
- mrp_log_error("ignoring malformed resource event");
+ mrp_res_error("ignoring malformed resource event");
}
fetch_request(msg, &cursor, &req) < 0)
goto error;
- mrp_log_info("received message %d for %p", req, cx);
+ mrp_res_info("received message %d for %p", req, cx);
err = MRP_RES_ERROR_MALFORMED;
switch (req) {
case RESPROTO_QUERY_RESOURCES:
- mrp_log_info("received QUERY_RESOURCES response");
+ mrp_res_info("received QUERY_RESOURCES response");
cx->priv->master_resource_set =
resource_query_response(msg, &cursor);
break;
case RESPROTO_QUERY_CLASSES:
- mrp_log_info("received QUERY_CLASSES response");
+ mrp_res_info("received QUERY_CLASSES response");
cx->priv->master_classes = class_query_response(msg, &cursor);
if (!cx->priv->master_classes)
mrp_res_resource_set_t *rset = NULL;
mrp_list_hook_t *p, *n;
- mrp_log_info("received CREATE_RESOURCE_SET response");
+ mrp_res_info("received CREATE_RESOURCE_SET response");
/* get the correct resource set from the pending_sets list */
{
mrp_res_resource_set_t *rset;
- mrp_log_info("received ACQUIRE_RESOURCE_SET response");
+ mrp_res_info("received ACQUIRE_RESOURCE_SET response");
rset = acquire_resource_set_response(msg, cx, &cursor);
case RESPROTO_RELEASE_RESOURCE_SET:
{
mrp_res_resource_set_t *rset;
- mrp_log_info("received RELEASE_RESOURCE_SET response");
+ mrp_res_info("received RELEASE_RESOURCE_SET response");
rset = acquire_resource_set_response(msg, cx, &cursor);
break;
}
case RESPROTO_RESOURCES_EVENT:
- mrp_log_info("received RESOURCES_EVENT response");
+ mrp_res_info("received RESOURCES_EVENT response");
resource_event(msg, cx, seqno, &cursor);
break;
case RESPROTO_DESTROY_RESOURCE_SET:
- mrp_log_info("received DESTROY_RESOURCE_SET response");
+ mrp_res_info("received DESTROY_RESOURCE_SET response");
/* TODO? */
break;
default:
return;
error:
- mrp_log_error("error processing a message from the server");
+ mrp_res_error("error processing a message from the server");
cx->priv->cb(cx, err, cx->priv->user_data);
}
MRP_UNUSED(transp);
MRP_UNUSED(error);
- mrp_log_error("connection closed for %p", cx);
+ mrp_res_error("connection closed for %p", cx);
cx->priv->connected = FALSE;
if (cx->state == MRP_RES_CONNECTED) {
static void htbl_free_rset_mapping(void *key, void *object)
{
#if 0
- mrp_log_info("> htbl_free_rset_mapping(%d, %p)", p_to_u(key), object);
+ mrp_res_info("> htbl_free_rset_mapping(%d, %p)", p_to_u(key), object);
#else
MRP_UNUSED(key);
#endif
error:
- mrp_log_error("error connecting to server");
+ mrp_res_error("error connecting to server");
destroy_context(cx);
return NULL;
void print_resource(mrp_res_resource_t *res)
{
- mrp_log_info(" resource '%s' -> '%s' : %smandatory, %sshared",
+ mrp_res_info(" resource '%s' -> '%s' : %smandatory, %sshared",
res->name, state_to_str(res->state),
res->priv->mandatory ? " " : "not ",
res->priv->shared ? "" : "not ");
uint32_t i;
mrp_res_resource_t *res;
- mrp_log_info("Resource set %i/%i (%s) -> '%s':",
+ mrp_res_info("Resource set %i/%i (%s) -> '%s':",
rset->priv->id, rset->priv->internal_id,
rset->application_class, state_to_str(rset->state));
rset->priv->internal_ref_count--;
if (rset->priv->internal_ref_count == 0) {
-
mrp_log_info("delete the server resource set now");
destroy_resource_set_request(cx, rset);
return copy;
error:
- mrp_log_error("failed to copy resource");
+ mrp_res_error("failed to copy resource");
if (copy) {
mrp_free((void *) copy->name);
return res;
error:
- mrp_log_error("error creating a resource");
+ mrp_res_error("mrp_res_create_resource error");
free_resource(res);
return NULL;
return release_resource_set_request(cx, internal_set);
error:
- mrp_log_error("error releasing a resource set");
+ mrp_res_error("mrp_release_resources error");
+
return -1;
}
mrp_res_resource_set_t *rset;
if (!cx->priv->connected) {
- mrp_log_error("not connected to server");
+ mrp_res_error("not connected to server");
goto error;
}
u_to_p(original->priv->internal_id));
if (!rset) {
- mrp_log_error("trying to acquire non-existent resource set");
+ mrp_res_error("trying to acquire non-existent resource set");
goto error;
}
if (rset->state == MRP_RES_RESOURCE_ACQUIRED) {
/* already requested, updating is not supported yet */
- mrp_log_error("trying to re-acquire already acquired set");
+ mrp_res_error("trying to re-acquire already acquired set");
/* TODO: when supported by backend
* type = RESPROTO_UPDATE_RESOURCE_SET
}
if (create_resource_set_request(cx, rset) < 0) {
- mrp_log_error("creating resource set failed");
+ mrp_res_error("creating resource set failed");
mrp_list_delete(&rset->priv->hook);
goto error;
}