TIVI-1924: Initial commit of IVI settings daemon.
[profile/ivi/settings-daemon.git] / include / settingsd / glib_traits.hpp
1 /**
2  * @file glib_traits.hpp
3  *
4  * @brief @c GLib traits.
5  *
6  * @author Ossama Othman @<ossama.othman@@intel.com@>
7  *
8  * @copyright @par
9  * Copyright 2013 Intel Corporation All Rights Reserved.
10  * @par
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation;
14  * version 2.1 of the License.
15  * @par
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  * @par
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA  02110-1301  USA
25  */
26
27 #ifndef IVI_SETTINGS_GLIB_TRAITS_HPP
28 #define IVI_SETTINGS_GLIB_TRAITS_HPP
29
30 #include <glib.h>
31 #include <json-glib/json-glib.h>
32
33
34 namespace ivi
35 {
36   namespace settings
37   {
38     template<typename T> struct traits;
39
40     template<>
41     struct traits<GVariant>
42     {
43       static void
44       release(GVariant * p)
45       {
46         if (p != nullptr)
47           g_variant_unref(p);
48       }
49     };
50
51     template<>
52     struct traits<GVariantIter>
53     {
54       static void release(GVariantIter * p) { g_variant_iter_free(p); }
55     };
56
57     template<>
58     struct traits<gchar>
59     {
60       static void release(gchar * p) { g_free(p); }
61     };
62
63     template<>
64     struct traits<GError>
65     {
66       static void release(GError * p)
67       {
68         if (p != nullptr)
69           g_error_free(p);
70       }
71     };
72
73     template<>
74     struct traits<GMainLoop>
75     {
76       static void release(GMainLoop * p)
77       {
78         if (p != nullptr)
79           g_main_loop_unref(p);
80       }
81     };
82
83   }
84 }
85
86
87 #endif /* IVI_SETTINGS_GLIB_TRAITS_HPP */
88
89
90 // Local Variables:
91 // mode:c++
92 // c-basic-offset:2
93 // indent-tabs-mode: nil
94 // End: