tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / NFC / NdefRecord.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2013 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 #ifndef __TIZEN_NFC_NDEFRECORD_H_
19 #define __TIZEN_NFC_NDEFRECORD_H_
20
21 #include <nfc.h>
22 #include <memory>
23 #include <vector>
24
25 namespace DeviceAPI {
26 namespace NFC {
27
28 class NdefRecord;
29 typedef std::shared_ptr<NdefRecord> NdefRecordPtr;
30 typedef std::vector<NdefRecordPtr> NdefRecordPtrVector;
31 typedef std::vector<unsigned char> UCharVector;
32
33 typedef enum {
34     NFC_RECORD_UNKNOWN,
35     NFC_RECORD_TEXT,
36     NFC_RECORD_URI,
37     NFC_RECORD_MEDIA
38 } nfc_recordtype_e;
39
40 typedef enum {
41     VALID_STATE,
42     INVALID_STATE
43 } nfc_recordstate_e;
44
45 class NdefRecord
46 {
47 public:
48     NdefRecord();
49     NdefRecord(const unsigned char* data, const unsigned long size);
50     NdefRecord(const short tnf,
51             const UCharVector &type,
52             const UCharVector &payload,
53             const UCharVector &id);
54     virtual ~NdefRecord();
55
56     short getTnf() const;
57     UCharVector getType() const;
58     UCharVector getPayload() const;
59     UCharVector getId() const;
60     // function used for checking type of inherited record class
61     nfc_recordtype_e getRecordType() const;
62     nfc_recordstate_e getRecordState() const;
63
64     static NdefRecordPtr getNdefRecord(nfc_ndef_message_h message, const int index);
65     static nfc_ndef_record_h getHandle(NdefRecordPtr record_ptr);
66     static short getTnfFromHandle(nfc_ndef_record_h handle,
67             nfc_ndef_message_h message_handle = NULL);
68     static UCharVector getTypeNameFromHandle(
69             nfc_ndef_record_h handle, nfc_ndef_message_h message_handle = NULL);
70     static UCharVector getIdFromHandle(
71             nfc_ndef_record_h handle, nfc_ndef_message_h message_handle = NULL);
72     static UCharVector getPayloadFromHandle(
73             nfc_ndef_record_h handle, nfc_ndef_message_h message_handle = NULL);
74     static void removeMessageHandle(nfc_ndef_message_h message_handle);
75     static void removeRecordHandle(nfc_ndef_record_h record_handle);
76
77 protected:
78     short m_tnf;
79     UCharVector m_type_name;
80     UCharVector m_id;
81     UCharVector m_payload;
82     nfc_recordtype_e m_record_type;
83     nfc_recordstate_e m_record_state;
84 };
85
86 } // NFC
87 } // DeviceAPI
88
89 #endif // __TIZEN_NFC_NDEFRECORD_H_