Merge branch 'tizen_5.5' into tizen
[platform/core/uifw/capi-ui-sticker.git] / receiver / src / message.cpp
1 /*
2  * Copyright (c) 2020 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 #include <stdlib.h>
18 #include <app_event.h>
19
20 #include "message.h"
21 #include "log.h"
22 #include "config.h"
23
24 #define EVENT_NAME "event.org.tizen.sticker-receiver.user_event"
25
26 bool send_message(const char *cmd, const char *data)
27 {
28     bool result = false;
29     int ret;
30     bool found = false;
31
32     bundle *b = bundle_create();
33     bundle_add_str(b, "command", cmd);
34     if (data)
35         bundle_add_str(b, "data", data);
36
37     message_port_check_remote_port(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, &found);
38     if (found) {
39         ret = message_port_send_message(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, b);
40         if (ret != MESSAGE_PORT_ERROR_NONE)
41         {
42             LOGW("message port send message error. err : %d", ret);
43             result = false;
44         }
45         else
46         {
47             LOGI("Succeed to send message.");
48             result = true;
49         }
50     }
51     else
52     {
53         LOGW("Can't find remote port");
54         result = false;
55     }
56
57     ret = event_publish_app_event(EVENT_NAME, b);
58     if (ret != EVENT_ERROR_NONE) {
59         result = false;
60         LOGE("Failed to send message by event publish. error : %d", ret);
61     }
62     else
63     {
64         result = true;
65     }
66
67     bundle_free(b);
68
69     return result;
70 }