remove message_port_unregister
[platform/core/appfw/message-port.git] / src / message-port.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        message-port.cpp
20  * @brief       This is the implementation file for the MessagePort.
21  */
22
23 #include <stdlib.h>
24
25 #include "message-port.h"
26 #include "message-port-log.h"
27
28 #include "MessagePortProxy.h"
29
30 int
31 messageport_register_local_port(const char* local_port, messageport_message_cb callback)
32 {
33         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
34         if (pProxy != NULL)
35         {
36                 return pProxy->RegisterMessagePort(local_port, false, callback);
37         }
38
39         return MESSAGEPORT_ERROR_IO_ERROR;
40 }
41
42 int
43 messageport_register_trusted_local_port(const char* local_port, messageport_message_cb callback)
44 {
45         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
46         if (pProxy != NULL)
47         {
48                 return pProxy->RegisterMessagePort(local_port, true, callback);
49         }
50
51         return MESSAGEPORT_ERROR_IO_ERROR;
52 }
53
54 int
55 messageport_check_remote_port(const char* remote_app_id, const char *remote_port, bool* exist)
56 {
57         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
58         if (pProxy != NULL)
59         {
60                 return pProxy->CheckRemotePort(remote_app_id, remote_port, false, exist);
61         }
62
63         return MESSAGEPORT_ERROR_IO_ERROR;
64 }
65
66 int
67 messageport_check_trusted_remote_port(const char* remote_app_id, const char *remote_port, bool* exist)
68 {
69         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
70         if (pProxy != NULL)
71         {
72                 return pProxy->CheckRemotePort(remote_app_id, remote_port, true, exist);
73         }
74
75         return MESSAGEPORT_ERROR_IO_ERROR;
76 }
77
78 int
79 messageport_send_message(const char* remote_app_id, const char* remote_port, bundle* message)
80 {
81         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
82         if (pProxy != NULL)
83         {
84                 return pProxy->SendMessage(remote_app_id, remote_port, false, message);
85         }
86
87         return MESSAGEPORT_ERROR_IO_ERROR;
88 }
89
90 int
91 messageport_send_trusted_message(const char* remote_app_id, const char* remote_port, bundle* message)
92 {
93         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
94         if (pProxy != NULL)
95         {
96                 return pProxy->SendMessage(remote_app_id, remote_port, true, message);
97         }
98
99         return MESSAGEPORT_ERROR_IO_ERROR;
100 }
101
102 int
103 messageport_send_bidirectional_message(int id, const char* remote_app_id, const char* remote_port, bundle* message)
104 {
105         int ret = 0;
106         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
107         if (pProxy != NULL)
108         {
109                 char* pName = pProxy->GetLocalPortNameN(id);
110                 bool trusted = false;
111                 ret = pProxy->CheckTrustedLocalPort(id, &trusted);
112                 if (ret < 0)
113                 {
114                         return MESSAGEPORT_ERROR_INVALID_PARAMETER;
115                 }
116
117                 ret = pProxy->SendMessage(pName, trusted, remote_app_id, remote_port, false, message);
118
119                 free(pName);
120
121                 return ret;
122         }
123
124         return MESSAGEPORT_ERROR_IO_ERROR;
125 }
126
127 int
128 messageport_send_bidirectional_trusted_message(int id, const char* remote_app_id, const char* remote_port, bundle* message)
129 {
130         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
131         if (pProxy != NULL)
132         {
133                 bool trusted = false;
134                 int ret = pProxy->CheckTrustedLocalPort(id, &trusted);
135                 if (ret < 0)
136                 {
137                         return ret;
138                 }
139
140                 char* pName = pProxy->GetLocalPortNameN(id);
141                 if (pName == NULL)
142                 {
143                         return MESSAGEPORT_ERROR_INVALID_PARAMETER;
144                 }
145
146                 ret = pProxy->SendMessage(pName, trusted, remote_app_id, remote_port, true, message);
147
148                 free(pName);
149
150                 return ret;
151         }
152
153         return MESSAGEPORT_ERROR_IO_ERROR;
154 }
155
156 int
157 messageport_get_local_port_name(int id, char **name)
158 {
159         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
160         if (pProxy != NULL)
161         {
162                 char* pName = pProxy->GetLocalPortNameN(id);
163                 if (pName == NULL)
164                 {
165                         return MESSAGEPORT_ERROR_INVALID_PARAMETER;
166                 }
167                 else
168                 {
169                         *name = pName;
170                         return 0;
171                 }
172         }
173
174         return MESSAGEPORT_ERROR_IO_ERROR;
175 }
176
177 int
178 messageport_check_trusted_local_port(int id, bool *trusted)
179 {
180         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
181         if (pProxy != NULL)
182         {
183                 return pProxy->CheckTrustedLocalPort(id, trusted);
184         }
185
186         return MESSAGEPORT_ERROR_IO_ERROR;
187 }
188