#include <gio/gio.h>
#include <string>
#include <vector>
#include "DBusMethod.h"
namespace ggk {
DBusMethod::DBusMethod(const DBusInterface *pOwner, const std::string &name, const char *pInArgs[], const char *pOutArgs, Callback callback)
: pOwner(pOwner), name(name), callback(callback)
{
const char **ppInArg = pInArgs;
while(*ppInArg)
{
this->inArgs.push_back(std::string(*ppInArg));
ppInArg++;
}
if (nullptr != pOutArgs)
{
this->outArgs = pOutArgs;
}
}
std::string DBusMethod::generateIntrospectionXML(int depth) const
{
std::string prefix;
prefix.insert(0, depth * 2, ' ');
std::string xml = std::string();
xml += prefix + "<method name='" + getName() + "'>\n";
for (const std::string &inArg : getInArgs())
{
xml += prefix + " <arg type='" + inArg + "' direction='in'>\n";
xml += prefix + " <annotation name='org.gtk.GDBus.C.ForceGVariant' value='true' />\n";
xml += prefix + " </arg>\n";
}
const std::string &outArgs = getOutArgs();
if (!outArgs.empty())
{
xml += prefix + " <arg type='" + outArgs + "' direction='out'>\n";
xml += prefix + " <annotation name='org.gtk.GDBus.C.ForceGVariant' value='true' />\n";
xml += prefix + " </arg>\n";
}
xml += prefix + "</method>\n";
return xml;
}
};