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 FNetNfcNdefTagConnection.h
19 * @brief This is the header file for the %NdefTagConnection class.
21 * This header file contains the declarations of the %NdefTagConnection class.
24 #ifndef _FNET_NFC_NDEF_TAG_CONNECTION_H_
25 #define _FNET_NFC_NDEF_TAG_CONNECTION_H_
27 #include <FBaseResult.h>
28 #include <FNetNfcTagConnection.h>
30 namespace Tizen { namespace Net { namespace Nfc
33 class _NdefTagConnectionImpl;
35 class INdefTagConnectionListener;
38 * @class NdefTagConnection
39 * @brief This class represents the connection with an NFC tag that has the NDEF data.
43 * The %NdefTagConnection class provides the mechanism to communicate with the tag that has NFC Data Exchange Format
44 * (NDEF) data and supports the NDEF message operations. @n
45 * This class can be derived from the TagConnection class. Use the IsNdefConnection() method to check the availability
46 * of the derivation. @n
47 * Use the Read() and Write() methods to read and write the NDEF data. After the completion of the read and write
48 * operations, the response is received by the INdefTagConnectionListener::OnNdefReadCompletedN() and
49 * INdefTagConnectionListener::OnNdefWriteCompleted() event handlers, respectively.
51 * For more information on the class features, see
52 * <a href="../org.tizen.native.appprogramming/html/guide/net/nfc.htm">NFC Guide</a>.
54 * The following example demonstrates how to use the %NdefTagConnection class.
60 * : public Tizen::Net::Nfc::INfcManagerEventListener
61 * , public Tizen::Net::Nfc::INfcTagDiscoveryEventListener
62 * , public Tizen::Net::Nfc::INdefTagConnectionListener
65 * void WriteNdefMessageSample(void);
66 * virtual void OnNfcTagDetectedN(Tizen::Net::Nfc::TagConnection* pConnection);
67 * virtual void OnNfcTagLost(void);
68 * virtual void OnNdefWriteCompleted(result r);
69 * // Other methods are hidden for the sake of simplicity.
72 * Tizen::Net::Nfc::NfcManager* __pNfcManager;
73 * Tizen::Net::Nfc::NdefTagConnection* __pNdefConnection;
77 * #include "MyClass.h"
79 * using namespace Tizen::Net::Nfc;
81 * MyClass::MyClass(void)
82 * : __pNfcManager(null)
83 * , __pNdefConnection(null)
85 * __pNfcManager = new NfcManager();
88 * MyClass::~MyClass(void)
90 * // Removes the tag discovery event listener for all the NDEF tag types
91 * __pNfcManager->RemoveTagDiscoveryEventListener(*this, NFC_TAG_TYPE_ALL_NDEF_COMPATIBLE);
93 * delete __pNfcManager;
97 * MyClass::WriteNdefMessageSample(void)
99 * // Creates NfcManager instance and registers the manager event listener
100 * __pNfcManager->Construct(*this);
102 * // Adds the tag discovery event listener for all the NDEF tag types
103 * __pNfcManager->AddTagDiscoveryEventListener(*this, NFC_TAG_TYPE_ALL_NDEF_COMPATIBLE);
106 * // This method is invoked when a new NDEF tag is detected
108 * MyClass::OnNfcTagDetectedN(TagConnection* pConnection)
110 * // Checks whether the connection supports NDEF operations,
111 * // but the evaluation result of the below code is always true in this example
112 * if (pConnection->IsNdefConnection())
114 * __pNdefConnection = dynamic_cast<NdefTagConnection*>(pConnection);
116 * // Registers the NDEF tag connection listener
117 * __pNdefConnection->SetNdefTagConnectionListener(this);
119 * NdefMessage message;
120 * // Fills up the NdefMessage object here
122 * __pNdefConnection->Write(message);
126 * // This method is invoked when the target tag is lost
128 * MyClass::OnNfcTagLost(void)
130 * // The acquired NdefTagConnection should be deallocated
131 * delete __pNdefConnection;
134 * // This method is invoked when the write request is completed
136 * MyClass::OnNdefWriteCompleted(result r)
138 * if (r == E_SUCCESS)
140 * // Writing NdefMessage is successful
145 class _OSP_EXPORT_ NdefTagConnection
146 : public TagConnection
150 * Checks whether the connection supports the NDEF message operations.
154 * @return @c true if the connection supports the NDEF message operations, @n
157 virtual bool IsNdefConnection(void) const;
160 * Sets a listener for receiving the result of reading or writing on this NDEF tag connection.
164 * @return An error code
165 * @param[in] pListener The listener to add
166 * @exception E_SUCCESS The method is successful.
167 * @exception E_SYSTEM A system error has occurred.
168 * @remarks At the most, one event listener can be registered. If the input parameter is @c null, the listener
169 * that is currently registered gets unregistered.
171 result SetNdefTagConnectionListener(INdefTagConnectionListener* pListener);
174 * Reads the NDEF data from the NDEF tag.
178 * @return An error code
179 * @exception E_SUCCESS The method is successful.
180 * @exception E_IN_PROGRESS The read process is in progress.
181 * @exception E_CONNECTION_BUSY The connection is busy. Therefore, the method cannot process the read request.
182 * @exception E_CONNECTION_FAILED The connection to the tag is closed or it has failed.
183 * @exception E_SYSTEM A system error has occurred.
184 * @see INdefTagConnectionListener::OnNdefReadCompletedN()
189 * Writes the NDEF data to the NDEF tag.
193 * @return An error code
194 * @param[in] message The NDEF message to write to the target
195 * @exception E_SUCCESS The method is successful.
196 * @exception E_INVALID_ARG The input @c message is invalid. @n
197 * For example, it does not contain any NDEF records.
198 * @exception E_IN_PROGRESS The write process is in progress.
199 * @exception E_CONNECTION_BUSY The connection is busy. Therefore, the method cannot process the write request.
200 * @exception E_CONNECTION_FAILED The connection to the tag is closed or it has failed.
201 * @exception E_SYSTEM A system error has occurred.
202 * @see INdefTagConnectionListener::OnNdefWriteCompleted()
204 result Write(const NdefMessage& message);
207 * This destructor overrides Tizen::Base::Object::~Object().
211 virtual ~NdefTagConnection(void);
215 // This default constructor is intentionally declared as private so that only the platform can create an instance.
217 NdefTagConnection(void);
220 // The implementation of this copy constructor is intentionally blank to prohibit copying of objects.
222 NdefTagConnection(const NdefTagConnection& value);
225 // The implementation of this copy assignment operator is intentionally blank to prohibit copying of objects.
227 NdefTagConnection& operator =(const NdefTagConnection& value);
230 _NdefTagConnectionImpl* __pNdefImpl;
232 friend class _TagConnectionImpl;
233 friend class _NdefTagConnectionImpl;
235 }; // NdefTagConnection
237 } } } // Tizen::Net::Nfc
239 #endif // _FNET_NFC_NDEF_TAG_CONNECTION_H_