summaryrefslogtreecommitdiff
path: root/src/heremaps-uc-dbus.c
blob: 194eebae96c8866b36d8db9c2c079dac5d8ca71e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* Copyright 2014 Samsung Electronics Co., Ltd 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.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include "heremaps-uc-dbus.h"

/**
* @brief        information for DBUS
*/
#define UC_RECEIVER_NAME	"org.tizen.lbs.Providers.HereMapsUCLauncher"
#define UC_RECEIVER_PATH	"/org/tizen/lbs/Providers/HereMapsUCLauncher"
#define UC_INTERFACE_NAME	"org.tizen.lbs.HereMapsUCLauncher"


typedef struct _heremaps_uc_dbus_s {
	GDBusConnection *conn;
	gchar *service_name;
	gchar *service_path;
	gchar *signal_path;
} heremaps_uc_dbus_s;

EXPORT_API int heremaps_uc_dbus_launch_receiver()
{
	MAPS_FUNC_ENTER

	char *bus_addr = NULL;
	GError *error = NULL;
	GDBusProxy *proxy = NULL;

#if !GLIB_CHECK_VERSION(2, 35, 0)
	g_type_init();
#endif

	heremaps_uc_dbus_s *handle = g_new0(heremaps_uc_dbus_s, 1);
	g_return_val_if_fail(handle, HEREMAPS_UC_DBUS_ERROR_MEMORY);

	handle->conn = NULL;

	/* get addr of dbus */
	bus_addr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SESSION, NULL, &error);
	if (!bus_addr) {
		MAPS_LOGD("Fail to get addr of bus.");
		return HEREMAPS_UC_DBUS_ERROR_CONNECTION;
	}
	MAPS_LOGD("bus_addr: %s", bus_addr);

	/* connect and setup dbus */
	handle->conn = g_dbus_connection_new_for_address_sync(bus_addr,
							G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
							G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
							NULL, NULL, &error);
	if (!handle->conn) {
		if (error && error->message) {
			MAPS_LOGD("Fail to get GBus. ErrCode[%d], Msg[%s]", error->code, error->message);
			g_error_free(error);
			error = NULL;
		}
		return HEREMAPS_UC_DBUS_ERROR_CONNECTION;
	}
	MAPS_LOGD("handle->conn: %p", handle->conn);
	g_free(bus_addr);

	handle->service_name = g_strdup(UC_RECEIVER_NAME);
	handle->service_path = g_strdup(UC_RECEIVER_PATH);
	handle->signal_path = g_strdup_printf("%s/%s", handle->service_path, "SAMSUNG");
	MAPS_LOGD("Object Path [%s]", handle->signal_path);

	proxy = g_dbus_proxy_new_sync(handle->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, handle->service_name, handle->signal_path, UC_INTERFACE_NAME, NULL, NULL);
	if (proxy) {
		MAPS_LOGD("proxy: %p", proxy);
		g_object_unref(proxy);
	} else {
		if (error) {
			MAPS_LOGD("Fail to get proxy Error[%s]", error->message);
			g_error_free(error);
		}
	}
	MAPS_LOGD("g_dbus_proxy_new_sync is done");

	if (handle->conn) {
		g_object_unref(handle->conn);
		handle->conn = NULL;
		MAPS_LOGD("g_object_unref : handle->conn");
	}
	g_free(handle->service_path);
	g_free(handle->service_name);
	g_free(handle->signal_path);
	g_free(handle);

	MAPS_LOGD("g_free done");
	return HEREMAPS_UC_DBUS_ERROR_NONE;
}