sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FIoLocalMessagePort.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  * @file                FIoLocalMessagePort.h
19  * @brief               This is the header file for the %LocalMessagePort class.
20  *
21  * This header file contains declarations of the %LocalMessagePort class.
22  */
23 #ifndef _FIO_LOCAL_MESSAGE_PORT_H_
24 #define _FIO_LOCAL_MESSAGE_PORT_H_
25
26 #include <FBaseResult.h>
27 #include <FBaseDataType.h>
28 #include <FBaseObject.h>
29 #include <FBaseString.h>
30
31 namespace Tizen { namespace Io
32 {
33
34 class IMessagePortListener;
35
36 /**
37 * @class    LocalMessagePort
38 * @brief    This class provides methods for receiving messages from other applications.
39 *
40 * @since    2.0
41 *
42 * @final        This class is not intended for extension.
43 *
44 * The %LocalMessagePort class provides methods for receiving messages from other applications.
45 *
46 * For more information on the class features,
47 * see <a href="../org.tizen.native.appprogramming/html/guide/io/messageport.htm">Message Port Communication</a>.
48 *
49 * @see Tizen::Io::MessagePortManager
50 * @see Tizen::Io::RemoteMessagePort
51 *
52 * The following example demonstrates how to use the %LocalMessagePort class.
53 *
54 * @code
55 *
56 * #include <FBase.h>
57 * #include <FIo.h>
58 *
59 * using namespace Tizen::Base;
60 * using namespace Tizen::Base::Collection;
61 * using namespace Tizen::Io;
62 *
63 * class MyAppClass
64 *               : public Tizen::Io::IMessagePortListener
65 * {
66 * public:
67 *       result Initialize(void);
68 *       virtual void OnMessageReceivedN(RemoteMessagePort* pRemoteMessagePort, IMap* pMessage);
69 *       IMap* GetOnlineFriends(void);
70 *
71 * private:
72 *       LocalMessagePort* pLocalPort;
73 * };
74 *
75 * void
76 * MyAppClass::Initialize(void)
77 * {
78 *       pLocalPort = MessagePortManager::RequestLocalMessagePort(L"PortB");
79 *       pLocalPort->AddMessagePortListener(*this);
80 * }
81 *
82 * void
83 * MyAppClass::OnMessageReceivedN(RemoteMessagePort* pRemoteMessagePort, IMap* pMessage);
84 * {
85 *       String* pValue = pMessage->GetValue(L"Request");
86 *
87 *       if (*pValue == L"Friend")
88 *       {
89 *               HashMap* pMap = GetOnlineFriends();
90 *               pRemoteMessagePort->SendMessage(pLocalPort, pMap);
91 *
92 *               delete pMap;
93 *       }
94
95 *       delete pMessage;
96 * }
97 *
98 * IMap*
99 * MyAppClass::GetOnlineFriends(void)
100 * {
101 *       HashMap* pMap = new HashMap(SingleObjectDeleter);
102 *       pMap->Construct();
103 *
104 *       pMap->Add(new String(L"Reply"), new String(L"Kim"));
105 *
106 *       return pMap;
107 * }
108 *
109 * @endcode
110 */
111
112 class _OSP_EXPORT_ LocalMessagePort
113         : public Tizen::Base::Object
114 {
115 public:
116         /**
117         * Adds a message port listener that is called when a message is received.
118         *
119         * @since    2.0
120         *
121         * @return               An error code
122         * @param[in]    listener    The message port listener
123         * @exception    E_SUCCESS           The method is successful.
124         * @exception    E_OBJ_ALREADY_EXIST     The listener instance already exists.
125         */
126         result AddMessagePortListener(IMessagePortListener& listener);
127
128         /**
129         * Removes a message port listener.
130         *
131         * @since    2.0
132         *
133         * @return               An error code
134         * @param[in]    listener    The message port listener
135         * @exception    E_SUCCESS           The method is successful.
136         * @exception    E_OBJ_NOT_FOUND     The listener instance is not found.
137         */
138         result RemoveMessagePortListener(IMessagePortListener& listener);
139
140         /**
141         * Gets the name of a local message port.
142         *
143         * @since    2.0
144         *
145         * @return               The name of a local message port
146         */
147         Tizen::Base::String GetName(void) const;
148
149         /**
150         * Checks whether an instance is a trusted message port or not.
151         *
152         * @since    2.0
153         *
154         * @return               @c true if this instance is a trusted message port, @n
155         *                               else @c false
156         */
157         bool IsTrusted(void) const;
158
159 private:
160         /**
161         * This default constructor is intentionally declared as private so that only the platform can create an instance.
162         */
163         LocalMessagePort(void);
164
165         /**
166         * This destructor is intentionally declared as private so that only the platform can delete an instance.
167         */
168         virtual ~LocalMessagePort(void);
169
170         /**
171         * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
172         */
173         LocalMessagePort(const LocalMessagePort& localMessagePort);
174
175         /**
176         * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
177         */
178         LocalMessagePort& operator =(const LocalMessagePort& localMessagePort);
179
180
181         friend class _LocalMessagePortImpl;
182
183         class _LocalMessagePortImpl * __pLocalMessagePortImpl;
184
185 }; // LocalMessagePort
186
187 } } // Tizen::Io
188
189 #endif //_FIO_LOCAL_MESSAGE_PORT_H_