Initialize smart traffic control manager package
[platform/core/connectivity/stc-manager.git] / include / stc-manager-gdbus.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __STC_MANAGER_GDBUS_H__
18 #define __STC_MANAGER_GDBUS_H__
19
20 #include "stc-manager.h"
21 #include "generated-code.h"
22
23 #define STC_DBUS_SERVICE                   "net.stc"
24 #define STC_DBUS_SERVICE_PATH              "/net/stc"
25 #define STC_DBUS_SERVICE_STATISTICS_PATH   "/net/stc/statistics"
26 #define STC_DBUS_SERVICE_RESTRICTION_PATH  "/net/stc/restriction"
27 #define STC_DBUS_SERVICE_QUOTA_PATH        "/net/stc/quota"
28
29 #define STC_DBUS_REPLY_ERROR_NONE(invocation) \
30         g_dbus_method_invocation_return_value((invocation), \
31                                               g_variant_new("(i)", \
32                                                             STC_ERROR_NONE));
33
34 #define STC_DBUS_REPLY(invocation, parameters) \
35         g_dbus_method_invocation_return_value((invocation), parameters);
36
37 #define DEBUG_PARAMS(parameters) do {\
38         gchar *params_str = NULL;\
39         if (parameters)\
40                 params_str = g_variant_print((GVariant *)parameters,\
41                                              TRUE);\
42         STC_LOGD("Dbus params [%s]", params_str ? params_str : "NULL");\
43         g_free(params_str);\
44 } while (0)
45
46 #define DEBUG_PARAM_TYPE(parameters) do { \
47         STC_LOGD("Dbus params type [%s]", \
48                  g_variant_get_type_string(parameters)); \
49 } while (0)
50
51
52 #define RETURN_IF_DBUS_TYPE_MISMATCH(parameters, str) do { \
53         DEBUG_PARAM_TYPE(parameters); \
54         DEBUG_PARAMS(parameters); \
55         if (g_strcmp0(g_variant_get_type_string(parameters), str)) { \
56                 STC_LOGE("Dbus type not matching, do not process"); \
57                 __STC_LOG_FUNC_EXIT__; \
58                 return; \
59         } \
60 } while (0)
61
62 typedef void(*dbus_dict_cb)(const char *key, GVariant *value,
63                             void *user_data);
64
65 void stc_manager_gdbus_init(gpointer stc_manager);
66 void stc_manager_gdbus_deinit(gpointer stc_manager);
67 GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection,
68                                       const char *dest, const char *path,
69                                       const char *interface_name,
70                                       const char *method, GVariant *params);
71 guint stc_manager_gdbus_subscribe_signal(GDBusConnection *connection,
72                                          const gchar *sender,
73                                          const gchar *interface_name,
74                                          const gchar *member,
75                                          const gchar *object_path,
76                                          const gchar *arg0,
77                                          GDBusSignalFlags flags,
78                                          GDBusSignalCallback callback,
79                                          gpointer user_data,
80                                          GDestroyNotify user_data_free_func);
81 void stc_manager_gdbus_unsubscribe_signal(GDBusConnection *connection,
82                                           guint subscription_id);
83 void stc_manager_gdbus_dict_foreach(GVariantIter *iter, dbus_dict_cb cb,
84                                     void *user_data);
85
86 #endif /* __STC_MANAGER_GDBUS_H__ */