b535ed28df2f38f792ff343fd121e1f17cc7b497
[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_INTERFACE_RESTRICTION     STC_DBUS_SERVICE ".restriction"
25 #define STC_DBUS_SERVICE_PATH              "/net/stc"
26 #define STC_DBUS_SERVICE_STATISTICS_PATH   "/net/stc/statistics"
27 #define STC_DBUS_SERVICE_RESTRICTION_PATH  "/net/stc/restriction"
28 #define STC_DBUS_SERVICE_FIREWALL_PATH     "/net/stc/firewall"
29 #define STC_DBUS_SERVICE_PCAP_PATH         "/net/stc/pcap"
30 #define STC_DBUS_SERVICE_MANAGER_PATH      "/net/stc/manager"
31
32 #define STC_DBUS_REPLY_ERROR_NONE(invocation) \
33         g_dbus_method_invocation_return_value((invocation), \
34                                               g_variant_new("(i)", \
35                                                             STC_ERROR_NONE));
36
37 #define STC_DBUS_REPLY(invocation, parameters) \
38         g_dbus_method_invocation_return_value((invocation), parameters);
39
40 #define DEBUG_PARAMS(parameters) do {\
41         gchar *params_str = NULL;\
42         if (parameters)\
43                 params_str = g_variant_print((GVariant *)parameters,\
44                                              TRUE);\
45         STC_LOGD("Dbus params [%s]", params_str ? params_str : "NULL");\
46         g_free(params_str);\
47 } while (0)
48
49 #define DEBUG_PARAM_TYPE(parameters) do { \
50         STC_LOGD("Dbus params type [%s]", \
51                  g_variant_get_type_string(parameters)); \
52 } while (0)
53
54
55 typedef void(*dbus_dict_cb)(const char *key, GVariant *value,
56                             void *user_data);
57
58 void stc_manager_gdbus_init(gpointer stc_manager);
59 void stc_manager_gdbus_deinit(gpointer stc_manager);
60 GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection,
61                                       const char *dest, const char *path,
62                                       const char *interface_name,
63                                       const char *method, GVariant *params);
64 int stc_manager_gdbus_call_async(GDBusConnection *connection,
65                                       const char *dest, const char *path,
66                                       const char *interface_name,
67                                       const char *method, GVariant *params,
68                                       GAsyncReadyCallback notify_func,
69                                       void *user_data);
70 guint stc_manager_gdbus_subscribe_signal(GDBusConnection *connection,
71                                          const gchar *sender,
72                                          const gchar *interface_name,
73                                          const gchar *member,
74                                          const gchar *object_path,
75                                          const gchar *arg0,
76                                          GDBusSignalFlags flags,
77                                          GDBusSignalCallback callback,
78                                          gpointer user_data,
79                                          GDestroyNotify user_data_free_func);
80 void stc_manager_gdbus_unsubscribe_signal(GDBusConnection *connection,
81                                           guint subscription_id);
82 void stc_manager_gdbus_dict_foreach(GVariantIter *iter, dbus_dict_cb cb,
83                                     void *user_data);
84 gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection,
85                                       const gchar *object_path,
86                                       const gchar *interface_name,
87                                       const gchar *signal_name,
88                                       GVariant *parameters);
89
90 gboolean handle_manager_stop(StcManager *object,
91                                           GDBusMethodInvocation *invocation);
92
93 gboolean handle_manager_commit_iptables(StcManager *object,
94                                         GDBusMethodInvocation *invocation,
95                                         const gchar *option,
96                                         void *user_data);
97 gboolean handle_manager_commit_ip6tables(StcManager *object,
98                                         GDBusMethodInvocation *invocation,
99                                         const gchar *option,
100                                         void *user_data);
101
102 #endif /* __STC_MANAGER_GDBUS_H__ */