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/GattService.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/GattService.cpp (limited to 'src/GattService.cpp') diff --git a/src/GattService.cpp b/src/GattService.cpp new file mode 100644 index 0000000..b5b0b84 --- /dev/null +++ b/src/GattService.cpp @@ -0,0 +1,93 @@ +// 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 +// >> +// +// A GATT Service, used to add services to a Bluetooth server +// +// >> +// >>> DISCUSSION +// >> +// +// A GATT Service is really a collection of +// +// This class is intended to be used within the server description. For an explanation of how this class is used, see the detailed +// description in Server.cpp. +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +#include +#include +#include + +#include "GattService.h" +#include "GattInterface.h" +#include "DBusObject.h" +#include "GattCharacteristic.h" + +// --------------------------------------------------------------------------------------------------------------------------------- +// Representation of a Bluetooth GATT Service +// --------------------------------------------------------------------------------------------------------------------------------- + +// Standard constructor +GattService::GattService(DBusObject &owner, const std::string &name) +: GattInterface(owner, name) +{ +} + +// Returning the parent pops us one level up the hierarchy +DBusObject &GattService::gattServiceEnd() +{ + return getOwner().getParent(); +} + +// Convenience functions to add a GATT characteristic to the hierarchy +// +// We simply add a new child at the given path and add an interface configured as a GATT characteristic to it. The +// new characteristic is declared with a UUID and a variable argument list of flags (in string form.) For a complete and +// up-to-date list of flag values, see: https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/gatt-api.txt +// +// At the time of this writing, the list of flags is as follows: +// +// "broadcast" +// "read" +// "write-without-response" +// "write" +// "notify" +// "indicate" +// "authenticated-signed-writes" +// "reliable-write" +// "writable-auxiliaries" +// "encrypt-read" +// "encrypt-write" +// "encrypt-authenticated-read" +// "encrypt-authenticated-write" +// "secure-read" (Server only) +// "secure-write" (Server only) +// +GattCharacteristic &GattService::gattCharacteristicBegin(const std::string &pathElement, const GattUuid &uuid, const std::vector &flags) +{ + DBusObject &child = owner.addChild(DBusObjectPath(pathElement)); + GattCharacteristic &characteristic = *child.addInterface(std::make_shared(child, *this, "org.bluez.GattCharacteristic1")); + characteristic.addProperty("UUID", uuid); + characteristic.addProperty("Service", owner.getPath()); + characteristic.addProperty("Flags", flags); + return characteristic; +} -- cgit v1.2.3