4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include "communicator.h"
32 struct tcore_communicator_type {
34 struct tcore_communitor_operations *ops;
38 TcorePlugin *parent_plugin;
42 Communicator *tcore_communicator_new(TcorePlugin *plugin,
43 const char *name, struct tcore_communitor_operations *ops)
47 comm = g_try_malloc0(sizeof(struct tcore_communicator_type));
52 comm->name = g_strdup(name);
54 comm->parent_plugin = plugin;
57 tcore_server_add_communicator(tcore_plugin_ref_server(plugin), comm);
62 void tcore_communicator_free(Communicator *comm)
73 TcorePlugin *tcore_communicator_ref_plugin(Communicator *comm)
78 return comm->parent_plugin;
81 const char *tcore_communicator_ref_name(Communicator *comm)
86 return (const char *)comm->name;
89 TReturn tcore_communicator_link_user_data(Communicator *comm, void *data)
92 return TCORE_RETURN_EINVAL;
94 comm->user_data = data;
96 return TCORE_RETURN_SUCCESS;
99 void *tcore_communicator_ref_user_data(Communicator *comm)
104 return comm->user_data;
107 TReturn tcore_communicator_dispatch_request(Communicator *comm, UserRequest *ur)
112 return TCORE_RETURN_EINVAL;
114 s = tcore_plugin_ref_server(comm->parent_plugin);
116 return tcore_server_dispatch_request(s, ur);
119 TReturn tcore_communicator_send_response(Communicator *comm, UserRequest *ur,
120 enum tcore_response_command command,
121 unsigned int data_len, const void *data)
123 if (!comm || !comm->ops || !comm->ops->send_response)
124 return TCORE_RETURN_EINVAL;
126 dbg("ur = 0x%x", (unsigned int)ur);
128 return comm->ops->send_response(comm, ur, command, data_len, data);
131 TReturn tcore_communicator_send_notification(Communicator *comm,
132 CoreObject *source, enum tcore_notification_command command,
133 unsigned int data_len, const void *data)
135 if (!comm || !comm->ops || !comm->ops->send_notification)
136 return TCORE_RETURN_EINVAL;
138 return comm->ops->send_notification(comm, source, command, data_len, data);