2 // Open Service Platform
3 // Copyright (c) 2012-2013 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.
18 * @file FNetNfcNfcManager.h
19 * @brief This is the header file for the %NfcManager class.
21 * This header file contains the declarations of the %NfcManager class.
23 #ifndef _FNET_NFC_NFC_MANAGER_H_
24 #define _FNET_NFC_NFC_MANAGER_H_
26 #include <FBaseObject.h>
27 #include <FBaseResult.h>
28 #include <FNetNfcNfcTypes.h>
30 namespace Tizen { namespace Net { namespace Nfc
33 class INfcManagerEventListener;
34 class INfcTransactionEventListener;
35 class INfcTagDiscoveryEventListener;
36 class INdefMessageDiscoveryEventListener;
37 class INfcDeviceDiscoveryEventListener;
41 class _NfcManagerImpl;
45 * @brief This is the manager class for the NFC features.
49 * The %NfcManager class is the manager class for NFC features that includes the methods for enabling and disabling the NFC feature of
50 * the device and the mechanism for establishing a connection with the detected tag. It is also used to detect the NFC
51 * tags and NDEF messages. @n
52 * There are two ways to get the TagConnection instance established with the detected tag. @n
53 * @li Use the INfcTagDiscoveryEventListener::OnNfcTagDetectedN() method that is invoked immediately when the target
55 * @li Invoke the GetCurrentTagConnectionN() method after the tag is detected.
57 * If the target tag is lost, the INfcTagDiscoveryEventListener::OnNfcTagLost() method is called and the old
58 * TagConnection instance becomes invalid. Therefore, the operations performed by the TagConnection class are not
59 * processed anymore. Moreover, the TagConnection instance cannot be used again even if the same tags are detected
60 * again by the device.
62 * For more information on the class features, see
63 * <a href="../org.tizen.native.appprogramming/html/guide/net/nfc.htm">NFC Guide</a>.
65 * The following example demonstrates how to use the %NfcManager class.
72 * : public Tizen::Net::Nfc::INfcManagerEventListener
73 * , public Tizen::Net::Nfc::INfcTagDiscoveryEventListener
74 * , public Tizen::Net::Nfc::INdefMessageDiscoveryEventListener
77 * // The method declarations are hidden for the sake of simplicity
80 * Tizen::Net::Nfc::NfcManager* __pNfcManager;
81 * Tizen::Net::Nfc::TagConnection* __pConnection;
85 * #include "MyClass.h"
87 * using namespace Tizen::Net::Nfc;
89 * MyClass::MyClass(void)
90 * : __pNfcManager(null)
91 * , __pConnection(null)
93 * __pNfcManager = new NfcManager();
96 * MyClass::~MyClass(void)
98 * // Removes the tag discovery event listener for all the NFC tag types
99 * __pNfcManager->RemoveTagDiscoveryEventListener(*this, NFC_TAG_TYPE_ALL);
100 * // Removes the NDEF message discovery event listener for all the TNF types
101 * __pNfcManager->RemoveNdefMessageDiscoveryEventListener(*this, NdefRecordType(NDEF_TNF_ALL));
103 * delete __pNfcManager;
107 * MyClass::DiscoverySample(void)
109 * // Creates the NfcManager instance and registers the manager event listener
110 * __pNfcManager->Construct(*this);
112 * if (__pNfcManager->IsTagConnected())
114 * // This is the way to get the connection already established with the detected tag
115 * __pConnection = __pNfcManager->GetCurrentTagConnectionN();
117 * // Performs connection operations here
120 * // Adds the tag discovery event listener for all the NFC tag types
121 * // This is the method to establish the connection with tags that are detected hereafter
122 * __pNfcManager->AddTagDiscoveryEventListener(*this, NFC_TAG_TYPE_ALL);
124 * // Adds the NDEF message discovery event listener for all the TNF types
125 * // This is the method to get NDEF messages that are detected hereafter
126 * __pNfcManager->AddNdefMessageDiscoveryEventListener(*this, NdefRecordType(NDEF_TNF_ALL));
129 * // This method is invoked when a new tag is detected
131 * MyClass::OnNfcTagDetectedN(TagConnection* pConnection)
133 * __pConnection = pConnection;
135 * // Performs connection operations here
138 * // This method is invoked when the target tag is lost
140 * MyClass::OnNfcTagLost(void)
142 * // The acquired TagConnection should be deallocated
143 * delete __pConnection;
146 * // This method is invoked when a new NDEF message is detected
148 * MyClass::OnNdefMessageDetectedN(NdefMessage* pMessage)
150 * // Manipulates the received message here
152 * // Deallocates the received NdefMessage
153 * pMessage->RemoveAllRecords(true);
158 class _OSP_EXPORT_ NfcManager
159 : public Tizen::Base::Object
163 * The object is not fully constructed after this constructor is called. @n
164 * For full construction, the Construct() method must be called right after calling this constructor.
168 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to
169 * initialize this instance.
175 * This destructor overrides Tizen::Base::Object::~Object().
179 virtual ~NfcManager(void);
182 * Initializes this instance of %NfcManager with the specified listener.
186 * @return An error code
187 * @param[in] listener The %INfcManagerEventListener instance to be added
188 * @exception E_SUCCESS The method is successful.
189 * @exception E_UNSUPPORTED_OPERATION The device does not support the NFC feature.
190 * @exception E_OUT_OF_MEMORY The memory is insufficient.
191 * @exception E_SYSTEM A system error has occurred.
193 result Construct(INfcManagerEventListener& listener);
196 * Activates the NFC feature of the device.
200 * @privilege %http://tizen.org/privilege/nfc.admin
202 * @return An error code
203 * @exception E_SUCCESS The method is successful.
204 * @exception E_IN_PROGRESS The activation process is in progress.
205 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
207 * For example, the NFC feature is already activated.
208 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
209 * @exception E_SYSTEM A system error has occurred.
210 * @see INfcManagerEventListener::OnNfcActivated()
212 result Activate(void);
215 * Deactivates the NFC feature of the device.
219 * @privilege %http://tizen.org/privilege/nfc.admin
221 * @return An error code
222 * @exception E_SUCCESS The method is successful.
223 * @exception E_IN_PROGRESS The deactivation process is in progress.
224 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified
226 * For example, the NFC feature is already deactivated.
227 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
228 * @exception E_SYSTEM A system error has occurred.
229 * @see INfcManagerEventListener::OnNfcDeactivated()
231 result Deactivate(void);
234 * Checks whether the NFC feature is activated.
238 * @return @c true if the NFC feature is activated, @n
241 bool IsActivated(void) const;
244 * Checks whether the NFC tag is currently connected with the device.
248 * @return @c true if the NFC tag is currently connected, @n
251 bool IsTagConnected(void) const;
254 * Gets the tag connection with the currently detected tag.
258 * @privilege %http://tizen.org/privilege/nfc.tag
260 * @return The tag connection with the currently detected tag, @n
261 * else @c null if no tag is connected or if the connection fails
262 * @exception E_SUCCESS The method is successful.
263 * @exception E_INVALID_STATE This instance is in an invalid state. @n
264 * For example, this instance has not been constructed as yet or the NFC
265 * feature is not activated.
266 * @exception E_CONNECTION_FAILED The connection to the tag is closed or has failed.
267 * @exception E_OUT_OF_MEMORY The memory is insufficient.
268 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
269 * @exception E_SYSTEM A system error has occurred.
270 * @remarks The NdefTagConnection class can inherit the TagConnection class if the currently detected tag
271 * supports the NDEF operations. To check whether the TagConnection class is inherited, use the
272 * TagConnection::IsNdefConnection() method.
273 * The specific error code can be accessed using the GetLastResult() method.
275 TagConnection* GetCurrentTagConnectionN(void) const;
278 * Adds the specified %INfcTagDiscoveryEventListener instance for the tag events with the specified tag type.
282 * @privilege %http://tizen.org/privilege/nfc.tag
284 * @return An error code
285 * @param[in] listener The listener to be added
286 * @param[in] type The tag type for which the listener is added
287 * @exception E_SUCCESS The method is successful.
288 * @exception E_OBJ_ALREADY_EXIST The listener with the specified type is already added.
289 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
290 * @exception E_SYSTEM A system error has occurred.
291 * @remarks This method can be invoked several times with different Tizen::Net::Nfc::NfcTagType values for the
292 * same listener instance. In this case, the listener is called if the specified type of the target
293 * tag matches with any one of the registered type.
295 result AddTagDiscoveryEventListener(INfcTagDiscoveryEventListener& listener, NfcTagType type);
298 * Removes the specified %INfcTagDiscoveryEventListener instance. @n
299 * The removed listener cannot listen to the events that are fired.
303 * @privilege %http://tizen.org/privilege/nfc.tag
305 * @return An error code
306 * @param[in] listener The listener to be removed
307 * @param[in] type The tag type for which the listener is removed
308 * @exception E_SUCCESS The method is successful.
309 * @exception E_OBJ_NOT_FOUND The listener with the specified type is not found.
310 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
311 * @exception E_SYSTEM A system error has occurred.
313 result RemoveTagDiscoveryEventListener(INfcTagDiscoveryEventListener& listener, NfcTagType type);
316 * Adds the specified %INdefMessageDiscoveryEventListener instance for the events related to an NDEF message that
317 * includes the NDEF record with the specified type.
321 * @privilege %http://tizen.org/privilege/nfc.common
323 * @return An error code
324 * @param[in] listener The listener to be added
325 * @param[in] type The type of the NDEF record for which the listener is added
326 * @exception E_SUCCESS The method is successful.
327 * @exception E_INVALID_ARG The specified @c type is invalid. @n
328 * For example, the name of the record type is an empty string if the name
329 * format is NDEF_TNF_WELL_KNOWN, NDEF_TNF_MIME_MEDIA, NDEF_TNF_ABSOLUTE_URI,
330 * or NDEF_TNF_EXTERNAL.
331 * @exception E_OBJ_ALREADY_EXIST The listener with the specified type is already added.
332 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
333 * @exception E_SYSTEM A system error has occurred.
334 * @remarks This method can be invoked several times with different NdefRecordType values for the same listener
335 * instance. In this case, the listener is called if the record type in the detected NDEF records
336 * matches with one of the registered types.
337 * In case of the MIME %Media type as Type Name Format (TNF), asterisks can be used in the type name
338 * for wildcard matching, such as @htmlonly "image/*" @endhtmlonly.
340 result AddNdefMessageDiscoveryEventListener(INdefMessageDiscoveryEventListener& listener, const NdefRecordType& type);
343 * Removes the specified %INdefMessageDiscoveryEventListener instance. @n
344 * The removed listener cannot listen to the events that are fired.
348 * @privilege %http://tizen.org/privilege/nfc.common
350 * @return An error code
351 * @param[in] listener The listener to be removed
352 * @param[in] type The type of the NDEF record for which the listener is removed
353 * @exception E_SUCCESS The method is successful.
354 * @exception E_INVALID_ARG The specified @c type is invalid. @n
355 * For example, the name of the record type is an empty string if the name
356 * format is NDEF_TNF_WELL_KNOWN, NDEF_TNF_MIME_MEDIA, NDEF_TNF_ABSOLUTE_URI,
357 * or NDEF_TNF_EXTERNAL.
358 * @exception E_OBJ_NOT_FOUND The listener with the specified type is not found.
359 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
360 * @exception E_SYSTEM A system error has occurred.
362 result RemoveNdefMessageDiscoveryEventListener(INdefMessageDiscoveryEventListener& listener, const NdefRecordType& type);
365 * Adds the specified %INfcDeviceDiscoveryEventListener instance for the device discovery events.
369 * @privilege %http://tizen.org/privilege/nfc.p2p
371 * @return An error code
372 * @param[in] listener The listener to be added
373 * @exception E_SUCCESS The method is successful.
374 * @exception E_OBJ_ALREADY_EXIST The listener was already added.
375 * @exception E_OUT_OF_MEMORY The memory is insufficient.
376 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
377 * @exception E_SYSTEM A system error has occurred.
379 result AddDeviceDiscoveryEventListener(INfcDeviceDiscoveryEventListener& listener);
382 * Removes the specified %INfcDeviceDiscoveryEventListener instance. @n
383 * The removed listener cannot listen to the events that are fired.
387 * @privilege %http://tizen.org/privilege/nfc.p2p
389 * @return An error code
390 * @param[in] listener The listener to be removed
391 * @exception E_SUCCESS The method is successful.
392 * @exception E_OBJ_NOT_FOUND The listener was not found.
393 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
394 * @exception E_SYSTEM A system error has occurred.
396 result RemoveDeviceDiscoveryEventListener(INfcDeviceDiscoveryEventListener& listener);
399 * Checks whether peer device has been detected.
403 * @return @c true if peer device has been detected, @n
406 bool IsDeviceDetected(void) const;
410 * Gets the NDEF message cached when the tag is detected.
414 * @privilege %http://tizen.org/privilege/nfc.common
416 * @return The cached %NdefMessage instance, @n
417 * else @c null if the method is not successful
418 * @exception E_SUCCESS The method is successful.
419 * @exception E_UNSUPPORTED_OPERATION The device does not support the NFC feature..
420 * @exception E_ILLEGAL_ACCESS This operation is not allowed because the application is not launched by
421 * Conditional %App Launch.
422 * @exception E_INVALID_FORMAT The cached data cannot be converted to the NDEF message.
423 * @exception E_OUT_OF_MEMORY The memory is insufficient.
424 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
425 * @exception E_SYSTEM A system error has occurred.
426 * @remarks This method is available only to the application that is launched by Conditional %App Launch until
427 * the application is terminated or another tag is detected.
428 * The input NdefMessage instance should be deleted by the application after it is used, even outside
429 * this method. The NdefMessage::RemoveAllRecords() method should be called with @c true as the input
430 * value immediately before the NdefMessage instance is deleted.
431 * The specific error code can be accessed using the GetLastResult() method.
432 * @see <a href="../org.tizen.native.appprogramming/html/guide/net/conditional_nfc_app_launch.htm">
433 * The Conditional NFC App Launch guide</a>
434 * @see Tizen::App::AppManager::RegisterAppLaunch
436 static NdefMessage* GetCachedNdefMessageN(void);
439 * Enables or disables the Conditional NFC %App Launch pop-up. @n
440 * The pop-up includes all kinds of UI components that the system raises about NFC as well as a pop-up for
441 * selecting the launching application when a tag is detected.
445 * @privilege %http://tizen.org/privilege/nfc.common
447 * @return An error code
448 * @param[in] enable Set to @c true to enable the Conditional NFC %App Launch pop-up, @n
450 * @exception E_SUCCESS The method is successful.
451 * @exception E_UNSUPPORTED_OPERATION The device does not support the NFC feature.
452 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
453 * @exception E_SYSTEM A system error has occurred.
454 * @remarks Note that this method is used to enable or disable the launch pop-up when the application is in the
455 * foreground. Although the application disables the launch pop-up by invoking this method, it is
456 * automatically enabled when the application goes to the background. The launch pop-up is enabled by
458 * @see <a href="../org.tizen.native.appprogramming/html/guide/net/conditional_nfc_app_launch.htm">
459 * The Conditional NFC App Launch guide</a>
461 static result SetLaunchPopupEnabled(bool enable);
465 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying
468 NfcManager(const NfcManager& value);
471 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit
472 // copying of objects.
474 NfcManager& operator =(const NfcManager& value);
477 _NfcManagerImpl* __pImpl;
479 friend class _NfcManagerImpl;
482 } } } // Tizen::Net::Nfc
484 #endif // _FNET_NFC_NFC_MANAGER_H_