1 | /* |
2 | * Copyright (C) 2015 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(INDEXED_DATABASE) |
29 | |
30 | #include "IDBKeyRangeData.h" |
31 | #include "IDBResourceIdentifier.h" |
32 | |
33 | namespace WebCore { |
34 | |
35 | class IDBTransaction; |
36 | |
37 | namespace IndexedDB { |
38 | enum class CursorDirection; |
39 | enum class CursorSource; |
40 | enum class CursorType; |
41 | } |
42 | |
43 | struct IDBKeyRangeData; |
44 | |
45 | enum class CursorDuplicity { |
46 | Duplicates, |
47 | NoDuplicates, |
48 | }; |
49 | |
50 | class IDBCursorInfo { |
51 | public: |
52 | static IDBCursorInfo objectStoreCursor(IDBTransaction&, uint64_t objectStoreIdentifier, const IDBKeyRangeData&, IndexedDB::CursorDirection, IndexedDB::CursorType); |
53 | static IDBCursorInfo indexCursor(IDBTransaction&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData&, IndexedDB::CursorDirection, IndexedDB::CursorType); |
54 | |
55 | IDBResourceIdentifier identifier() const { return m_cursorIdentifier; } |
56 | uint64_t sourceIdentifier() const { return m_sourceIdentifier; } |
57 | uint64_t objectStoreIdentifier() const { return m_objectStoreIdentifier; } |
58 | |
59 | IndexedDB::CursorSource cursorSource() const { return m_source; } |
60 | IndexedDB::CursorDirection cursorDirection() const { return m_direction; } |
61 | IndexedDB::CursorType cursorType() const { return m_type; } |
62 | const IDBKeyRangeData& range() const { return m_range; } |
63 | |
64 | bool isDirectionForward() const; |
65 | CursorDuplicity duplicity() const; |
66 | |
67 | IDBCursorInfo isolatedCopy() const; |
68 | |
69 | WEBCORE_EXPORT IDBCursorInfo(); |
70 | template<class Encoder> void encode(Encoder&) const; |
71 | template<class Decoder> static bool decode(Decoder&, IDBCursorInfo&); |
72 | |
73 | #if !LOG_DISABLED |
74 | String loggingString() const; |
75 | #endif |
76 | |
77 | private: |
78 | IDBCursorInfo(IDBTransaction&, uint64_t objectStoreIdentifier, const IDBKeyRangeData&, IndexedDB::CursorDirection, IndexedDB::CursorType); |
79 | IDBCursorInfo(IDBTransaction&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData&, IndexedDB::CursorDirection, IndexedDB::CursorType); |
80 | |
81 | IDBCursorInfo(const IDBResourceIdentifier&, const IDBResourceIdentifier&, uint64_t, uint64_t, const IDBKeyRangeData&, IndexedDB::CursorSource, IndexedDB::CursorDirection, IndexedDB::CursorType); |
82 | |
83 | IDBResourceIdentifier m_cursorIdentifier; |
84 | IDBResourceIdentifier m_transactionIdentifier; |
85 | uint64_t m_objectStoreIdentifier { 0 }; |
86 | uint64_t m_sourceIdentifier { 0 }; |
87 | |
88 | IDBKeyRangeData m_range; |
89 | |
90 | IndexedDB::CursorSource m_source; |
91 | IndexedDB::CursorDirection m_direction; |
92 | IndexedDB::CursorType m_type; |
93 | }; |
94 | |
95 | template<class Encoder> |
96 | void IDBCursorInfo::encode(Encoder& encoder) const |
97 | { |
98 | encoder << m_cursorIdentifier << m_transactionIdentifier << m_objectStoreIdentifier << m_sourceIdentifier << m_range; |
99 | |
100 | encoder.encodeEnum(m_source); |
101 | encoder.encodeEnum(m_direction); |
102 | encoder.encodeEnum(m_type); |
103 | } |
104 | |
105 | template<class Decoder> |
106 | bool IDBCursorInfo::decode(Decoder& decoder, IDBCursorInfo& info) |
107 | { |
108 | if (!decoder.decode(info.m_cursorIdentifier)) |
109 | return false; |
110 | |
111 | if (!decoder.decode(info.m_transactionIdentifier)) |
112 | return false; |
113 | |
114 | if (!decoder.decode(info.m_objectStoreIdentifier)) |
115 | return false; |
116 | |
117 | if (!decoder.decode(info.m_sourceIdentifier)) |
118 | return false; |
119 | |
120 | if (!decoder.decode(info.m_range)) |
121 | return false; |
122 | |
123 | if (!decoder.decodeEnum(info.m_source)) |
124 | return false; |
125 | |
126 | if (!decoder.decodeEnum(info.m_direction)) |
127 | return false; |
128 | |
129 | if (!decoder.decodeEnum(info.m_type)) |
130 | return false; |
131 | |
132 | return true; |
133 | } |
134 | |
135 | } // namespace WebCore |
136 | |
137 | #endif // ENABLE(INDEXED_DATABASE) |
138 | |