summaryrefslogtreecommitdiff
path: root/system/include/hardware/avrcp/avrcp_logging_helper.h
blob: ce95337c71bd9e68f4e9209132570ccf8838ab7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <type_traits>

#include "avrcp_common.h"
#include "bt_trace.h"

namespace bluetooth {
namespace avrcp {

#define CASE_RETURN_TEXT(code) \
  case code:                   \
    return #code

inline std::string CTypeText(const CType& type) {
  switch (type) {
    CASE_RETURN_TEXT(CType::CONTROL);
    CASE_RETURN_TEXT(CType::STATUS);
    CASE_RETURN_TEXT(CType::NOTIFY);
    CASE_RETURN_TEXT(CType::ACCEPTED);
    CASE_RETURN_TEXT(CType::REJECTED);
    CASE_RETURN_TEXT(CType::STABLE);
    CASE_RETURN_TEXT(CType::CHANGED);
    CASE_RETURN_TEXT(CType::INTERIM);
    default:
      return "Unknown CType: " + loghex((uint8_t)type);
  }
}

inline std::ostream& operator<<(std::ostream& os, const CType& type) {
  return os << CTypeText(type);
}

inline std::string OpcodeText(const Opcode& opcode) {
  switch (opcode) {
    CASE_RETURN_TEXT(Opcode::VENDOR);
    CASE_RETURN_TEXT(Opcode::UNIT_INFO);
    CASE_RETURN_TEXT(Opcode::SUBUNIT_INFO);
    CASE_RETURN_TEXT(Opcode::PASS_THROUGH);
    default:
      return "Unknown Opcode: " + loghex((uint8_t)opcode);
  }
}

inline std::ostream& operator<<(std::ostream& os, const Opcode& opcode) {
  return os << OpcodeText(opcode);
}

inline std::string CommandPduText(const CommandPdu& pdu) {
  switch (pdu) {
    CASE_RETURN_TEXT(CommandPdu::GET_CAPABILITIES);
    CASE_RETURN_TEXT(CommandPdu::LIST_APPLICATION_SETTING_ATTRIBUTES);
    CASE_RETURN_TEXT(CommandPdu::GET_ELEMENT_ATTRIBUTES);
    CASE_RETURN_TEXT(CommandPdu::GET_PLAY_STATUS);
    CASE_RETURN_TEXT(CommandPdu::REGISTER_NOTIFICATION);
    CASE_RETURN_TEXT(CommandPdu::SET_ABSOLUTE_VOLUME);
    CASE_RETURN_TEXT(CommandPdu::SET_ADDRESSED_PLAYER);
    CASE_RETURN_TEXT(CommandPdu::PLAY_ITEM);
    default:
      return "Unknown Command PDU: " + loghex((uint8_t)pdu);
  }
}

inline std::ostream& operator<<(std::ostream& os, const CommandPdu& pdu) {
  return os << CommandPduText(pdu);
}

inline std::string PacketTypeText(const PacketType& type) {
  switch (type) {
    CASE_RETURN_TEXT(PacketType::SINGLE);
    default:
      return "Unknown Packet Type: " + loghex((uint8_t)type);
  }
}

inline std::ostream& operator<<(std::ostream& os, const PacketType& type) {
  return os << PacketTypeText(type);
}

inline std::string CapabilityText(const Capability& cap) {
  switch (cap) {
    CASE_RETURN_TEXT(Capability::COMPANY_ID);
    CASE_RETURN_TEXT(Capability::EVENTS_SUPPORTED);
    default:
      return "Unknown Capability: " + loghex((uint8_t)cap);
  }
}

inline std::ostream& operator<<(std::ostream& os, const Capability& cap) {
  return os << CapabilityText(cap);
}

inline std::string EventText(const Event& event) {
  switch (event) {
    CASE_RETURN_TEXT(Event::PLAYBACK_STATUS_CHANGED);
    CASE_RETURN_TEXT(Event::TRACK_CHANGED);
    CASE_RETURN_TEXT(Event::PLAYBACK_POS_CHANGED);
    CASE_RETURN_TEXT(Event::PLAYER_APPLICATION_SETTING_CHANGED);
    CASE_RETURN_TEXT(Event::NOW_PLAYING_CONTENT_CHANGED);
    CASE_RETURN_TEXT(Event::AVAILABLE_PLAYERS_CHANGED);
    CASE_RETURN_TEXT(Event::ADDRESSED_PLAYER_CHANGED);
    CASE_RETURN_TEXT(Event::UIDS_CHANGED);
    CASE_RETURN_TEXT(Event::VOLUME_CHANGED);
    default:
      return "Unknown Event: " + loghex((uint8_t)event);
  }
}

inline std::ostream& operator<<(std::ostream& os, const Event& event) {
  return os << EventText(event);
}

inline std::string AttributeText(const Attribute& attr) {
  switch (attr) {
    CASE_RETURN_TEXT(Attribute::TITLE);
    CASE_RETURN_TEXT(Attribute::ARTIST_NAME);
    CASE_RETURN_TEXT(Attribute::ALBUM_NAME);
    CASE_RETURN_TEXT(Attribute::TRACK_NUMBER);
    CASE_RETURN_TEXT(Attribute::TOTAL_NUMBER_OF_TRACKS);
    CASE_RETURN_TEXT(Attribute::GENRE);
    CASE_RETURN_TEXT(Attribute::PLAYING_TIME);
    CASE_RETURN_TEXT(Attribute::DEFAULT_COVER_ART);
    default:
      return "Unknown Attribute Value: " + loghex((uint32_t)attr);
  }
}

inline std::ostream& operator<<(std::ostream& os, const Attribute& attr) {
  return os << AttributeText(attr);
}

inline std::string StatusText(const Status& status) {
  switch (status) {
    CASE_RETURN_TEXT(Status::INVALID_COMMAND);
    CASE_RETURN_TEXT(Status::INVALID_PARAMETER);
    CASE_RETURN_TEXT(Status::PARAMETER_CONTENT_ERROR);
    CASE_RETURN_TEXT(Status::INTERNAL_ERROR);
    CASE_RETURN_TEXT(Status::NO_ERROR);
    CASE_RETURN_TEXT(Status::UIDS_CHANGED);
    CASE_RETURN_TEXT(Status::RESERVED);
    CASE_RETURN_TEXT(Status::INVALID_DIRECTION);
    CASE_RETURN_TEXT(Status::NOT_A_DIRECTORY);
    CASE_RETURN_TEXT(Status::DOES_NOT_EXIST);
    CASE_RETURN_TEXT(Status::INVALID_SCOPE);
    CASE_RETURN_TEXT(Status::RANGE_OUT_OF_BOUNDS);
    CASE_RETURN_TEXT(Status::FOLDER_ITEM_NOT_PLAYABLE);
    CASE_RETURN_TEXT(Status::MEDIA_IN_USE);
    CASE_RETURN_TEXT(Status::NOW_PLAYING_LIST_FULL);
    CASE_RETURN_TEXT(Status::SEARCH_NOT_SUPPORTED);
    CASE_RETURN_TEXT(Status::SEARCH_IN_PROGRESS);
    CASE_RETURN_TEXT(Status::INVALID_PLAYER_ID);
    CASE_RETURN_TEXT(Status::PLAYER_NOT_BROWSABLE);
    CASE_RETURN_TEXT(Status::PLAYER_NOT_ADDRESSED);
    CASE_RETURN_TEXT(Status::NO_VALID_SEARCH_RESULTS);
    CASE_RETURN_TEXT(Status::NO_AVAILABLE_PLAYERS);
    CASE_RETURN_TEXT(Status::ADDRESSED_PLAYER_CHANGED);
    default:
      return "Unknown Status: " + loghex((uint8_t)status);
  }
}

inline std::ostream& operator<<(std::ostream& os, const Status& status) {
  return os << StatusText(status);
}

inline std::string BrowsePduText(const BrowsePdu& pdu) {
  switch (pdu) {
    CASE_RETURN_TEXT(BrowsePdu::SET_BROWSED_PLAYER);
    CASE_RETURN_TEXT(BrowsePdu::GET_FOLDER_ITEMS);
    CASE_RETURN_TEXT(BrowsePdu::CHANGE_PATH);
    CASE_RETURN_TEXT(BrowsePdu::GET_ITEM_ATTRIBUTES);
    default:
      return "Unknown Browse PDU: " + loghex((uint8_t)pdu);
  }
}

inline std::ostream& operator<<(std::ostream& os, const BrowsePdu& pdu) {
  return os << BrowsePduText(pdu);
}

inline std::string ScopeText(const Scope& scope) {
  switch (scope) {
    CASE_RETURN_TEXT(Scope::MEDIA_PLAYER_LIST);
    CASE_RETURN_TEXT(Scope::VFS);
    CASE_RETURN_TEXT(Scope::SEARCH);
    CASE_RETURN_TEXT(Scope::NOW_PLAYING);
    default:
      return "Unknown Scope: " + loghex((uint8_t)scope);
  }
}

inline std::ostream& operator<<(std::ostream& os, const Scope& pdu) {
  return os << ScopeText(pdu);
}

inline std::string DirectionText(const Direction& dir) {
  switch (dir) {
    CASE_RETURN_TEXT(Direction::UP);
    CASE_RETURN_TEXT(Direction::DOWN);
    default:
      return "Unknown Direction: " + loghex((uint8_t)dir);
  }
}

inline std::ostream& operator<<(std::ostream& os, const Direction& dir) {
  return os << DirectionText(dir);
}

inline std::string KeyStateText(const KeyState& state) {
  switch (state) {
    CASE_RETURN_TEXT(KeyState::PUSHED);
    CASE_RETURN_TEXT(KeyState::RELEASED);
    default:
      return "Unknown KeyState: " + loghex((uint8_t)state);
  }
}

inline std::ostream& operator<<(std::ostream& os, const KeyState& dir) {
  return os << KeyStateText(dir);
}

}  // namespace avrcp
}  // namespace bluetooth