#include "GattInterface.h"
#include "GattProperty.h"
#include "DBusObject.h"
#include "Logger.h"
namespace ggk {
GattInterface::GattInterface(DBusObject &owner, const std::string &name)
: DBusInterface(owner, name)
{
}
GattInterface::~GattInterface()
{
}
const std::list<GattProperty> &GattInterface::getProperties() const
{
return properties;
}
void GattInterface::methodReturnVariant(GDBusMethodInvocation *pInvocation, GVariant *pVariant, bool wrapInTuple) const
{
if (wrapInTuple)
{
pVariant = g_variant_new_tuple(&pVariant, 1);
}
g_dbus_method_invocation_return_value(pInvocation, pVariant);
}
const GattProperty *GattInterface::findProperty(const std::string &name) const
{
for (const GattProperty &property : properties)
{
if (property.getName() == name)
{
return &property;
}
}
return nullptr;
}
std::string GattInterface::generateIntrospectionXML(int depth) const
{
std::string prefix;
prefix.insert(0, depth * 2, ' ');
std::string xml = std::string();
if (methods.size() && getProperties().empty())
{
xml += prefix + "<interface name='" + getName() + "' />\n";
}
else
{
xml += prefix + "<interface name='" + getName() + "'>\n";
for (const DBusMethod &method : methods)
{
xml += method.generateIntrospectionXML(depth + 1);
}
for (const GattProperty &property : getProperties())
{
xml += property.generateIntrospectionXML(depth + 1);
}
xml += prefix + "</interface>\n";
}
return xml;
}
};