/*
* libtcore
*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Ja-young Gu <jygu@samsung.com>
+ * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
+ * Copyright (c) 2013 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "communicator.h"
struct tcore_communicator_type {
- const char *name;
- struct tcore_communitor_operations *ops;
+ gchar *name;
+ TcoreCommunicatorOps *ops;
void *user_data;
};
-Communicator* tcore_communicator_new(TcorePlugin *plugin, const char *name,
- struct tcore_communitor_operations *ops)
+Communicator* tcore_communicator_new(TcorePlugin *plugin,
+ const gchar *name, TcoreCommunicatorOps *ops)
{
Communicator *comm;
- comm = calloc(1, sizeof(struct tcore_communicator_type));
- if (!comm)
+ comm = g_try_new0(struct tcore_communicator_type, 1);
+ if (comm == NULL) {
+ err("Failed to allocate memory");
return NULL;
+ }
- if (name)
- comm->name = strdup(name);
-
+ /* Update parameters */
+ comm->name = tcore_strdup(name);
comm->parent_plugin = plugin;
comm->ops = ops;
+ dbg("Comunicator '%s' created", name);
+
+ /* Add communicator to Server */
tcore_server_add_communicator(tcore_plugin_ref_server(plugin), comm);
return comm;
void tcore_communicator_free(Communicator *comm)
{
- if (!comm)
+ if (comm == NULL) {
+ err("Communicator is NULL");
return;
+ }
- if (comm->name)
- free((void *)comm->name);
+ dbg("Comunicator '%s' free", comm->name);
- free(comm);
+ /* Free resources */
+ tcore_free((void *)comm->name);
+ tcore_free(comm);
}
TcorePlugin *tcore_communicator_ref_plugin(Communicator *comm)
{
- if (!comm)
+ if (comm == NULL) {
+ err("Communicator is NULL");
return NULL;
+ }
return comm->parent_plugin;
}
-const char *tcore_communicator_ref_name(Communicator *comm)
+const gchar *tcore_communicator_ref_name(Communicator *comm)
{
- if (!comm)
+ if (comm == NULL) {
+ err("Communicator is NULL");
return NULL;
+ }
return comm->name;
}
-TReturn tcore_communicator_link_user_data(Communicator *comm, void *data)
+TelReturn tcore_communicator_link_user_data(Communicator *comm, void *data)
{
- if (!comm)
- return TCORE_RETURN_EINVAL;
+ if (comm == NULL) {
+ err("Communicator is NULL");
+ return TEL_RETURN_INVALID_PARAMETER;
+ }
comm->user_data = data;
- return TCORE_RETURN_SUCCESS;
+ return TEL_RETURN_SUCCESS;
}
void *tcore_communicator_ref_user_data(Communicator *comm)
{
- if (!comm)
+ if (comm == NULL) {
+ err("Communicator is NULL");
return NULL;
+ }
return comm->user_data;
}
-TReturn tcore_communicator_dispatch_request(Communicator *comm, UserRequest *ur)
-{
- Server *s;
-
- if (!comm || !ur)
- return TCORE_RETURN_EINVAL;
-
- s = tcore_plugin_ref_server(comm->parent_plugin);
-
- return tcore_server_dispatch_request(s, ur);
-}
-
-TReturn tcore_communicator_send_response(Communicator *comm, UserRequest *ur,
- enum tcore_response_command command,
- unsigned int data_len, const void *data)
-{
- if (!comm || !comm->ops || !comm->ops->send_response)
- return TCORE_RETURN_EINVAL;
-
- dbg("ur = 0x%x", (unsigned int)ur);
-
- return comm->ops->send_response(comm, ur, command, data_len, data);
-}
-
-TReturn tcore_communicator_send_notification(Communicator *comm,
- CoreObject *source, enum tcore_notification_command command,
- unsigned int data_len, const void *data)
+TelReturn tcore_communicator_send_notification(Communicator *comm,
+ TcorePlugin *source, gint command, guint data_len, const void *data)
{
- if (!comm || !comm->ops || !comm->ops->send_notification)
- return TCORE_RETURN_EINVAL;
+ if ((comm == NULL) || (comm->ops == NULL)
+ || (comm->ops->send_notification == NULL)) {
+ err("comm: [%p] ops: [%p] send_notiifcation: [%p]",
+ comm, (comm ? comm->ops : NULL),
+ ((comm && comm->ops) ? comm->ops->send_notification : NULL));
+ return TEL_RETURN_INVALID_PARAMETER;
+ }
return comm->ops->send_notification(comm, source, command, data_len, data);
}