Release version 0.21.1
[platform/core/appfw/aul-1.git] / include / aul_app_com.h
1 /*
2  *  aul
3  *
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef __APP_COM_H__
21 #define __APP_COM_H__
22
23 #include <bundle.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 typedef enum {
30         AUL_APP_COM_PUBLIC = 0x0, /* allowed for all */
31         AUL_APP_COM_PRIVILEGED = 0x1, /* allowed for given privileged app */
32 } aul_app_com_propagate_option_e;
33
34 typedef enum {
35         AUL_APP_COM_R_ERROR_OK = 0,
36         AUL_APP_COM_R_ERROR_UNKNOWN_ENDPOINT = -1,
37         AUL_APP_COM_R_ERROR_ENDPOINT_ALREADY_EXISTS = -2,
38         AUL_APP_COM_R_ERROR_ILLEGAL_ACCESS = -3,
39         AUL_APP_COM_R_ERROR_CLIENT_REMAINING = -4,
40         AUL_APP_COM_R_ERROR_OUT_OF_MEMORY = -5,
41         AUL_APP_COM_R_ERROR_FATAL_ERROR = -6,
42 } aul_app_com_error_e;
43
44 typedef enum {
45         AUL_APP_COM_R_OK = 0,
46         AUL_APP_COM_R_ILLEGAL_ACCESS = -1,
47 } aul_app_com_result_e;
48
49 typedef struct _aul_app_com_permission_s aul_app_com_permission_s;
50 typedef aul_app_com_permission_s *aul_app_com_permission_h;
51 typedef struct _aul_app_com_connection_s aul_app_com_connection_s;
52 typedef aul_app_com_connection_s *aul_app_com_connection_h;
53
54 typedef int (*app_com_cb)(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data);
55
56 /**
57  * aul_app_com provides publish-subscribe style message for internal AUL use.
58  * e.g) widget status propagation, sharing callee app status to caller app
59  * @code
60
61 static int __handler(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data)
62 {
63         _D("endpoint: %s", endpoint);
64         _D("result: %d", result);
65
66         return 0;
67 }
68
69 // viewer-side
70 aul_app_com_permission_h permission = aul_app_com_permission_create();
71 aul_app_com_permission_set_propagation(permission, AUL_APP_COM_PRIVILEGED);
72 aul_app_com_permission_set_privilege(permission, "http://tizen.org/privilege/widget.viewer");
73 aul_app_com_connection_h connection = NULL;
74 aul_app_com_create("widget.status", permission, __handler, NULL, &connection);
75
76
77 // widget-side
78 bundle *b = bundle_create();
79 bundle_add_str(b, "WIDGET_ID", "org.example.widget");
80 bundle_add_str(b, "STATUS", "RUNNING");
81 aul_app_com_send("widget.status", b);
82 bundle_free(b);
83
84
85 // monitor-side
86 static int __handler(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data)
87 {
88         const char *widget_id = bundle_get_val(envelope, "WIDGET_ID");
89         const char *status = bundle_get_val(envelope, "STATUS");
90
91         _D("%s is %s", widget_id, status);
92
93         return 0;
94 }
95
96 aul_app_com_connection_h connection = NULL;
97 aul_app_com_join("widget.status", NULL, __handler, NULL, &connection);
98
99  */
100
101 aul_app_com_permission_h aul_app_com_permission_create();
102 void aul_app_com_permission_destroy(aul_app_com_permission_h permission);
103 int aul_app_com_permission_set_propagation(aul_app_com_permission_h permission, aul_app_com_propagate_option_e option);
104 int aul_app_com_permission_set_privilege(aul_app_com_permission_h permission, const char *privilege);
105
106
107 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);
108 int aul_app_com_join(const char *endpoint, const char *filter, app_com_cb callback, void *user_data, aul_app_com_connection_h *connection);
109 int aul_app_com_leave(aul_app_com_connection_h connection);
110 int aul_app_com_send(const char *endpoint, bundle *envelope);
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif