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 FNetNfcNdefMessage.h
19 * @brief This is the header file for the %NdefMessage class.
21 * This header file contains the declarations of the %NdefMessage class.
24 #ifndef _FNET_NFC_NDEF_MESSAGE_H_
25 #define _FNET_NFC_NDEF_MESSAGE_H_
27 #include <FBaseObject.h>
28 #include <FBaseResult.h>
30 namespace Tizen { namespace Base
36 namespace Tizen { namespace Net { namespace Nfc
39 class _NdefMessageImpl;
44 * @brief This class represents an NDEF message.
48 * The %NdefMessage class represents an NDEF message. An NDEF message is composed of 1 or more NDEF records. Therefore,
49 * this class has NdefRecord instances and provides the operations to manipulate the list of those instances. These
50 * operations are very similar to those of the Tizen::Base::Collection::IList class.
52 * If a new NDEF record is inserted, the uniqueness of its payload identifier is checked. This class also provides
53 * methods which convert %NdefMessage to Tizen::Base::ByteBuffer and vice versa.
55 * For more information on the class features, see
56 * <a href="../org.tizen.native.appprogramming/html/guide/net/nfc.htm">NFC Guide</a>.
58 class _OSP_EXPORT_ NdefMessage
59 : public Tizen::Base::Object
63 * This is the default constructor for this class.
70 * Copying of objects using this copy assignment operator is allowed.
74 * @param[in] value An instance of %NdefMessage
75 * @remarks This performs a deep copy.
77 NdefMessage(const NdefMessage& value);
80 * This destructor overrides Tizen::Base::Object::~Object().
84 virtual ~NdefMessage(void);
87 * Compares the calling instance with the specified instance.
91 * @return @c true if the specified instance of Tizen::Base::Object is equal to the calling %NdefMessage
94 * @param[in] obj The object to compare
95 * @remark Two NdefMessage instances are equal only if they contain the same %NdefRecord instances in the
98 virtual bool Equals(const Tizen::Base::Object& obj) const;
101 * Gets the hash value of the current instance.
105 * @return The hash value of the current instance
107 virtual int GetHashCode(void) const;
110 * Gets the number of NDEF records in this NDEF message.
114 * @return The number of NDEF records
116 int GetRecordsCount(void) const;
119 * Searches for an NdefRecord object in this class. @n
120 * Gets the index of the NdefRecord object if the record is present.
124 * @exception E_SUCCESS The method is successful.
125 * @exception E_OBJ_NOT_FOUND The specified record is not found.
126 * @remarks This method verifies the equality of its pointers, but does not check the content of the specified
129 result IndexOf(const NdefRecord& record, int& index) const;
132 * Gets the NdefRecord object from the specified location.
136 * @return The requested NdefRecord object, @n
137 * else @c null if the index is not valid
138 * @param[in] index The index of the NDEF record to get
139 * @exception E_SUCCESS The method is successful.
140 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n
141 * The specified @c index parameter is either greater than or equal to the number
142 * of elements or less than @c 0.
143 * @remarks The specific error code can be accessed using the GetLastResult() method.
145 NdefRecord* GetRecordAt(int index) const;
148 * Gets the NdefRecord object with the specified payload identifier.
152 * @return The requested NdefRecord object, @n
153 * else @c null if no record matches
154 * @param[in] payloadId The payload identifier of the NDEF record to get
155 * @exception E_SUCCESS The method is successful.
156 * @exception E_OBJ_NOT_FOUND The specified @c id is not found in any of the NDEF records.
157 * @remarks The specific error code can be accessed using the GetLastResult() method.
159 NdefRecord* GetRecord(const Tizen::Base::String& payloadId) const;
162 * Appends the specified NDEF record at the end of the last record in the NDEF message.
166 * @return An error code
167 * @param[in] record The NDEF record to append
168 * @exception E_SUCCESS The method is successful.
169 * @exception E_INVALID_ARG The specified NDEF record is invalid. @n
170 * For example, the record has the same payload identifier as the other records in
172 * @exception E_OUT_OF_MEMORY The memory is insufficient.
173 * @remarks This method performs a shallow copy. It adds just the pointer, not the NdefRecord instance.
175 result AppendRecord(const NdefRecord& record);
178 * Inserts the specified NDEF record in the NDEF message at the specified location.
182 * @return An error code
183 * @param[in] record The NDEF record to insert
184 * @param[in] index The index at which the NDEF record must be inserted
185 * @exception E_SUCCESS The method is successful.
186 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n
187 * The specified @c index is greater than the number of elements or less than
189 * @exception E_INVALID_ARG The specified NDEF record is invalid. @n
190 * For example, the record has the same payload identifier as the other records in
192 * @exception E_OUT_OF_MEMORY The memory is insufficient.
194 * - The NDEF records that appear after the insertion point move downwards to accommodate the inserted
196 * - This method performs a shallow copy. It adds just the pointer, not the NdefRecord instance.
198 result InsertRecordAt(const NdefRecord& record, int index);
201 * Replaces the NDEF record from the specified location with the specified NDEF record.
205 * @return An error code
206 * @param[in] record The NDEF record to set
207 * @param[in] index The index at which the NDEF record is set
208 * @param[in] deallocate Set to @c true to deallocate the replaced record, @n
210 * @exception E_SUCCESS The method is successful.
211 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n
212 * The specified @c index is either equal to or greater than the number of
213 * elements or less than @c 0.
214 * @exception E_INVALID_ARG The specified NDEF record is invalid. @n
215 * For example, the record has the same payload identifier as the other records in
217 * @remarks This method performs a shallow copy. It adds just the pointer, not the NdefRecord instance.
219 result SetRecordAt(const NdefRecord& record, int index, bool deallocate = false);
222 * Removes the NDEF record from a specified location.
226 * @return An error code
227 * @param[in] index The index from where the NDEF record is removed
228 * @param[in] deallocate Set to @c true to deallocate the record, @n
230 * @exception E_SUCCESS The method is successful.
231 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n
232 * The specified @c index is either equal to or greater than the number of
233 * elements or less than @c 0.
234 * @remarks The NDEF records that appear after the deletion point move upwards to occupy the vacated spot.
236 result RemoveRecordAt(int index, bool deallocate = false);
239 * Removes all the records in the NDEF message. @n
240 * If the specified @c deallocate parameter is set to @c true, it deallocates all the NdefRecord instances in the
245 * @param[in] deallocate Set to @c true to deallocate the record, @n
248 void RemoveAllRecords(bool deallocate = false);
251 * Converts the entire NDEF message with all the NDEF records into a byte sequence as per the NDEF specification.
255 * @return The NDEF message as a Tizen::Base::ByteBuffer, @n
256 * else @c null if the conversion fails
257 * @exception E_SUCCESS The method is successful.
258 * @exception E_INVALID_DATA The specified NDEF message does not contain any NDEF records.
259 * @exception E_OUT_OF_MEMORY The memory is insufficient.
260 * @exception E_SYSTEM A system error has occurred.
261 * @remarks The specific error code can be accessed using the GetLastResult() method.
263 Tizen::Base::ByteBuffer* ToByteBufferN(void) const;
266 * Gets a new instance of the NDEF message from the specified Tizen::Base::ByteBuffer.
270 * @return The instance of the created NDEF message, @n
271 * else @c null if the conversion fails
272 * @param[in] buffer An NDEF message as a byte sequence
273 * @exception E_SUCCESS The method is successful.
274 * @exception E_INVALID_FORMAT The specified @c buffer cannot be formulated to the NDEF message.
275 * @exception E_OUT_OF_MEMORY The memory is insufficient.
276 * @exception E_SYSTEM A system error has occurred.
277 * @remarks The specific error code can be accessed using the GetLastResult() method.
279 static NdefMessage* GetInstanceN(const Tizen::Base::ByteBuffer& buffer);
282 * Assigns the value of the specified instance to the current instance of %NdefMessage.
286 * @return A reference to the %NdefMessage instance
287 * @param[in] rhs A reference to the %NdefMessage instance to copy
289 NdefMessage& operator =(const NdefMessage& rhs);
292 _NdefMessageImpl* __pImpl;
294 friend class _NdefMessageImpl;
298 } } } // Tizen::Net::Nfc
300 #endif // _FNET_NFC_NDEF_MESSAGE_H_