Debian Codegraph @

Xpjproject/pjsip/include/pjsua2/json.hpp

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