2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file MessagePortManagerProxy.h
24 #ifndef _PLATFORM_MESSAGE_PORT_MESSAGE_PORT_MANAGER_WRAPPER_H_
25 #define _PLATFORM_MESSAGE_PORT_MESSAGE_PORT_MANAGER_WRAPPER_H_
29 #include <dpl/shared_ptr.h>
30 #include <dpl/singleton.h>
31 #include "ILocalMessagePort.h"
32 #include "IRemoteMessagePort.h"
34 #include <message-port.h>
37 namespace MessagePort {
39 #define UNDEFINED_LOCAL_PORT_ID (-1)
41 class MessagePortManagerProxy
44 MessagePortManagerProxy();
45 virtual ~MessagePortManagerProxy();
47 LocalMessagePortPtr requestLocalMessagePort(std::string &messagePortName);
48 LocalMessagePortPtr requestTrustedLocalMessagePort(std::string &messagePortName);
49 RemoteMessagePortPtr requestRemoteMessagePort(std::string &appId, std::string &messagePortName);
50 RemoteMessagePortPtr requestTrustedRemoteMessagePort(std::string &appId, std::string &messagePortName);
52 void sendMessage(std::string appId, std::string name, bool isTrusted,
53 MessagePortDataItemMapPtr &data, int localPortId = UNDEFINED_LOCAL_PORT_ID);
56 LocalMessagePortPtr getLocalMessagePort(std::string &name, bool isTrusted);
57 RemoteMessagePortPtr getRemoteMessagePort(std::string &appId, std::string &name, bool isTrusted);
60 void cacheLocalMessagePort(int id, std::string &name, bool isTrusted, LocalMessagePortPtr &localMessagePort);
61 LocalMessagePortPtr getCachedLocalMessagePort(std::string &name, bool isTrusted);
62 LocalMessagePortPtr getCachedLocalMessagePort(int id);
64 void cacheRemoteMessagePort(std::string &appId, std::string &name, bool isTrusted, RemoteMessagePortPtr &remoteMessagePort);
65 RemoteMessagePortPtr getCachedRemoteMessagePort(std::string &appId, std::string &name, bool isTrusted);
67 struct LocalMessagePortKey {
70 bool operator<(const LocalMessagePortKey &t) const {
71 return (name < t.name || (name == t.name && isTrusted < t.isTrusted));
74 struct RemoteMessagePortKey {
78 bool operator<(const RemoteMessagePortKey &t) const {
79 if (appId < t.appId) return true;
80 if (appId == t.appId) {
81 if (name < t.name) return true;
82 if (name == t.name && isTrusted < t.isTrusted)
88 typedef std::map<LocalMessagePortKey, LocalMessagePortPtr> LocalMessagePortMap;
89 typedef std::pair<LocalMessagePortKey, LocalMessagePortPtr> LocalMessagePortPair;
90 typedef std::map<int, LocalMessagePortPtr> LocalMessagePortIdMap;
91 typedef std::pair<int, LocalMessagePortPtr> LocalMessagePortIdPair;
92 typedef std::map<RemoteMessagePortKey, RemoteMessagePortPtr> RemoteMessagePortMap;
93 typedef std::pair<RemoteMessagePortKey, RemoteMessagePortPtr> RemoteMessagePortPair;
95 LocalMessagePortMap m_localMessagePortMap;
96 LocalMessagePortIdMap m_localMessagePortIdMap;
97 RemoteMessagePortMap m_remoteMessagePortMap;
100 void messagePortMessageCb(int id, const char* remote_app_id, const char* remote_port,
101 bool trusted_message, bundle* data);
102 static void message_port_message_cb(int id, const char* remote_app_id,
103 const char* remote_port, bool trusted_message, bundle* data);
105 typedef DPL::Singleton<MessagePortManagerProxy> MessagePortManagerProxySingleton;
110 #endif // _PLATFORM_MESSAGE_PORT_MESSAGE_PORT_MANAGER_WRAPPER_H_