From 06f646aec4dbce64d28bae1be6111bd833f8e79e Mon Sep 17 00:00:00 2001 From: Paul Nettle Date: Fri, 25 Aug 2017 09:30:39 -0500 Subject: Initial version 1.0 --- src/DBusMethod.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/DBusMethod.cpp (limited to 'src/DBusMethod.cpp') diff --git a/src/DBusMethod.cpp b/src/DBusMethod.cpp new file mode 100644 index 0000000..716a454 --- /dev/null +++ b/src/DBusMethod.cpp @@ -0,0 +1,88 @@ +// 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" + +// 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; +} -- cgit v1.2.3