AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
ManagedGVariant.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_BLUETOOTHIMPLEMENTATIONS_BLUEZ_INCLUDE_BLUEZ_MANAGEDGVARIANT_H_
17 #define ALEXA_CLIENT_SDK_BLUETOOTHIMPLEMENTATIONS_BLUEZ_INCLUDE_BLUEZ_MANAGEDGVARIANT_H_
18 
19 #include <memory>
20 #include <string>
21 
22 #include <gio/gio.h>
23 
24 namespace alexaClientSDK {
25 namespace bluetoothImplementations {
26 namespace blueZ {
27 
34 public:
39 
44 
51  explicit ManagedGVariant(GVariant* variant);
52 
59  GVariant** asOutputParameter();
60 
67  GVariant* get();
68 
75  std::string dumpToString(bool withAnnotations);
76 
84 
90  bool hasValue();
91 
96  void swap(ManagedGVariant& other);
97 
98 private:
102  GVariant* m_variant;
103 };
104 
106  if (m_variant) {
107  g_variant_unref(m_variant);
108  }
109 }
110 
111 inline ManagedGVariant::ManagedGVariant() : m_variant{nullptr} {
112 }
113 
114 inline ManagedGVariant::ManagedGVariant(GVariant* variant) : m_variant{variant} {
115  if (variant && g_variant_is_floating(variant)) {
116  g_variant_ref_sink(variant);
117  }
118 }
119 
121  return &m_variant;
122 }
123 
124 inline GVariant* ManagedGVariant::get() {
125  return m_variant;
126 }
127 
128 inline std::string ManagedGVariant::dumpToString(bool withAnnotations) {
129  if (!m_variant) {
130  return "<NULL>";
131  }
132  auto cstring = g_variant_print(m_variant, withAnnotations);
133  std::string result = cstring;
134  g_free(cstring);
135  return result;
136 }
137 
139  if (!m_variant) {
140  return ManagedGVariant();
141  }
142  return ManagedGVariant(g_variant_get_variant(m_variant));
143 }
144 
146  return m_variant != nullptr;
147 }
148 
150  GVariant* temp = other.m_variant;
151  other.m_variant = m_variant;
152  m_variant = temp;
153 }
154 
155 } // namespace blueZ
156 } // namespace bluetoothImplementations
157 } // namespace alexaClientSDK
158 
159 #endif // ALEXA_CLIENT_SDK_BLUETOOTHIMPLEMENTATIONS_BLUEZ_INCLUDE_BLUEZ_MANAGEDGVARIANT_H_
GVariant ** asOutputParameter()
Definition: ManagedGVariant.h:120
::std::string string
Definition: gtest-port.h:1097
std::string dumpToString(bool withAnnotations)
Definition: ManagedGVariant.h:128
GVariant * get()
Definition: ManagedGVariant.h:124
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void swap(ManagedGVariant &other)
Definition: ManagedGVariant.h:149
ManagedGVariant unbox()
Definition: ManagedGVariant.h:138

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0