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