Merge from master
[platform/core/appfw/message-port.git] / src / MessagePortProxy.h
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        MessagePortProxy.h
20  * @brief       This is the header file for the MessagePortProxy class.
21  *
22  * This file contains the declarations of MessagePortProxy.
23  */
24
25
26 #ifndef _MESSAGE_PORT_PROXY_H_
27 #define _MESSAGE_PORT_PROXY_H_
28
29 #include <string>
30 #include <map>
31 #include <pthread.h>
32
33 #include <bundle.h>
34
35 #include "message-port.h"
36 #include "message-port-data-types.h"
37
38 #include "IIpcClientEventListener.h"
39
40 namespace IPC { class Message; }
41
42 class IpcClient;
43
44 class MessagePortProxy
45         : public IIpcClientEventListener
46 {
47 public:
48         virtual ~MessagePortProxy(void);
49
50         int Construct(void);
51
52         virtual void OnIpcResponseReceived(IpcClient& client, const IPC::Message& message);
53
54
55         int RegisterMessagePort(const std::string& localPort,
56                                                         bool isTrusted,
57                                                         messageport_message_cb callback);
58
59         int CheckRemotePort(const std::string& remoteAppId,
60                                                 const std::string& remotePort,
61                                                 bool isTrusted,
62                                                 bool *exist);
63
64         int SendMessage(const std::string& remoteAppId,
65                                         const std::string& remotePort,
66                                         bool trustedMessage,
67                                         bundle* data);
68
69         int SendMessage(const std::string& localPort,
70                                         bool trustedPort,
71                                         const std::string& remoteAppId,
72                                         const std::string& remotePort,
73                                         bool trustedMessage,
74                                         bundle* data);
75
76         char* GetLocalPortNameN(int id);
77
78         int CheckTrustedLocalPort(int id, bool* trusted);
79
80         static MessagePortProxy* GetProxy(void);
81
82 private:
83         MessagePortProxy(void);
84
85         int SendMessageInternal(const BundleBuffer& buffer);
86
87         bool OnSendMessageInternal(const BundleBuffer& buffer);
88
89         int GetNextId(void);
90
91         bool IsLocalPortRegisted(const std::string& localPort, bool trusted, int &id);
92
93         int CheckCertificate(const std::string& remoteAppId);
94
95         bool IsPreloaded(const std::string& remoteAppId);
96
97 private:
98         IpcClient* __pIpcClient;
99         pthread_mutex_t* __pMutex;
100
101         std::string __appId;
102
103         std::map<std::string, messageport_message_cb> __listeners;
104         std::map<std::string, int> __idFromString;
105         std::map<int, std::string> __ids;
106
107         std::map<std::string, messageport_message_cb> __trustedListeners;
108         std::map<std::string, int> __trustedIdFromString;
109         std::map<int, std::string> __trustedIds;
110
111 }; // MessagePortProxy
112
113 #endif // _MESSAGE_PORT_PROXY_H_