#include <cstring>
-
ivi::settings::technology::technology(char const * path,
GDBusConnection * connection,
connman_manager & manager)
set_powered(reader, response);
else if (strcmp(name, "scan") == 0)
scan(reader, response);
+ else if (strcmp(name, "tethering") == 0)
+ set_tethering(reader, response);
else {
response.send_error(
std::string("Unrecognized connman technology request name: ")
}
void
+ivi::settings::technology::set_tethering(JsonReader * reader,
+ response_callback & response)
+{
+ char const * ssid = nullptr;
+ char const * password = nullptr;
+ bool enabled = false, have_password = true, have_ssid = true;
+ constexpr char const identifier[] = "TetheringIdentifier";
+ constexpr char const passphrase[] = "TetheringPassphrase";
+ constexpr char const tethering[] = "Tethering";
+
+ if (json_reader_read_member(reader, "enabled")) {
+ enabled = json_reader_get_boolean_value(reader);
+ json_reader_end_element(reader);
+
+ // In case that we are enabling tethering we need to setup also SSID and passphrase
+ // Otherwise those values are not required
+ if (enabled) {
+ have_ssid = json_reader_read_member(reader, "ssid");
+ if (have_ssid) {
+ ssid = json_reader_get_string_value(reader);
+ }
+ json_reader_end_element(reader);
+
+ have_password = json_reader_read_member(reader, "password");
+ if (have_password) {
+ password = json_reader_get_string_value(reader);
+ }
+ json_reader_end_element(reader);
+ }
+
+ if (have_ssid && have_password) {
+ GError * identifier_error = nullptr, *passphrase_error = nullptr, *enabled_error = nullptr;
+ bool identifier_res = true, passphrase_res = true, enabled_res;
+
+ enabled_res = this->set_property(tethering, g_variant_new_boolean(enabled), response, enabled_error);
+
+ if (enabled && enabled_res) {
+ passphrase_res = this->set_property(passphrase, g_variant_new_string(password), response, passphrase_error);
+ identifier_res = this->set_property(identifier, g_variant_new_string(ssid), response, identifier_error);
+ }
+
+ if (enabled_res && identifier_res && passphrase_res) {
+ response.send_response(
+ [enabled](JsonBuilder * builder)
+ {
+ json_builder_set_member_name(builder, "value");
+ json_builder_add_boolean_value(builder, enabled);
+ });
+ } else {
+ std::string failed_part;
+ GError *error;
+
+ if (!enabled_res) {
+ error = enabled_error;
+ failed_part = std::string("status");
+ } else if (!identifier_res) {
+ error = identifier_error;
+ failed_part = std::string("identifier");
+ } else {
+ error = passphrase_error;
+ failed_part = std::string("passphrase");
+ }
+
+ if (error != nullptr) {
+ unique_ptr<GError> safe_error(error);
+ response.send_error(
+ std::string("Unable to set connman::technology tethering ")
+ + failed_part
+ + std::string(": ")
+ + enabled_error->message);
+ } else {
+ response.send_error(std::string("Malformed connman::technology tethering value ") + failed_part);
+ }
+ }
+ } else if (!have_ssid) {
+ response.send_error("connman::technology tether ssid parameter is null.");
+ } else {
+ response.send_error("connman::technology tether password parameter is null.");
+ }
+ } else {
+ response.send_error("connman::technology tether enabled parameter is null.");
+ }
+}
+
+bool
+ivi::settings::technology::set_property(char const * name,
+ GVariant * value,
+ response_callback /* response */,
+ GError *& error)
+{
+ unique_ptr<GVariant> const ret(
+ connman_.set_property(name, value, error));
+
+ return ret != nullptr;
+}
+
+void
ivi::settings::technology::scan(JsonReader * reader,
response_callback & response)
{