Fix TIVI-{1191,1192,2108} by implementing a connman 'Agent'.
[profile/ivi/settings-daemon.git] / plugins / connman / connman.cpp
1 /**
2  * @file connman.cpp
3  *
4  * @brief Connman-based settings plugin.
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 #include "connman.hpp"
28
29 #include <settingsd/glib_traits.hpp>
30 #include <settingsd/unique_ptr.hpp>
31
32 #include <cstring>
33 #include <string>
34 #include <stdexcept>
35
36
37 ivi::settings::connman::connman(char const * interface,
38                                 char const * path,
39                                 GDBusConnection * connection)
40   : proxy_(nullptr)
41 {
42   static char const name[] = "net.connman";  // Service
43
44   GError * error = nullptr;
45
46   proxy_ =
47     g_dbus_proxy_new_sync (connection,
48                            G_DBUS_PROXY_FLAGS_NONE,
49                            nullptr, // GDBusInterfaceInfo
50                            name,
51                            path,
52                            interface,
53                            nullptr, // GCancellable
54                            &error);
55
56   unique_ptr<GError> safe_error(error);
57
58   if (proxy_ == nullptr) {
59     g_printerr("Unable to create D-Bus proxy for (\"%s\", \"%s\"): %s\n",
60                interface,
61                path,
62                error->message);
63
64     throw std::runtime_error(error->message);
65   }
66 }
67
68 ivi::settings::connman::~connman()
69 {
70   if (proxy_ != nullptr)
71     g_object_unref(proxy_);
72 }
73
74 GVariant *
75 ivi::settings::connman::set_property(char const * property,
76                                      GVariant * value,
77                                      GError *& error)
78 {
79   static gint const timeout = 5000;  // milliseconds
80
81   return g_dbus_proxy_call_sync(proxy_,
82                                 "SetProperty",     // Method name
83                                 g_variant_new("(sv)",
84                                               property,
85                                               value),
86                                 G_DBUS_CALL_FLAGS_NONE,
87                                 timeout,
88                                 nullptr,  // Not cancellable
89                                 &error);
90 }
91
92
93 // Local Variables:
94 // mode:c++
95 // c-basic-offset:2
96 // indent-tabs-mode: nil
97 // End: