Release version 1.3.20
[platform/core/appfw/message-port.git] / src / inc / message_port_common.h
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
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 __TIZEN_APPFW_MESSAGE_PORT_COMMOM_H__
18 #define __TIZEN_APPFW_MESSAGE_PORT_COMMOM_H__
19
20 #include <bundle.h>
21 #include <gio/gio.h>
22
23 #include <message_port.h>
24 #include <message_port_log.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #define MESSAGEPORT_BUS_NAME_PREFIX "org.tizen.messageport._"
31 #define MESSAGEPORT_OBJECT_PATH "/org/tizen/messageport"
32 #define MESSAGEPORT_INTERFACE_PREFIX "org.tizen.messageport._"
33
34 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
35 #define DBUS_PATH_DBUS "/org/freedesktop/DBus"
36 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
37
38
39 #define retvm_if(expr, val, fmt, arg...) do { \
40         if (expr) { \
41                 _LOGE(fmt, ##arg); \
42                 _LOGE("(%s) -> %s() return", #expr, __func__); \
43                 return val; \
44         } \
45 } while (0)
46
47 #define retv_if(expr, val) do { \
48         if (expr) { \
49                 _LOGE("(%s) -> %s() return", #expr, __func__); \
50                 return val; \
51         } \
52 } while (0)
53
54 #define FREE_AND_NULL(ptr) do { \
55         if (ptr) { \
56                 free((void *)ptr); \
57                 ptr = NULL; \
58         } \
59 } while (0)
60
61 int write_socket(int fd,
62                 const char *buffer,
63                 unsigned int nbytes,
64                 unsigned int *bytes_write,
65                 int *sequence);
66 int write_string_to_socket(int fd,
67                 const char *buffer,
68                 int string_len,
69                 unsigned int *bytes_write,
70                 int *sequence);
71 int read_socket(int fd,
72                 char *buffer,
73                 unsigned int nbytes,
74                 unsigned int *bytes_read);
75 int read_string_from_socket(int fd, char **buffer, int *string_len);
76 bool initialize_common();
77 bool is_preloaded(const char *local_appid, const char *remote_appid);
78 int check_certificate(const char *local_appid, const char *remote_appid);
79 char *get_encoded_name(const char *remote_app_id, const char *port_name, bool is_trusted);
80 void message_port_lock_mutex();
81 void message_port_unlock_mutex();
82
83 extern bool initialized_common;
84 extern GDBusConnection *gdbus_conn;
85 extern char *app_id;
86
87 /**
88  * @}
89  */
90
91 #ifdef __cplusplus
92 }
93 #endif
94
95 #endif /*  __TIZEN_APPFW_MESSAGE_PORT_COMMOM_H__ */