Revert manifest to default one
[framework/telephony/tel-plugin-dbus_tapi.git] / src / common.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <glib.h>
5
6 #include <tcore.h>
7 #include <plugin.h>
8 #include <communicator.h>
9 #include <server.h>
10 #include <user_request.h>
11
12 #include "generated-code.h"
13 #include "common.h"
14
15
16 static void _free_hook(UserRequest *ur)
17 {
18         const struct tcore_user_info *ui;
19
20         ui = tcore_user_request_ref_user_info(ur);
21         if (!ui)
22                 return;
23
24         if (ui->user_data)
25                 free(ui->user_data);
26 }
27
28 char *dbus_plugin_get_plugin_name_by_object_path(const char *object_path)
29 {
30         if (!object_path)
31                 return NULL;
32
33         if (!g_str_has_prefix(object_path, MY_DBUS_PATH)) {
34                 return NULL;
35         }
36
37         return (char *)object_path + strlen(MY_DBUS_PATH) + 1;
38 }
39
40 UserRequest *dbus_plugin_macro_user_request_new(struct custom_data *ctx, void *object, GDBusMethodInvocation *invocation)
41 {
42         UserRequest *ur = NULL;
43         char *plugin_name;
44         struct tcore_user_info ui = { 0, };
45         struct dbus_request_info *dbus_info;
46
47         plugin_name = GET_PLUGIN_NAME(invocation);
48         dbg("plugin_name = [%s]", plugin_name);
49
50         ur = tcore_user_request_new(ctx->comm, plugin_name);
51
52         dbus_info = calloc(sizeof(struct dbus_request_info), 1);
53         dbus_info->interface_object = object;
54         dbus_info->invocation = invocation;
55
56         ui.user_data = dbus_info;
57
58         tcore_user_request_set_user_info(ur, &ui);
59         tcore_user_request_set_free_hook(ur, _free_hook);
60
61         return ur;
62 }