summaryrefslogtreecommitdiffstats
path: root/afb-client/bower_components/foundation-icon-fonts/svgs/fi-social-xbox.svg
blob: 1503532e4647f94709a3d3ee4e2a6642c1c70b3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="100px" height="100px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
<g id="g3">
	<path d="M39.749,33.478c-11.464-7.078-18.27-10.103-18.27-10.103C14.977,30.353,11,39.719,11,50.019
		c0,9.229,3.19,17.695,8.522,24.373C19.522,74.393,14.173,60.023,39.749,33.478z"/>
	<path d="M49.971,25.935l0.032,0.018c-0.014-0.01-0.026-0.018-0.026-0.018c15.609-11.279,25.305-5.611,25.305-5.611
		c-6.803-5.846-15.642-9.381-25.305-9.381c-9.659,0-18.498,3.535-25.301,9.381C24.675,20.324,34.371,14.523,49.971,25.935z"/>
	<path d="M49.846,41.947C28.15,58.006,21.824,76.959,21.824,76.959c7.083,7.455,17.08,12.098,28.152,12.098
		c11.101,0,21.114-4.658,28.199-12.141C78.175,76.916,74.055,59.869,49.846,41.947z"/>
	<path d="M89,50.019c0-10.301-3.978-19.666-10.479-26.644c0,0-6.806,3.025-18.27,10.103c25.576,26.545,20.227,40.914,20.227,40.914
		C85.81,67.715,89,59.248,89,50.019z"/>
</g>
</svg>
008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (C) 2018 Konsulko Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "message.h"
#include "messageengine.h"
#include "bluetooth.h"
#include "bluetoothmessage.h"
#include "responsemessage.h"

Bluetooth::Bluetooth (QUrl &url, QObject * parent) :
    QObject(parent),
    m_mloop(nullptr)
{
    m_mloop = new MessageEngine(url);
    QObject::connect(m_mloop, &MessageEngine::connected, this, &Bluetooth::onConnected);
    QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Bluetooth::onDisconnected);
    QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Bluetooth::onMessageReceived);

    uuids.insert("a2dp", "0000110a-0000-1000-8000-00805f9b34fb");
    uuids.insert("avrcp", "0000110e-0000-1000-8000-00805f9b34fb");
    uuids.insert("hfp", "0000111f-0000-1000-8000-00805f9b34fb");
}

Bluetooth::~Bluetooth()
{
    delete m_mloop;
}

void Bluetooth::send_command(QString verb, QJsonObject parameter)
{
    BluetoothMessage *tmsg = new BluetoothMessage();
    tmsg->createRequest(verb, parameter);
    m_mloop->sendMessage(tmsg);
    delete tmsg;
}

void Bluetooth::setPower(bool state)
{
    QJsonObject parameter;
    parameter.insert("powered", state ? "true" : "false");
    send_command("adapter_state", parameter);
}

void Bluetooth::setDiscoverable(bool state)
{
    QJsonObject parameter;
    parameter.insert("discoverable", state ? "true" : "false");
    send_command("adapter_state", parameter);

    m_discoverable = state;

    emit discoverableChanged();
}

void Bluetooth::discovery_command(bool state)
{
    QJsonObject parameter;
    parameter.insert("discovery", state ? "true" : "false");

    set_discovery_filter();

    send_command("adapter_state", parameter);
}

void Bluetooth::start_discovery()
{
    discovery_command(true);

    // temp workaround to list already discovered devices
    send_command("managed_objects", QJsonObject());
}

void Bluetooth::stop_discovery()
{
    discovery_command(false);
}

void Bluetooth::remove_device(QString device)
{
    QJsonObject parameter;
    parameter.insert("device", device);

    send_command("remove_device", parameter);
}

void Bluetooth::pair(QString device)
{
    QJsonObject parameter;
    parameter.insert("device", device);

    send_command("pair", parameter);
}

void Bluetooth::cancel_pair(QString device)
{
    send_command("cancel_pairing", QJsonObject());
}

void Bluetooth::connect(QString device, QString uuid)
{
    QJsonObject parameter;
    uuid = process_uuid(uuid);
    parameter.insert("device", device);
    parameter.insert("uuid", uuid);
    send_command("connect", parameter);
}

void Bluetooth::connect(QString device)
{
    QJsonObject parameter;
    parameter.insert("device", device);
    send_command("connect", parameter);
}

void Bluetooth::disconnect(QString device, QString uuid)
{
    QJsonObject parameter;
    uuid = process_uuid(uuid);
    parameter.insert("device", device);
    parameter.insert("uuid", uuid);
    send_command("disconnect", parameter);
}

void Bluetooth::disconnect(QString device)
{
    QJsonObject parameter;
    parameter.insert("device", device);
    send_command("disconnect", parameter);
}

void Bluetooth::send_confirmation(int pincode)
{
    QJsonObject parameter;
    parameter.insert("pincode", pincode);
    send_command("confirm_pairing", parameter);
}


void Bluetooth::set_discovery_filter()
{
    QStringListIterator eventIterator(uuids.values());
    QJsonObject parameter;
    QJsonArray array;

    while (eventIterator.hasNext())
        array.push_back(eventIterator.next());

    // send inital adapter state + discovery filter
    parameter.insert("filter", array);
    send_command("adapter_state", parameter);
}

void Bluetooth::onConnected()
{
    QStringListIterator eventIterator(events);

    while (eventIterator.hasNext()) {
        QJsonObject parameter;
        parameter.insert("value", eventIterator.next());
        send_command("subscribe", parameter);
    }

    // send initial list
    send_command("managed_objects", QJsonObject());

    // get initial power state
    send_command("adapter_state", QJsonObject());
}

void Bluetooth::onDisconnected()
{
    QStringListIterator eventIterator(events);

    while (eventIterator.hasNext()) {
        QJsonObject parameter;
        parameter.insert("value", eventIterator.next());
        send_command("unsubscribe", parameter);
    }
}

void Bluetooth::processDeviceChangesEvent(QJsonObject data)
{
    QString action = data.value("action").toString();

    if (action == "added")
        emit deviceAddedEvent(data);
    else if (action == "changed") {
        auto powered = data.find("powered").value();

        if (powered.isBool()) {
            m_power = powered.toBool();
            emit powerChanged(m_power);
        } else {
            emit deviceUpdatedEvent(data);
        }
    } else if (action == "removed")
        emit deviceRemovedEvent(data);
}

void Bluetooth::onMessageReceived(MessageType type, Message *msg)
{
    if (msg->isEvent() && type == BluetoothEventMessage) {
        BluetoothMessage *tmsg = qobject_cast<BluetoothMessage*>(msg);

        if (tmsg->isDeviceChangesEvent()) {
            processDeviceChangesEvent(tmsg->eventData());
        } else if (tmsg->isAgentEvent()) {
            emit requestConfirmationEvent(tmsg->eventData());
        }

    } else if (msg->isReply() && type == ResponseRequestMessage) {
        ResponseMessage *tmsg = qobject_cast<ResponseMessage*>(msg);

        if (tmsg->requestVerb() == "managed_objects") {
            emit deviceListEvent(tmsg->replyData());
        } else if (tmsg->requestVerb() == "adapter_state") {
            m_power = tmsg->replyData().value("powered").toBool();
            emit powerChanged(m_power);
        }
    }

    msg->deleteLater();
}