Move function definition to aul header
[platform/core/appfw/aul-1.git] / include / aul_app_com.h
1 /*
2  * Copyright (c) 2015 - 2021 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 __APP_COM_H__
18 #define __APP_COM_H__
19
20 #include <bundle.h>
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 typedef enum {
27         AUL_APP_COM_PUBLIC = 0x0, /* allowed for all */
28         AUL_APP_COM_PRIVILEGED = 0x1, /* allowed for given privileged app */
29 } aul_app_com_propagate_option_e;
30
31 typedef enum {
32         AUL_APP_COM_R_ERROR_OK = 0,
33         AUL_APP_COM_R_ERROR_UNKNOWN_ENDPOINT = -1,
34         AUL_APP_COM_R_ERROR_ENDPOINT_ALREADY_EXISTS = -2,
35         AUL_APP_COM_R_ERROR_ILLEGAL_ACCESS = -3,
36         AUL_APP_COM_R_ERROR_CLIENT_REMAINING = -4,
37         AUL_APP_COM_R_ERROR_OUT_OF_MEMORY = -5,
38         AUL_APP_COM_R_ERROR_FATAL_ERROR = -6,
39 } aul_app_com_error_e;
40
41 typedef enum {
42         AUL_APP_COM_R_OK = 0,
43         AUL_APP_COM_R_ILLEGAL_ACCESS = -1,
44 } aul_app_com_result_e;
45
46 typedef void *aul_app_com_permission_h;
47 typedef void *aul_app_com_connection_h;
48
49 typedef int (*app_com_cb)(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data);
50
51 /**
52  * aul_app_com provides publish-subscribe style message for internal AUL use.
53  * e.g) widget status propagation, sharing callee app status to caller app
54  * @code
55
56 static int __handler(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data)
57 {
58         _D("endpoint: %s", endpoint);
59         _D("result: %d", result);
60
61         return 0;
62 }
63
64 // viewer-side
65 aul_app_com_permission_h permission = aul_app_com_permission_create();
66 aul_app_com_permission_set_propagation(permission, AUL_APP_COM_PRIVILEGED);
67 aul_app_com_permission_set_privilege(permission, "http://tizen.org/privilege/widget.viewer");
68 aul_app_com_connection_h connection = NULL;
69 aul_app_com_create("widget.status", permission, __handler, NULL, &connection);
70
71
72 // widget-side
73 bundle *b = bundle_create();
74 bundle_add_str(b, "WIDGET_ID", "org.example.widget");
75 bundle_add_str(b, "STATUS", "RUNNING");
76 aul_app_com_send("widget.status", b);
77 bundle_free(b);
78
79
80 // monitor-side
81 static int __handler(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data)
82 {
83         const char *widget_id = bundle_get_val(envelope, "WIDGET_ID");
84         const char *status = bundle_get_val(envelope, "STATUS");
85
86         _D("%s is %s", widget_id, status);
87
88         return 0;
89 }
90
91 aul_app_com_connection_h connection = NULL;
92 aul_app_com_join("widget.status", NULL, __handler, NULL, &connection);
93
94  */
95
96 aul_app_com_permission_h aul_app_com_permission_create();
97 void aul_app_com_permission_destroy(aul_app_com_permission_h permission);
98 int aul_app_com_permission_set_propagation(aul_app_com_permission_h permission, aul_app_com_propagate_option_e option);
99 int aul_app_com_permission_set_privilege(aul_app_com_permission_h permission, const char *privilege);
100
101 int aul_app_com_create(const char *endpoint, aul_app_com_permission_h permission, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection);
102 int aul_app_com_join(const char *endpoint, const char *filter, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection);
103 int aul_app_com_leave(aul_app_com_connection_h connection);
104 int aul_app_com_send(const char *endpoint, bundle *envelope);
105
106 int aul_app_com_create_async(const char *endpoint,
107                 aul_app_com_permission_h permission,
108                 app_com_cb callback,
109                 void *user_data,
110                 aul_app_com_connection_h *connection);
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif