blob: 987fb87e4dfe261e58dc37fdf9e02254ec27ec7c [file] [log] [blame]
Alexandre Lision0e143012014-01-22 11:02:46 -05001/* $Id: json.hpp 4704 2014-01-16 05:30:46Z ming $ */
2/*
3 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJSUA2_JSON_HPP__
20#define __PJSUA2_JSON_HPP__
21
22/**
23 * @file pjsua2/persistent.hpp
24 * @brief PJSUA2 Persistent Services
25 */
26#include <pjsua2/persistent.hpp>
27#include <pjlib-util/json.h>
28#include <pj/pool.h>
29#include <string>
30
31/** PJSUA2 API is inside pj namespace */
32namespace pj
33{
34
35/**
36 * @defgroup PJSUA2_JSON JSON Persistent Support
37 * @ingroup PJSUA2_PERSISTENT
38 * @{
39 * Provides object serialization and deserialization to/from JSON document.
40 */
41
42using std::string;
43
44/**
45 * Persistent document (file) with JSON format.
46 */
47class JsonDocument : public PersistentDocument
48{
49public:
50 /** Default constructor */
51 JsonDocument();
52
53 /** Destructor */
54 ~JsonDocument();
55
56 /**
57 * Load this document from a file.
58 *
59 * @param filename The file name.
60 */
61 virtual void loadFile(const string &filename) throw(Error);
62
63 /**
64 * Load this document from string.
65 *
66 * @param input The string.
67 */
68 virtual void loadString(const string &input) throw(Error);
69
70 /**
71 * Write this document to a file.
72 *
73 * @param filename The file name.
74 */
75 virtual void saveFile(const string &filename) throw(Error);
76
77 /**
78 * Write this document to string.
79 */
80 virtual string saveString() throw(Error);
81
82 /**
83 * Get the root container node for this document
84 */
85 virtual ContainerNode & getRootContainer() const;
86
87 /**
88 * An internal function to create JSON element.
89 */
90 pj_json_elem* allocElement() const;
91
92 /**
93 * An internal function to get the pool.
94 */
95 pj_pool_t* getPool();
96
97private:
98 pj_caching_pool cp;
99 mutable ContainerNode rootNode;
100 mutable pj_json_elem *root;
101 mutable pj_pool_t *pool;
102
103 void initRoot() const;
104};
105
106
107
108
109/**
110 * @} PJSUA2
111 */
112
113} // namespace pj
114
115
116#endif /* __PJSUA2_JSON_HPP__ */