blob: 707d3a622de06cc968f3e1207cd1c7b2dec8af88 [file] [log] [blame]
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include <vector>
#include <base/macros.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
namespace chromeos_dbus_bindings {
class DbusSignature {
virtual ~DbusSignature() = default;
// Returns a C++ typename in |output| for a D-Bus signature in |signature|
// and returns true on success. Returns false otherwise.
bool Parse(const std::string& signature, std::string* output);
void set_object_path_typename(const std::string& object_path_typename) {
object_path_typename_ = object_path_typename;
friend class DbusSignatureTest;
FRIEND_TEST(DbusSignatureTest, DefaultObjectPathTypename);
FRIEND_TEST(DbusSignatureTest, ParseSuccesses);
// Typenames are C++ syntax types.
static const char kArrayTypename[];
static const char kBooleanTypename[];
static const char kByteTypename[];
static const char kDefaultObjectPathTypename[];
static const char kDictTypename[];
static const char kDoubleTypename[];
static const char kSigned16Typename[];
static const char kSigned32Typename[];
static const char kSigned64Typename[];
static const char kStringTypename[];
static const char kUnixFdTypename[];
static const char kUnsigned16Typename[];
static const char kUnsigned32Typename[];
static const char kUnsigned64Typename[];
static const char kVariantTypename[];
// Returns the C++ type name for the next D-Bus signature in the string at
// |signature| in |output|, as well as the next position within the string
// that parsing should continue |next|. It is not an error to pass a
// pointer to |signature| or nullptr as |next|. Returns true on success.
bool GetTypenameForSignature(std::string::const_iterator signature,
std::string::const_iterator end,
std::string::const_iterator* next,
std::string* output);
// Utility task for GetTypenameForSignature() which handles array objects
// and decodes them into a map or vector depending on the encoded sub-elements
// in the array. The arguments and return values are the same
// as GetTypenameForSignature().
bool GetArrayTypenameForSignature(std::string::const_iterator signature,
std::string::const_iterator end,
std::string::const_iterator* next,
std::string* output);
// The C++ typename to be used for D-Bus object pathnames.
std::string object_path_typename_;
} // namespace chromeos_dbus_bindings