// Copyright 2017 Paul Nettle. // // This file is part of Gobbledegook. // // Gobbledegook is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Gobbledegook is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Gobbledegook. If not, see . // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // >> // >>> INSIDE THIS FILE // >> // // This is a representation of a D-Bus interface method. // // >> // >>> DISCUSSION // >> // // Methods are identified by their name (such as "ReadValue" or "WriteValue"). They have argument definitions (defined as part of // their interface) that describe the type of arguments passed into the method and returned from the method. // // In addition to the method itself, we also store a callback delegate that is responsible for performing the tasks for this method. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include #include #include #include "DBusMethod.h" namespace ggk { // Instantiate a named method on a given interface (pOwner) with a given set of arguments and a callback delegate 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; } } // Internal method used to generate introspection XML used to describe our services on D-Bus std::string DBusMethod::generateIntrospectionXML(int depth) const { std::string prefix; prefix.insert(0, depth * 2, ' '); std::string xml = std::string(); xml += prefix + "\n"; // Add our input arguments for (const std::string &inArg : getInArgs()) { xml += prefix + " \n"; xml += prefix + " \n"; xml += prefix + " \n"; } const std::string &outArgs = getOutArgs(); if (!outArgs.empty()) { xml += prefix + " \n"; xml += prefix + " \n"; xml += prefix + " \n"; } xml += prefix + "\n"; return xml; } }; // namespace ggk