summaryrefslogtreecommitdiff
path: root/include/bundle_cpp.h
blob: 2abc522a8ee2a639268e764cc97daf3a4a9b0fd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef BUNDLE_CPP_H_
#define BUNDLE_CPP_H_

/**
 * @file bundle_cpp.h
 * @brief This file declares API of the bundle C++ library.
 */

/**
 * @addtogroup CORE_LIB_BUNDLE_CPP_MODULE
 * @{
 */

#include <bundle.h>
#include <dlog.h>

#include <cstdio>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#ifdef LOG_TAG
#undef LOG_TAG
#endif

#define LOG_TAG "BUNDLE"

#ifndef EXPORT_API
#define EXPORT_API __attribute__((visibility("default")))
#endif

namespace tizen_base {

/**
 * @brief The class for bundle APIs.
 * @since_tizen 5.5
 */
class EXPORT_API Bundle final {
 public:
  /**
   * @brief The type for raw bundle.
   * @since_tizen 5.5
   */
  using BundleRaw =
      std::pair<std::unique_ptr<bundle_raw, decltype(std::free)*>, int>;

  /**
   * @brief The class for information of keys.
   * @since_tizen 5.5
   */
  class KeyInfo final {
   public:
    /**
     * @brief Constructor.
     * @since_tizen 5.5
     * @param[in] handle The handle for type bundle_keyval_t
     * @param[in] name The key string
     */
    KeyInfo(const bundle_keyval_t* handle,  std::string name);

    /**
     * @brief Constructor.
     * @since_tizen 5.5
     */
    KeyInfo();

    /**
     * @brief Destructor.
     * @since_tizen 5.5
     */
    ~KeyInfo();

    /**
     * @brief Copy-constructor.
     * @since_tizen 5.5
     * @param[in] b The object to copy
    */
    KeyInfo(const KeyInfo& b);

    /**
     * @brief Assignment.
     * @since_tizen 5.5
     * @param[in] b The object to copy
     */
    KeyInfo& operator = (const KeyInfo& b);

    /**
     * @brief Move-constructor.
     * @since_tizen 5.5
     * @param[in] b The object to move
    */
    KeyInfo(KeyInfo&& b) noexcept;

    /**
     * @brief Assignment.
     * @since_tizen 5.5
     * @param[in] b The object to move
     */
    KeyInfo& operator = (KeyInfo&& b) noexcept;

    /**
     * @brief Gets the type of a key-value pair.
     * @since_tizen 5.5
     * @return The type
     */
    bundle_type GetType() const;

    /**
     * @brief Determines whether the type of a key-value pair is an array.
     * @since_tizen 5.5
     * @return True when it is an array
     */
    bool IsArray() const;

    /**
     * @brief Gets the key string.
     * @since_tizen 5.5
     * @return The key string
     */
    const std::string& GetName() const;

   private:
    class Impl;
    std::unique_ptr<Impl> impl_;
  };

  /**
   * @brief Constructor.
   * @since_tizen 5.5
   */
  Bundle();

  /**
   * @brief Constructor.
   * @since_tizen 5.5
   * @param[in] raw The object for BundleRaw
   */
  explicit Bundle(BundleRaw raw);

  /**
   * @brief Constructor.
   * @since_tizen 5.5
   * @param[in] raw The string object for raw bundle
   */
  explicit Bundle(const std::string& raw);

  /**
   * @brief Constructor.
   * @since_tizen 5.5
   * @param[in] b The handle for bundle
   * @param[in] copy True if this object wants to copy it from the handle
   * @param[in] own True if this object owns the handle
   */
  explicit Bundle(bundle* b, bool copy = true, bool own = true);

  /**
   * @brief Destructor.
   * @since_tizen 5.5
   */
  ~Bundle();

  /**
   * @brief Copy-constructor.
   * @since_tizen 5.5
   * @param[in] b The object to copy
   */
  Bundle(const Bundle& b);

  /**
   * @brief Assignment.
   * @since_tizen 5.5
   * @param[in] b The object to copy
   */
  Bundle& operator = (const Bundle& b);

  /**
   * @brief Move-constructor.
   * @since_tizen 5.5
   * @param[in] b The object to move
   */
  Bundle(Bundle&& b) noexcept;

  /**
   * @brief Assignment.
   * @since_tizen 5.5
   * @param[in] b The object to move
   */
  Bundle& operator = (Bundle&& b) noexcept;

  /**
   * @brief Gets keys in bundle object.
   * @since_tizen 5.5
   * @return A string array of object KeyInfo
  */
  std::vector<KeyInfo> GetKeys();

  /**
   * @brief Adds a string type key-value pair into a bundle.
   * @since_tizen 5.5
   * @param[in] key The string key
   * @param[in] val The string value
   * @return The operation result
   * @retval BUNDLE_ERROR_NONE Success
   * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
   * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
   * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
  */
  int Add(const std::string& key, const std::string& val);

  /**
   * @brief Adds a string type key-value pair into a bundle.
   * @since_tizen 5.5
   * @param[in] key The string key
   * @param[in] val The array of strings
   * @return The operation result
   * @retval BUNDLE_ERROR_NONE Success
   * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
   * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
   * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
  */
  int Add(const std::string& key, const std::vector<std::string>& val);

  /**
   * @brief Adds a string type key-value pair into a bundle.
   * @since_tizen 5.5
   * @param[in] key The string key
   * @param[in] val The array of bytes
   * @return The operation result
   * @retval BUNDLE_ERROR_NONE Success
   * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
   * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
   * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
  */
  int Add(const std::string& key, const std::vector<unsigned char>& val);

  /**
   * @brief Deletes a key-value object with the given key.
   * @since_tizen 5.5
   * @param[in] key The string key
   * @return The operation result
   * @retval BUNDLE_ERROR_NONE Success
   * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
   * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
  */
  int Delete(const std::string& key);

  /**
   * @brief Gets a string from the key.
   * @since_tizen 5.5
   * @param[in] key The string key
   * @return The string
  */
  std::string GetString(const std::string& key) const;

  /**
   * @brief Gets strings from the key.
   * @since_tizen 5.5
   * @param[in] key The string key
   * @return The array of strings
  */
  std::vector<std::string> GetStringArray(const std::string& key) const;

  /**
   * @brief Gets bytes from the key.
   * @since_tizen 5.5
   * @param[in] key The string key
   * @return Bytes
  */
  std::vector<unsigned char> GetByte(const std::string& key) const;

  /**
   * @brief Converts this object to BundleRaw type.
   * @since_tizen 5.5
   * @return The object of BundleRaw
  */
  BundleRaw ToRaw();

  /**
   * @brief Gets the count of keys.
   * @since_tizen 5.5
   * @return The count
  */
  int GetCount() const;

  /**
   * @brief Gets the data type from the key.
   * @since_tizen 5.5
   * @param[in] key The string key
   * @return The data type
  */
  bundle_type GetType(const std::string& key) const;

  /**
   * @brief Gets the handle for bundle APIs.
   * @since_tizen 5.5
   * @return The handle for bundle
  */
  bundle* GetHandle() const;

  /**
   * @brief Moves this object into the bundle handle.
   * @since_tizen 5.5
   * @return The handle for bundle
  */
  bundle* Detach();

 private:
  class Impl;
  std::unique_ptr<Impl> impl_;
};

}  // namespace tizen_base

/**
 * @}
 */

#endif  // BUNDLE_CPP_H_