| 1 | /* |
| 2 | * Copyright (c) 2020-2021 Philippe Proulx <pproulx@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | */ |
| 6 | |
| 7 | #ifndef BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP |
| 8 | #define BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP |
| 9 | |
| 10 | #include <cstdint> |
| 11 | #include <type_traits> |
| 12 | |
| 13 | #include <babeltrace2/babeltrace.h> |
| 14 | |
| 15 | #include "common/macros.h" |
| 16 | #include "cpp-common/bt2c/c-string-view.hpp" |
| 17 | #include "cpp-common/bt2s/optional.hpp" |
| 18 | |
| 19 | #include "borrowed-object.hpp" |
| 20 | #include "clock-class.hpp" |
| 21 | #include "field-class.hpp" |
| 22 | #include "field.hpp" |
| 23 | #include "internal/utils.hpp" |
| 24 | #include "optional-borrowed-object.hpp" |
| 25 | #include "shared-object.hpp" |
| 26 | #include "value.hpp" |
| 27 | |
| 28 | namespace bt2 { |
| 29 | |
| 30 | template <typename LibObjT> |
| 31 | class CommonEvent; |
| 32 | |
| 33 | template <typename LibObjT> |
| 34 | class CommonPacket; |
| 35 | |
| 36 | template <typename LibObjT> |
| 37 | class CommonStream; |
| 38 | |
| 39 | template <typename LibObjT> |
| 40 | class CommonTrace; |
| 41 | |
| 42 | template <typename LibObjT> |
| 43 | class CommonEventClass; |
| 44 | |
| 45 | template <typename LibObjT> |
| 46 | class CommonStreamClass; |
| 47 | |
| 48 | template <typename LibObjT> |
| 49 | class CommonTraceClass; |
| 50 | |
| 51 | namespace internal { |
| 52 | |
| 53 | template <typename LibObjT> |
| 54 | struct CommonEventSpec; |
| 55 | |
| 56 | /* Functions specific to mutable events */ |
| 57 | template <> |
| 58 | struct CommonEventSpec<bt_event> final |
| 59 | { |
| 60 | static bt_event_class *cls(bt_event * const libObjPtr) noexcept |
| 61 | { |
| 62 | return bt_event_borrow_class(libObjPtr); |
| 63 | } |
| 64 | |
| 65 | static bt_stream *stream(bt_event * const libObjPtr) noexcept |
| 66 | { |
| 67 | return bt_event_borrow_stream(libObjPtr); |
| 68 | } |
| 69 | |
| 70 | static bt_packet *packet(bt_event * const libObjPtr) noexcept |
| 71 | { |
| 72 | return bt_event_borrow_packet(libObjPtr); |
| 73 | } |
| 74 | |
| 75 | static bt_field *payloadField(bt_event * const libObjPtr) noexcept |
| 76 | { |
| 77 | return bt_event_borrow_payload_field(libObjPtr); |
| 78 | } |
| 79 | |
| 80 | static bt_field *specificContextField(bt_event * const libObjPtr) noexcept |
| 81 | { |
| 82 | return bt_event_borrow_specific_context_field(libObjPtr); |
| 83 | } |
| 84 | |
| 85 | static bt_field *commonContextField(bt_event * const libObjPtr) noexcept |
| 86 | { |
| 87 | return bt_event_borrow_common_context_field(libObjPtr); |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | /* Functions specific to constant events */ |
| 92 | template <> |
| 93 | struct CommonEventSpec<const bt_event> final |
| 94 | { |
| 95 | static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept |
| 96 | { |
| 97 | return bt_event_borrow_class_const(libObjPtr); |
| 98 | } |
| 99 | |
| 100 | static const bt_stream *stream(const bt_event * const libObjPtr) noexcept |
| 101 | { |
| 102 | return bt_event_borrow_stream_const(libObjPtr); |
| 103 | } |
| 104 | |
| 105 | static const bt_packet *packet(const bt_event * const libObjPtr) noexcept |
| 106 | { |
| 107 | return bt_event_borrow_packet_const(libObjPtr); |
| 108 | } |
| 109 | |
| 110 | static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept |
| 111 | { |
| 112 | return bt_event_borrow_payload_field_const(libObjPtr); |
| 113 | } |
| 114 | |
| 115 | static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept |
| 116 | { |
| 117 | return bt_event_borrow_specific_context_field_const(libObjPtr); |
| 118 | } |
| 119 | |
| 120 | static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept |
| 121 | { |
| 122 | return bt_event_borrow_common_context_field_const(libObjPtr); |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | template <typename LibObjT> |
| 127 | using DepStructField = DepType<LibObjT, StructureField, ConstStructureField>; |
| 128 | |
| 129 | } /* namespace internal */ |
| 130 | |
| 131 | template <typename LibObjT> |
| 132 | class CommonEvent final : public BorrowedObject<LibObjT> |
| 133 | { |
| 134 | private: |
| 135 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 136 | using _Spec = internal::CommonEventSpec<LibObjT>; |
| 137 | using _Packet = internal::DepPacket<LibObjT>; |
| 138 | using _Stream = internal::DepStream<LibObjT>; |
| 139 | using _StructureField = internal::DepStructField<LibObjT>; |
| 140 | |
| 141 | public: |
| 142 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 143 | |
| 144 | using Class = internal::DepType<LibObjT, CommonEventClass<bt_event_class>, |
| 145 | CommonEventClass<const bt_event_class>>; |
| 146 | |
| 147 | explicit CommonEvent(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
| 148 | { |
| 149 | } |
| 150 | |
| 151 | template <typename OtherLibObjT> |
| 152 | CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event} |
| 153 | { |
| 154 | } |
| 155 | |
| 156 | template <typename OtherLibObjT> |
| 157 | CommonEvent<LibObjT> operator=(const CommonEvent<OtherLibObjT> event) noexcept |
| 158 | { |
| 159 | _ThisBorrowedObject::operator=(event); |
| 160 | return *this; |
| 161 | } |
| 162 | |
| 163 | CommonEvent<const bt_event> asConst() const noexcept |
| 164 | { |
| 165 | return CommonEvent<const bt_event> {*this}; |
| 166 | } |
| 167 | |
| 168 | Class cls() const noexcept; |
| 169 | _Stream stream() const noexcept; |
| 170 | OptionalBorrowedObject<_Packet> packet() const noexcept; |
| 171 | |
| 172 | OptionalBorrowedObject<_StructureField> payloadField() const noexcept |
| 173 | { |
| 174 | return _Spec::payloadField(this->libObjPtr()); |
| 175 | } |
| 176 | |
| 177 | OptionalBorrowedObject<_StructureField> specificContextField() const noexcept |
| 178 | { |
| 179 | return _Spec::specificContextField(this->libObjPtr()); |
| 180 | } |
| 181 | |
| 182 | OptionalBorrowedObject<_StructureField> commonContextField() const noexcept |
| 183 | { |
| 184 | return _Spec::commonContextField(this->libObjPtr()); |
| 185 | } |
| 186 | }; |
| 187 | |
| 188 | using Event = CommonEvent<bt_event>; |
| 189 | using ConstEvent = CommonEvent<const bt_event>; |
| 190 | |
| 191 | namespace internal { |
| 192 | |
| 193 | struct EventTypeDescr |
| 194 | { |
| 195 | using Const = ConstEvent; |
| 196 | using NonConst = Event; |
| 197 | }; |
| 198 | |
| 199 | template <> |
| 200 | struct TypeDescr<Event> : public EventTypeDescr |
| 201 | { |
| 202 | }; |
| 203 | |
| 204 | template <> |
| 205 | struct TypeDescr<ConstEvent> : public EventTypeDescr |
| 206 | { |
| 207 | }; |
| 208 | |
| 209 | struct PacketRefFuncs final |
| 210 | { |
| 211 | static void get(const bt_packet * const libObjPtr) noexcept |
| 212 | { |
| 213 | bt_packet_get_ref(libObjPtr); |
| 214 | } |
| 215 | |
| 216 | static void put(const bt_packet * const libObjPtr) noexcept |
| 217 | { |
| 218 | bt_packet_put_ref(libObjPtr); |
| 219 | } |
| 220 | }; |
| 221 | |
| 222 | template <typename LibObjT> |
| 223 | struct CommonPacketSpec; |
| 224 | |
| 225 | /* Functions specific to mutable packets */ |
| 226 | template <> |
| 227 | struct CommonPacketSpec<bt_packet> final |
| 228 | { |
| 229 | static bt_stream *stream(bt_packet * const libObjPtr) noexcept |
| 230 | { |
| 231 | return bt_packet_borrow_stream(libObjPtr); |
| 232 | } |
| 233 | |
| 234 | static bt_field *contextField(bt_packet * const libObjPtr) noexcept |
| 235 | { |
| 236 | return bt_packet_borrow_context_field(libObjPtr); |
| 237 | } |
| 238 | }; |
| 239 | |
| 240 | /* Functions specific to constant packets */ |
| 241 | template <> |
| 242 | struct CommonPacketSpec<const bt_packet> final |
| 243 | { |
| 244 | static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept |
| 245 | { |
| 246 | return bt_packet_borrow_stream_const(libObjPtr); |
| 247 | } |
| 248 | |
| 249 | static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept |
| 250 | { |
| 251 | return bt_packet_borrow_context_field_const(libObjPtr); |
| 252 | } |
| 253 | }; |
| 254 | |
| 255 | } /* namespace internal */ |
| 256 | |
| 257 | template <typename LibObjT> |
| 258 | class CommonPacket final : public BorrowedObject<LibObjT> |
| 259 | { |
| 260 | private: |
| 261 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 262 | using _Spec = internal::CommonPacketSpec<LibObjT>; |
| 263 | using _Stream = internal::DepStream<LibObjT>; |
| 264 | using _StructureField = internal::DepStructField<LibObjT>; |
| 265 | |
| 266 | public: |
| 267 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 268 | using Shared = SharedObject<CommonPacket, LibObjT, internal::PacketRefFuncs>; |
| 269 | |
| 270 | explicit CommonPacket(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
| 271 | { |
| 272 | } |
| 273 | |
| 274 | template <typename OtherLibObjT> |
| 275 | CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet} |
| 276 | { |
| 277 | } |
| 278 | |
| 279 | template <typename OtherLibObjT> |
| 280 | CommonPacket operator=(const CommonPacket<OtherLibObjT> packet) noexcept |
| 281 | { |
| 282 | _ThisBorrowedObject::operator=(packet); |
| 283 | return *this; |
| 284 | } |
| 285 | |
| 286 | CommonPacket<const bt_packet> asConst() const noexcept |
| 287 | { |
| 288 | return CommonPacket<const bt_packet> {*this}; |
| 289 | } |
| 290 | |
| 291 | _Stream stream() const noexcept; |
| 292 | |
| 293 | OptionalBorrowedObject<_StructureField> contextField() const noexcept |
| 294 | { |
| 295 | return _Spec::contextField(this->libObjPtr()); |
| 296 | } |
| 297 | |
| 298 | Shared shared() const noexcept |
| 299 | { |
| 300 | return Shared::createWithRef(*this); |
| 301 | } |
| 302 | }; |
| 303 | |
| 304 | using Packet = CommonPacket<bt_packet>; |
| 305 | using ConstPacket = CommonPacket<const bt_packet>; |
| 306 | |
| 307 | namespace internal { |
| 308 | |
| 309 | struct PacketTypeDescr |
| 310 | { |
| 311 | using Const = ConstPacket; |
| 312 | using NonConst = Packet; |
| 313 | }; |
| 314 | |
| 315 | template <> |
| 316 | struct TypeDescr<Packet> : public PacketTypeDescr |
| 317 | { |
| 318 | }; |
| 319 | |
| 320 | template <> |
| 321 | struct TypeDescr<ConstPacket> : public PacketTypeDescr |
| 322 | { |
| 323 | }; |
| 324 | |
| 325 | } /* namespace internal */ |
| 326 | |
| 327 | template <typename LibObjT> |
| 328 | OptionalBorrowedObject<typename CommonEvent<LibObjT>::_Packet> |
| 329 | CommonEvent<LibObjT>::packet() const noexcept |
| 330 | { |
| 331 | return _Spec::packet(this->libObjPtr()); |
| 332 | } |
| 333 | |
| 334 | namespace internal { |
| 335 | |
| 336 | struct StreamRefFuncs final |
| 337 | { |
| 338 | static void get(const bt_stream * const libObjPtr) noexcept |
| 339 | { |
| 340 | bt_stream_get_ref(libObjPtr); |
| 341 | } |
| 342 | |
| 343 | static void put(const bt_stream * const libObjPtr) noexcept |
| 344 | { |
| 345 | bt_stream_put_ref(libObjPtr); |
| 346 | } |
| 347 | }; |
| 348 | |
| 349 | template <typename LibObjT> |
| 350 | struct CommonStreamSpec; |
| 351 | |
| 352 | /* Functions specific to mutable streams */ |
| 353 | template <> |
| 354 | struct CommonStreamSpec<bt_stream> final |
| 355 | { |
| 356 | static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept |
| 357 | { |
| 358 | return bt_stream_borrow_class(libObjPtr); |
| 359 | } |
| 360 | |
| 361 | static bt_trace *trace(bt_stream * const libObjPtr) noexcept |
| 362 | { |
| 363 | return bt_stream_borrow_trace(libObjPtr); |
| 364 | } |
| 365 | |
| 366 | static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept |
| 367 | { |
| 368 | return bt_stream_borrow_user_attributes(libObjPtr); |
| 369 | } |
| 370 | }; |
| 371 | |
| 372 | /* Functions specific to constant streams */ |
| 373 | template <> |
| 374 | struct CommonStreamSpec<const bt_stream> final |
| 375 | { |
| 376 | static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept |
| 377 | { |
| 378 | return bt_stream_borrow_class_const(libObjPtr); |
| 379 | } |
| 380 | |
| 381 | static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept |
| 382 | { |
| 383 | return bt_stream_borrow_trace_const(libObjPtr); |
| 384 | } |
| 385 | |
| 386 | static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept |
| 387 | { |
| 388 | return bt_stream_borrow_user_attributes_const(libObjPtr); |
| 389 | } |
| 390 | }; |
| 391 | |
| 392 | } /* namespace internal */ |
| 393 | |
| 394 | template <typename LibObjT> |
| 395 | class CommonStream final : public BorrowedObject<LibObjT> |
| 396 | { |
| 397 | private: |
| 398 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 399 | using _Spec = internal::CommonStreamSpec<LibObjT>; |
| 400 | using _Trace = internal::DepType<LibObjT, CommonTrace<bt_trace>, CommonTrace<const bt_trace>>; |
| 401 | |
| 402 | public: |
| 403 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 404 | using Shared = SharedObject<CommonStream, LibObjT, internal::StreamRefFuncs>; |
| 405 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 406 | |
| 407 | using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>, |
| 408 | CommonStreamClass<const bt_stream_class>>; |
| 409 | |
| 410 | explicit CommonStream(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
| 411 | { |
| 412 | } |
| 413 | |
| 414 | template <typename OtherLibObjT> |
| 415 | CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream} |
| 416 | { |
| 417 | } |
| 418 | |
| 419 | template <typename OtherLibObjT> |
| 420 | CommonStream operator=(const CommonStream<OtherLibObjT> stream) noexcept |
| 421 | { |
| 422 | _ThisBorrowedObject::operator=(stream); |
| 423 | return *this; |
| 424 | } |
| 425 | |
| 426 | CommonStream<const bt_stream> asConst() const noexcept |
| 427 | { |
| 428 | return CommonStream<const bt_stream> {*this}; |
| 429 | } |
| 430 | |
| 431 | Packet::Shared createPacket() const |
| 432 | { |
| 433 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`."); |
| 434 | |
| 435 | const auto libObjPtr = bt_packet_create(this->libObjPtr()); |
| 436 | |
| 437 | internal::validateCreatedObjPtr(libObjPtr); |
| 438 | return Packet::Shared::createWithoutRef(libObjPtr); |
| 439 | } |
| 440 | |
| 441 | Class cls() const noexcept; |
| 442 | _Trace trace() const noexcept; |
| 443 | |
| 444 | std::uint64_t id() const noexcept |
| 445 | { |
| 446 | return bt_stream_get_id(this->libObjPtr()); |
| 447 | } |
| 448 | |
| 449 | CommonStream name(const bt2c::CStringView name) const |
| 450 | { |
| 451 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`."); |
| 452 | |
| 453 | const auto status = bt_stream_set_name(this->libObjPtr(), name); |
| 454 | |
| 455 | if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) { |
| 456 | throw MemoryError {}; |
| 457 | } |
| 458 | |
| 459 | return *this; |
| 460 | } |
| 461 | |
| 462 | bt2c::CStringView name() const noexcept |
| 463 | { |
| 464 | return bt_stream_get_name(this->libObjPtr()); |
| 465 | } |
| 466 | |
| 467 | template <typename LibValT> |
| 468 | CommonStream userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 469 | { |
| 470 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`."); |
| 471 | |
| 472 | bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
| 473 | return *this; |
| 474 | } |
| 475 | |
| 476 | UserAttributes userAttributes() const noexcept |
| 477 | { |
| 478 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
| 479 | } |
| 480 | |
| 481 | Shared shared() const noexcept |
| 482 | { |
| 483 | return Shared::createWithRef(*this); |
| 484 | } |
| 485 | }; |
| 486 | |
| 487 | using Stream = CommonStream<bt_stream>; |
| 488 | using ConstStream = CommonStream<const bt_stream>; |
| 489 | |
| 490 | namespace internal { |
| 491 | |
| 492 | struct StreamTypeDescr |
| 493 | { |
| 494 | using Const = ConstStream; |
| 495 | using NonConst = Stream; |
| 496 | }; |
| 497 | |
| 498 | template <> |
| 499 | struct TypeDescr<Stream> : public StreamTypeDescr |
| 500 | { |
| 501 | }; |
| 502 | |
| 503 | template <> |
| 504 | struct TypeDescr<ConstStream> : public StreamTypeDescr |
| 505 | { |
| 506 | }; |
| 507 | |
| 508 | } /* namespace internal */ |
| 509 | |
| 510 | template <typename LibObjT> |
| 511 | typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept |
| 512 | { |
| 513 | return _Stream {_Spec::stream(this->libObjPtr())}; |
| 514 | } |
| 515 | |
| 516 | template <typename LibObjT> |
| 517 | typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept |
| 518 | { |
| 519 | return _Stream {_Spec::stream(this->libObjPtr())}; |
| 520 | } |
| 521 | |
| 522 | namespace internal { |
| 523 | |
| 524 | struct TraceRefFuncs final |
| 525 | { |
| 526 | static void get(const bt_trace * const libObjPtr) noexcept |
| 527 | { |
| 528 | bt_trace_get_ref(libObjPtr); |
| 529 | } |
| 530 | |
| 531 | static void put(const bt_trace * const libObjPtr) noexcept |
| 532 | { |
| 533 | bt_trace_put_ref(libObjPtr); |
| 534 | } |
| 535 | }; |
| 536 | |
| 537 | template <typename LibObjT> |
| 538 | struct CommonTraceSpec; |
| 539 | |
| 540 | /* Functions specific to mutable traces */ |
| 541 | template <> |
| 542 | struct CommonTraceSpec<bt_trace> final |
| 543 | { |
| 544 | static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept |
| 545 | { |
| 546 | return bt_trace_borrow_class(libObjPtr); |
| 547 | } |
| 548 | |
| 549 | static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept |
| 550 | { |
| 551 | return bt_trace_borrow_stream_by_index(libObjPtr, index); |
| 552 | } |
| 553 | |
| 554 | static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept |
| 555 | { |
| 556 | return bt_trace_borrow_stream_by_id(libObjPtr, id); |
| 557 | } |
| 558 | |
| 559 | static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept |
| 560 | { |
| 561 | return bt_trace_borrow_user_attributes(libObjPtr); |
| 562 | } |
| 563 | }; |
| 564 | |
| 565 | /* Functions specific to constant traces */ |
| 566 | template <> |
| 567 | struct CommonTraceSpec<const bt_trace> final |
| 568 | { |
| 569 | static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept |
| 570 | { |
| 571 | return bt_trace_borrow_class_const(libObjPtr); |
| 572 | } |
| 573 | |
| 574 | static const bt_stream *streamByIndex(const bt_trace * const libObjPtr, |
| 575 | const std::uint64_t index) noexcept |
| 576 | { |
| 577 | return bt_trace_borrow_stream_by_index_const(libObjPtr, index); |
| 578 | } |
| 579 | |
| 580 | static const bt_stream *streamById(const bt_trace * const libObjPtr, |
| 581 | const std::uint64_t id) noexcept |
| 582 | { |
| 583 | return bt_trace_borrow_stream_by_id_const(libObjPtr, id); |
| 584 | } |
| 585 | |
| 586 | static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept |
| 587 | { |
| 588 | return bt_trace_borrow_user_attributes_const(libObjPtr); |
| 589 | } |
| 590 | }; |
| 591 | |
| 592 | } /* namespace internal */ |
| 593 | |
| 594 | template <typename LibObjT> |
| 595 | class CommonTrace final : public BorrowedObject<LibObjT> |
| 596 | { |
| 597 | private: |
| 598 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 599 | using _Spec = internal::CommonTraceSpec<LibObjT>; |
| 600 | using _Stream = internal::DepStream<LibObjT>; |
| 601 | |
| 602 | public: |
| 603 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 604 | using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>; |
| 605 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 606 | |
| 607 | using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>, |
| 608 | CommonTraceClass<const bt_trace_class>>; |
| 609 | |
| 610 | struct ConstEnvironmentEntry |
| 611 | { |
| 612 | bt2c::CStringView name; |
| 613 | ConstValue value; |
| 614 | }; |
| 615 | |
| 616 | explicit CommonTrace(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
| 617 | { |
| 618 | } |
| 619 | |
| 620 | template <typename OtherLibObjT> |
| 621 | CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace} |
| 622 | { |
| 623 | } |
| 624 | |
| 625 | template <typename OtherLibObjT> |
| 626 | CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept |
| 627 | { |
| 628 | _ThisBorrowedObject::operator=(trace); |
| 629 | return *this; |
| 630 | } |
| 631 | |
| 632 | CommonTrace<const bt_trace> asConst() const noexcept |
| 633 | { |
| 634 | return CommonTrace<const bt_trace> {*this}; |
| 635 | } |
| 636 | |
| 637 | Class cls() const noexcept; |
| 638 | |
| 639 | CommonTrace name(const bt2c::CStringView name) const |
| 640 | { |
| 641 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`."); |
| 642 | |
| 643 | const auto status = bt_trace_set_name(this->libObjPtr(), name); |
| 644 | |
| 645 | if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) { |
| 646 | throw MemoryError {}; |
| 647 | } |
| 648 | |
| 649 | return *this; |
| 650 | } |
| 651 | |
| 652 | bt2c::CStringView name() const noexcept |
| 653 | { |
| 654 | return bt_trace_get_name(this->libObjPtr()); |
| 655 | } |
| 656 | |
| 657 | CommonTrace uuid(const bt2c::UuidView& uuid) const noexcept |
| 658 | { |
| 659 | bt_trace_set_uuid(this->libObjPtr(), uuid.begin()); |
| 660 | return *this; |
| 661 | } |
| 662 | |
| 663 | bt2s::optional<bt2c::UuidView> uuid() const noexcept |
| 664 | { |
| 665 | const auto uuid = bt_trace_get_uuid(this->libObjPtr()); |
| 666 | |
| 667 | if (uuid) { |
| 668 | return bt2c::UuidView {uuid}; |
| 669 | } |
| 670 | |
| 671 | return bt2s::nullopt; |
| 672 | } |
| 673 | |
| 674 | std::uint64_t length() const noexcept |
| 675 | { |
| 676 | return bt_trace_get_stream_count(this->libObjPtr()); |
| 677 | } |
| 678 | |
| 679 | _Stream operator[](const std::uint64_t index) const noexcept |
| 680 | { |
| 681 | return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)}; |
| 682 | } |
| 683 | |
| 684 | OptionalBorrowedObject<_Stream> streamById(const std::uint64_t id) const noexcept |
| 685 | { |
| 686 | return _Spec::streamById(this->libObjPtr(), id); |
| 687 | } |
| 688 | |
| 689 | CommonTrace environmentEntry(const bt2c::CStringView name, const std::int64_t val) const |
| 690 | { |
| 691 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`."); |
| 692 | |
| 693 | const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val); |
| 694 | |
| 695 | if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) { |
| 696 | throw MemoryError {}; |
| 697 | } |
| 698 | |
| 699 | return *this; |
| 700 | } |
| 701 | |
| 702 | CommonTrace environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const |
| 703 | { |
| 704 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`."); |
| 705 | |
| 706 | const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val); |
| 707 | |
| 708 | if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) { |
| 709 | throw MemoryError {}; |
| 710 | } |
| 711 | |
| 712 | return *this; |
| 713 | } |
| 714 | |
| 715 | std::uint64_t environmentSize() const noexcept |
| 716 | { |
| 717 | return bt_trace_get_environment_entry_count(this->libObjPtr()); |
| 718 | } |
| 719 | |
| 720 | ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept |
| 721 | { |
| 722 | const char *name; |
| 723 | const bt_value *libObjPtr; |
| 724 | |
| 725 | bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name, |
| 726 | &libObjPtr); |
| 727 | return ConstEnvironmentEntry {name, ConstValue {libObjPtr}}; |
| 728 | } |
| 729 | |
| 730 | OptionalBorrowedObject<ConstValue> environmentEntry(const bt2c::CStringView name) const noexcept |
| 731 | { |
| 732 | return bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name); |
| 733 | } |
| 734 | |
| 735 | template <typename LibValT> |
| 736 | CommonTrace userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 737 | { |
| 738 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`."); |
| 739 | |
| 740 | bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
| 741 | return *this; |
| 742 | } |
| 743 | |
| 744 | UserAttributes userAttributes() const noexcept |
| 745 | { |
| 746 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
| 747 | } |
| 748 | |
| 749 | Shared shared() const noexcept |
| 750 | { |
| 751 | return Shared::createWithRef(*this); |
| 752 | } |
| 753 | }; |
| 754 | |
| 755 | using Trace = CommonTrace<bt_trace>; |
| 756 | using ConstTrace = CommonTrace<const bt_trace>; |
| 757 | |
| 758 | namespace internal { |
| 759 | |
| 760 | struct TraceTypeDescr |
| 761 | { |
| 762 | using Const = ConstTrace; |
| 763 | using NonConst = Trace; |
| 764 | }; |
| 765 | |
| 766 | template <> |
| 767 | struct TypeDescr<Trace> : public TraceTypeDescr |
| 768 | { |
| 769 | }; |
| 770 | |
| 771 | template <> |
| 772 | struct TypeDescr<ConstTrace> : public TraceTypeDescr |
| 773 | { |
| 774 | }; |
| 775 | |
| 776 | } /* namespace internal */ |
| 777 | |
| 778 | template <typename LibObjT> |
| 779 | typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept |
| 780 | { |
| 781 | return _Trace {_Spec::trace(this->libObjPtr())}; |
| 782 | } |
| 783 | |
| 784 | namespace internal { |
| 785 | |
| 786 | struct EventClassRefFuncs final |
| 787 | { |
| 788 | static void get(const bt_event_class * const libObjPtr) noexcept |
| 789 | { |
| 790 | bt_event_class_get_ref(libObjPtr); |
| 791 | } |
| 792 | |
| 793 | static void put(const bt_event_class * const libObjPtr) noexcept |
| 794 | { |
| 795 | bt_event_class_put_ref(libObjPtr); |
| 796 | } |
| 797 | }; |
| 798 | |
| 799 | template <typename LibObjT> |
| 800 | struct CommonEventClassSpec; |
| 801 | |
| 802 | /* Functions specific to mutable event classes */ |
| 803 | template <> |
| 804 | struct CommonEventClassSpec<bt_event_class> final |
| 805 | { |
| 806 | static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept |
| 807 | { |
| 808 | return bt_event_class_borrow_stream_class(libObjPtr); |
| 809 | } |
| 810 | |
| 811 | static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept |
| 812 | { |
| 813 | return bt_event_class_borrow_payload_field_class(libObjPtr); |
| 814 | } |
| 815 | |
| 816 | static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept |
| 817 | { |
| 818 | return bt_event_class_borrow_specific_context_field_class(libObjPtr); |
| 819 | } |
| 820 | |
| 821 | static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept |
| 822 | { |
| 823 | return bt_event_class_borrow_user_attributes(libObjPtr); |
| 824 | } |
| 825 | }; |
| 826 | |
| 827 | /* Functions specific to constant event classes */ |
| 828 | template <> |
| 829 | struct CommonEventClassSpec<const bt_event_class> final |
| 830 | { |
| 831 | static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept |
| 832 | { |
| 833 | return bt_event_class_borrow_stream_class_const(libObjPtr); |
| 834 | } |
| 835 | |
| 836 | static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept |
| 837 | { |
| 838 | return bt_event_class_borrow_payload_field_class_const(libObjPtr); |
| 839 | } |
| 840 | |
| 841 | static const bt_field_class * |
| 842 | specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept |
| 843 | { |
| 844 | return bt_event_class_borrow_specific_context_field_class_const(libObjPtr); |
| 845 | } |
| 846 | |
| 847 | static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept |
| 848 | { |
| 849 | return bt_event_class_borrow_user_attributes_const(libObjPtr); |
| 850 | } |
| 851 | }; |
| 852 | |
| 853 | template <typename LibObjT> |
| 854 | using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>; |
| 855 | |
| 856 | } /* namespace internal */ |
| 857 | |
| 858 | template <typename LibObjT> |
| 859 | class CommonEventClass final : public BorrowedObject<LibObjT> |
| 860 | { |
| 861 | private: |
| 862 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 863 | using _Spec = internal::CommonEventClassSpec<LibObjT>; |
| 864 | using _StructureFieldClass = internal::DepStructFc<LibObjT>; |
| 865 | |
| 866 | using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>, |
| 867 | CommonStreamClass<const bt_stream_class>>; |
| 868 | |
| 869 | public: |
| 870 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 871 | using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>; |
| 872 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 873 | |
| 874 | /* Avoid `-Wshadow` error on GCC, conflicting with `bt2::Error` */ |
| 875 | BT_DIAG_PUSH |
| 876 | BT_DIAG_IGNORE_SHADOW |
| 877 | |
| 878 | enum class LogLevel |
| 879 | { |
| 880 | Emergency = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY, |
| 881 | Alert = BT_EVENT_CLASS_LOG_LEVEL_ALERT, |
| 882 | Critical = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL, |
| 883 | Error = BT_EVENT_CLASS_LOG_LEVEL_ERROR, |
| 884 | Warning = BT_EVENT_CLASS_LOG_LEVEL_WARNING, |
| 885 | Notice = BT_EVENT_CLASS_LOG_LEVEL_NOTICE, |
| 886 | Info = BT_EVENT_CLASS_LOG_LEVEL_INFO, |
| 887 | DebugSystem = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM, |
| 888 | DebugProgram = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM, |
| 889 | DebugProcess = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS, |
| 890 | DebugModule = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE, |
| 891 | DebugUnit = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT, |
| 892 | DebugFunction = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION, |
| 893 | DebugLine = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE, |
| 894 | Debug = BT_EVENT_CLASS_LOG_LEVEL_DEBUG, |
| 895 | }; |
| 896 | |
| 897 | BT_DIAG_POP |
| 898 | |
| 899 | explicit CommonEventClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
| 900 | { |
| 901 | } |
| 902 | |
| 903 | template <typename OtherLibObjT> |
| 904 | CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept : |
| 905 | _ThisBorrowedObject {eventClass} |
| 906 | { |
| 907 | } |
| 908 | |
| 909 | template <typename OtherLibObjT> |
| 910 | CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept |
| 911 | { |
| 912 | _ThisBorrowedObject::operator=(eventClass); |
| 913 | return *this; |
| 914 | } |
| 915 | |
| 916 | CommonEventClass<const bt_event_class> asConst() const noexcept |
| 917 | { |
| 918 | return CommonEventClass<const bt_event_class> {*this}; |
| 919 | } |
| 920 | |
| 921 | _StreamClass streamClass() const noexcept; |
| 922 | |
| 923 | std::uint64_t id() const noexcept |
| 924 | { |
| 925 | return bt_event_class_get_id(this->libObjPtr()); |
| 926 | } |
| 927 | |
| 928 | CommonEventClass name(const bt2c::CStringView name) const |
| 929 | { |
| 930 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
| 931 | |
| 932 | const auto status = bt_event_class_set_name(this->libObjPtr(), name); |
| 933 | |
| 934 | if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) { |
| 935 | throw MemoryError {}; |
| 936 | } |
| 937 | |
| 938 | return *this; |
| 939 | } |
| 940 | |
| 941 | bt2c::CStringView name() const noexcept |
| 942 | { |
| 943 | return bt_event_class_get_name(this->libObjPtr()); |
| 944 | } |
| 945 | |
| 946 | CommonEventClass logLevel(const LogLevel logLevel) const noexcept |
| 947 | { |
| 948 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
| 949 | |
| 950 | bt_event_class_set_log_level(this->libObjPtr(), |
| 951 | static_cast<bt_event_class_log_level>(logLevel)); |
| 952 | return *this; |
| 953 | } |
| 954 | |
| 955 | bt2s::optional<LogLevel> logLevel() const noexcept |
| 956 | { |
| 957 | bt_event_class_log_level libLogLevel; |
| 958 | |
| 959 | if (bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel)) { |
| 960 | return static_cast<LogLevel>(libLogLevel); |
| 961 | } |
| 962 | |
| 963 | return bt2s::nullopt; |
| 964 | } |
| 965 | |
| 966 | CommonEventClass emfUri(const bt2c::CStringView emfUri) const |
| 967 | { |
| 968 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
| 969 | |
| 970 | const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri); |
| 971 | |
| 972 | if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) { |
| 973 | throw MemoryError {}; |
| 974 | } |
| 975 | |
| 976 | return *this; |
| 977 | } |
| 978 | |
| 979 | bt2c::CStringView emfUri() const noexcept |
| 980 | { |
| 981 | return bt_event_class_get_emf_uri(this->libObjPtr()); |
| 982 | } |
| 983 | |
| 984 | CommonEventClass payloadFieldClass(const StructureFieldClass fc) const |
| 985 | { |
| 986 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
| 987 | |
| 988 | const auto status = |
| 989 | bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr()); |
| 990 | |
| 991 | if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { |
| 992 | throw MemoryError {}; |
| 993 | } |
| 994 | |
| 995 | return *this; |
| 996 | } |
| 997 | |
| 998 | OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept |
| 999 | { |
| 1000 | return _Spec::payloadFieldClass(this->libObjPtr()); |
| 1001 | } |
| 1002 | |
| 1003 | CommonEventClass specificContextFieldClass(const StructureFieldClass fc) const |
| 1004 | { |
| 1005 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
| 1006 | |
| 1007 | const auto status = |
| 1008 | bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr()); |
| 1009 | |
| 1010 | if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { |
| 1011 | throw MemoryError {}; |
| 1012 | } |
| 1013 | |
| 1014 | return *this; |
| 1015 | } |
| 1016 | |
| 1017 | OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept |
| 1018 | { |
| 1019 | return _Spec::specificContextFieldClass(this->libObjPtr()); |
| 1020 | } |
| 1021 | |
| 1022 | template <typename LibValT> |
| 1023 | CommonEventClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 1024 | { |
| 1025 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`."); |
| 1026 | |
| 1027 | bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
| 1028 | return *this; |
| 1029 | } |
| 1030 | |
| 1031 | UserAttributes userAttributes() const noexcept |
| 1032 | { |
| 1033 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
| 1034 | } |
| 1035 | |
| 1036 | Shared shared() const noexcept |
| 1037 | { |
| 1038 | return Shared::createWithRef(*this); |
| 1039 | } |
| 1040 | }; |
| 1041 | |
| 1042 | using EventClass = CommonEventClass<bt_event_class>; |
| 1043 | using ConstEventClass = CommonEventClass<const bt_event_class>; |
| 1044 | |
| 1045 | namespace internal { |
| 1046 | |
| 1047 | struct EventClassTypeDescr |
| 1048 | { |
| 1049 | using Const = ConstEventClass; |
| 1050 | using NonConst = EventClass; |
| 1051 | }; |
| 1052 | |
| 1053 | template <> |
| 1054 | struct TypeDescr<EventClass> : public EventClassTypeDescr |
| 1055 | { |
| 1056 | }; |
| 1057 | |
| 1058 | template <> |
| 1059 | struct TypeDescr<ConstEventClass> : public EventClassTypeDescr |
| 1060 | { |
| 1061 | }; |
| 1062 | |
| 1063 | } /* namespace internal */ |
| 1064 | |
| 1065 | template <typename LibObjT> |
| 1066 | typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept |
| 1067 | { |
| 1068 | return Class {_Spec::cls(this->libObjPtr())}; |
| 1069 | } |
| 1070 | |
| 1071 | namespace internal { |
| 1072 | |
| 1073 | struct StreamClassRefFuncs final |
| 1074 | { |
| 1075 | static void get(const bt_stream_class * const libObjPtr) noexcept |
| 1076 | { |
| 1077 | bt_stream_class_get_ref(libObjPtr); |
| 1078 | } |
| 1079 | |
| 1080 | static void put(const bt_stream_class * const libObjPtr) noexcept |
| 1081 | { |
| 1082 | bt_stream_class_put_ref(libObjPtr); |
| 1083 | } |
| 1084 | }; |
| 1085 | |
| 1086 | template <typename LibObjT> |
| 1087 | struct CommonStreamClassSpec; |
| 1088 | |
| 1089 | /* Functions specific to mutable stream classes */ |
| 1090 | template <> |
| 1091 | struct CommonStreamClassSpec<bt_stream_class> final |
| 1092 | { |
| 1093 | static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept |
| 1094 | { |
| 1095 | return bt_stream_class_borrow_trace_class(libObjPtr); |
| 1096 | } |
| 1097 | |
| 1098 | static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr, |
| 1099 | const std::uint64_t index) noexcept |
| 1100 | { |
| 1101 | return bt_stream_class_borrow_event_class_by_index(libObjPtr, index); |
| 1102 | } |
| 1103 | |
| 1104 | static bt_event_class *eventClassById(bt_stream_class * const libObjPtr, |
| 1105 | const std::uint64_t id) noexcept |
| 1106 | { |
| 1107 | return bt_stream_class_borrow_event_class_by_id(libObjPtr, id); |
| 1108 | } |
| 1109 | |
| 1110 | static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept |
| 1111 | { |
| 1112 | return bt_stream_class_borrow_default_clock_class(libObjPtr); |
| 1113 | } |
| 1114 | |
| 1115 | static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept |
| 1116 | { |
| 1117 | return bt_stream_class_borrow_packet_context_field_class(libObjPtr); |
| 1118 | } |
| 1119 | |
| 1120 | static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept |
| 1121 | { |
| 1122 | return bt_stream_class_borrow_event_common_context_field_class(libObjPtr); |
| 1123 | } |
| 1124 | |
| 1125 | static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept |
| 1126 | { |
| 1127 | return bt_stream_class_borrow_user_attributes(libObjPtr); |
| 1128 | } |
| 1129 | }; |
| 1130 | |
| 1131 | /* Functions specific to constant stream classes */ |
| 1132 | template <> |
| 1133 | struct CommonStreamClassSpec<const bt_stream_class> final |
| 1134 | { |
| 1135 | static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept |
| 1136 | { |
| 1137 | return bt_stream_class_borrow_trace_class_const(libObjPtr); |
| 1138 | } |
| 1139 | |
| 1140 | static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr, |
| 1141 | const std::uint64_t index) noexcept |
| 1142 | { |
| 1143 | return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index); |
| 1144 | } |
| 1145 | |
| 1146 | static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr, |
| 1147 | const std::uint64_t id) noexcept |
| 1148 | { |
| 1149 | return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id); |
| 1150 | } |
| 1151 | |
| 1152 | static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept |
| 1153 | { |
| 1154 | return bt_stream_class_borrow_default_clock_class_const(libObjPtr); |
| 1155 | } |
| 1156 | |
| 1157 | static const bt_field_class * |
| 1158 | packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept |
| 1159 | { |
| 1160 | return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr); |
| 1161 | } |
| 1162 | |
| 1163 | static const bt_field_class * |
| 1164 | eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept |
| 1165 | { |
| 1166 | return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr); |
| 1167 | } |
| 1168 | |
| 1169 | static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept |
| 1170 | { |
| 1171 | return bt_stream_class_borrow_user_attributes_const(libObjPtr); |
| 1172 | } |
| 1173 | }; |
| 1174 | |
| 1175 | } /* namespace internal */ |
| 1176 | |
| 1177 | template <typename LibObjT> |
| 1178 | class CommonStreamClass final : public BorrowedObject<LibObjT> |
| 1179 | { |
| 1180 | private: |
| 1181 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 1182 | using _Spec = internal::CommonStreamClassSpec<LibObjT>; |
| 1183 | using _StructureFieldClass = internal::DepStructFc<LibObjT>; |
| 1184 | |
| 1185 | using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>, |
| 1186 | CommonTraceClass<const bt_trace_class>>; |
| 1187 | |
| 1188 | using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>, |
| 1189 | CommonEventClass<const bt_event_class>>; |
| 1190 | |
| 1191 | using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>; |
| 1192 | |
| 1193 | public: |
| 1194 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 1195 | using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>; |
| 1196 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 1197 | |
| 1198 | explicit CommonStreamClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
| 1199 | { |
| 1200 | } |
| 1201 | |
| 1202 | template <typename OtherLibObjT> |
| 1203 | CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept : |
| 1204 | _ThisBorrowedObject {streamClass} |
| 1205 | { |
| 1206 | } |
| 1207 | |
| 1208 | template <typename OtherLibObjT> |
| 1209 | CommonStreamClass operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept |
| 1210 | { |
| 1211 | _ThisBorrowedObject::operator=(streamClass); |
| 1212 | return *this; |
| 1213 | } |
| 1214 | |
| 1215 | CommonStreamClass<const bt_stream_class> asConst() const noexcept |
| 1216 | { |
| 1217 | return CommonStreamClass<const bt_stream_class> {*this}; |
| 1218 | } |
| 1219 | |
| 1220 | Stream::Shared instantiate(const Trace trace) const |
| 1221 | { |
| 1222 | static_assert(!std::is_const<LibObjT>::value, |
| 1223 | "Not available with `bt2::ConstStreamClass`."); |
| 1224 | |
| 1225 | const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr()); |
| 1226 | |
| 1227 | internal::validateCreatedObjPtr(libObjPtr); |
| 1228 | return Stream::Shared::createWithoutRef(libObjPtr); |
| 1229 | } |
| 1230 | |
| 1231 | Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const |
| 1232 | { |
| 1233 | static_assert(!std::is_const<LibObjT>::value, |
| 1234 | "Not available with `bt2::ConstStreamClass`."); |
| 1235 | |
| 1236 | const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id); |
| 1237 | |
| 1238 | internal::validateCreatedObjPtr(libObjPtr); |
| 1239 | return Stream::Shared::createWithoutRef(libObjPtr); |
| 1240 | } |
| 1241 | |
| 1242 | EventClass::Shared createEventClass() const |
| 1243 | { |
| 1244 | static_assert(!std::is_const<LibObjT>::value, |
| 1245 | "Not available with `bt2::ConstStreamClass`."); |
| 1246 | |
| 1247 | const auto libObjPtr = bt_event_class_create(this->libObjPtr()); |
| 1248 | |
| 1249 | internal::validateCreatedObjPtr(libObjPtr); |
| 1250 | return EventClass::Shared::createWithoutRef(libObjPtr); |
| 1251 | } |
| 1252 | |
| 1253 | EventClass::Shared createEventClass(const std::uint64_t id) const |
| 1254 | { |
| 1255 | static_assert(!std::is_const<LibObjT>::value, |
| 1256 | "Not available with `bt2::ConstStreamClass`."); |
| 1257 | |
| 1258 | const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id); |
| 1259 | |
| 1260 | internal::validateCreatedObjPtr(libObjPtr); |
| 1261 | return EventClass::Shared::createWithoutRef(libObjPtr); |
| 1262 | } |
| 1263 | |
| 1264 | _TraceClass traceClass() const noexcept; |
| 1265 | |
| 1266 | std::uint64_t id() const noexcept |
| 1267 | { |
| 1268 | return bt_stream_class_get_id(this->libObjPtr()); |
| 1269 | } |
| 1270 | |
| 1271 | CommonStreamClass name(const bt2c::CStringView name) const |
| 1272 | { |
| 1273 | static_assert(!std::is_const<LibObjT>::value, |
| 1274 | "Not available with `bt2::ConstStreamClass`."); |
| 1275 | |
| 1276 | const auto status = bt_stream_class_set_name(this->libObjPtr(), name); |
| 1277 | |
| 1278 | if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) { |
| 1279 | throw MemoryError {}; |
| 1280 | } |
| 1281 | |
| 1282 | return *this; |
| 1283 | } |
| 1284 | |
| 1285 | bt2c::CStringView name() const noexcept |
| 1286 | { |
| 1287 | return bt_stream_class_get_name(this->libObjPtr()); |
| 1288 | } |
| 1289 | |
| 1290 | CommonStreamClass assignsAutomaticEventClassId(const bool val) const noexcept |
| 1291 | { |
| 1292 | static_assert(!std::is_const<LibObjT>::value, |
| 1293 | "Not available with `bt2::ConstStreamClass`."); |
| 1294 | |
| 1295 | bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(), |
| 1296 | static_cast<bt_bool>(val)); |
| 1297 | return *this; |
| 1298 | } |
| 1299 | |
| 1300 | bool assignsAutomaticEventClassId() const noexcept |
| 1301 | { |
| 1302 | return static_cast<bool>( |
| 1303 | bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr())); |
| 1304 | } |
| 1305 | |
| 1306 | CommonStreamClass assignsAutomaticStreamId(const bool val) const noexcept |
| 1307 | { |
| 1308 | static_assert(!std::is_const<LibObjT>::value, |
| 1309 | "Not available with `bt2::ConstStreamClass`."); |
| 1310 | |
| 1311 | bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(), |
| 1312 | static_cast<bt_bool>(val)); |
| 1313 | return *this; |
| 1314 | } |
| 1315 | |
| 1316 | bool assignsAutomaticStreamId() const noexcept |
| 1317 | { |
| 1318 | return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr())); |
| 1319 | } |
| 1320 | |
| 1321 | CommonStreamClass supportsPackets(const bool supportsPackets, |
| 1322 | const bool withBeginningDefaultClkSnapshot, |
| 1323 | const bool withEndDefaultClkSnapshot) const noexcept |
| 1324 | { |
| 1325 | static_assert(!std::is_const<LibObjT>::value, |
| 1326 | "Not available with `bt2::ConstStreamClass`."); |
| 1327 | |
| 1328 | bt_stream_class_set_supports_packets(this->libObjPtr(), |
| 1329 | static_cast<bt_bool>(supportsPackets), |
| 1330 | static_cast<bt_bool>(withBeginningDefaultClkSnapshot), |
| 1331 | static_cast<bt_bool>(withEndDefaultClkSnapshot)); |
| 1332 | return *this; |
| 1333 | } |
| 1334 | |
| 1335 | bool supportsPackets() const noexcept |
| 1336 | { |
| 1337 | return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr())); |
| 1338 | } |
| 1339 | |
| 1340 | bool packetsHaveBeginningClockSnapshot() const noexcept |
| 1341 | { |
| 1342 | return static_cast<bool>( |
| 1343 | bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr())); |
| 1344 | } |
| 1345 | |
| 1346 | bool packetsHaveEndClockSnapshot() const noexcept |
| 1347 | { |
| 1348 | return static_cast<bool>( |
| 1349 | bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr())); |
| 1350 | } |
| 1351 | |
| 1352 | CommonStreamClass supportsDiscardedEvents(const bool supportsDiscardedEvents, |
| 1353 | const bool withDefaultClkSnapshots) const noexcept |
| 1354 | { |
| 1355 | static_assert(!std::is_const<LibObjT>::value, |
| 1356 | "Not available with `bt2::ConstStreamClass`."); |
| 1357 | |
| 1358 | bt_stream_class_set_supports_discarded_events( |
| 1359 | this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents), |
| 1360 | static_cast<bt_bool>(withDefaultClkSnapshots)); |
| 1361 | return *this; |
| 1362 | } |
| 1363 | |
| 1364 | bool supportsDiscardedEvents() const noexcept |
| 1365 | { |
| 1366 | return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr())); |
| 1367 | } |
| 1368 | |
| 1369 | bool discardedEventsHaveDefaultClockSnapshots() const noexcept |
| 1370 | { |
| 1371 | return static_cast<bool>( |
| 1372 | bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr())); |
| 1373 | } |
| 1374 | |
| 1375 | CommonStreamClass supportsDiscardedPackets(const bool supportsDiscardedPackets, |
| 1376 | const bool withDefaultClkSnapshots) const noexcept |
| 1377 | { |
| 1378 | static_assert(!std::is_const<LibObjT>::value, |
| 1379 | "Not available with `bt2::ConstStreamClass`."); |
| 1380 | |
| 1381 | bt_stream_class_set_supports_discarded_packets( |
| 1382 | this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets), |
| 1383 | static_cast<bt_bool>(withDefaultClkSnapshots)); |
| 1384 | return *this; |
| 1385 | } |
| 1386 | |
| 1387 | bool supportsDiscardedPackets() const noexcept |
| 1388 | { |
| 1389 | return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr())); |
| 1390 | } |
| 1391 | |
| 1392 | bool discardedPacketsHaveDefaultClockSnapshots() const noexcept |
| 1393 | { |
| 1394 | return static_cast<bool>( |
| 1395 | bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr())); |
| 1396 | } |
| 1397 | |
| 1398 | CommonStreamClass defaultClockClass(const ClockClass clkCls) const |
| 1399 | { |
| 1400 | static_assert(!std::is_const<LibObjT>::value, |
| 1401 | "Not available with `bt2::ConstStreamClass`."); |
| 1402 | |
| 1403 | const auto status = |
| 1404 | bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr()); |
| 1405 | |
| 1406 | BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK); |
| 1407 | return *this; |
| 1408 | } |
| 1409 | |
| 1410 | OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept |
| 1411 | { |
| 1412 | return _Spec::defaultClockClass(this->libObjPtr()); |
| 1413 | } |
| 1414 | |
| 1415 | std::uint64_t length() const noexcept |
| 1416 | { |
| 1417 | return bt_stream_class_get_event_class_count(this->libObjPtr()); |
| 1418 | } |
| 1419 | |
| 1420 | _EventClass operator[](const std::uint64_t index) const noexcept |
| 1421 | { |
| 1422 | return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)}; |
| 1423 | } |
| 1424 | |
| 1425 | OptionalBorrowedObject<_EventClass> eventClassById(const std::uint64_t id) const noexcept |
| 1426 | { |
| 1427 | return _Spec::eventClassById(this->libObjPtr(), id); |
| 1428 | } |
| 1429 | |
| 1430 | CommonStreamClass packetContextFieldClass(const StructureFieldClass fc) const |
| 1431 | { |
| 1432 | static_assert(!std::is_const<LibObjT>::value, |
| 1433 | "Not available with `bt2::ConstStreamClass`."); |
| 1434 | |
| 1435 | const auto status = |
| 1436 | bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr()); |
| 1437 | |
| 1438 | if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { |
| 1439 | throw MemoryError {}; |
| 1440 | } |
| 1441 | |
| 1442 | return *this; |
| 1443 | } |
| 1444 | |
| 1445 | OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept |
| 1446 | { |
| 1447 | return _Spec::packetContextFieldClass(this->libObjPtr()); |
| 1448 | } |
| 1449 | |
| 1450 | CommonStreamClass eventCommonContextFieldClass(const StructureFieldClass fc) const |
| 1451 | { |
| 1452 | static_assert(!std::is_const<LibObjT>::value, |
| 1453 | "Not available with `bt2::ConstStreamClass`."); |
| 1454 | |
| 1455 | const auto status = |
| 1456 | bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr()); |
| 1457 | |
| 1458 | if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) { |
| 1459 | throw MemoryError {}; |
| 1460 | } |
| 1461 | |
| 1462 | return *this; |
| 1463 | } |
| 1464 | |
| 1465 | OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept |
| 1466 | { |
| 1467 | return _Spec::eventCommonContextFieldClass(this->libObjPtr()); |
| 1468 | } |
| 1469 | |
| 1470 | template <typename LibValT> |
| 1471 | CommonStreamClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 1472 | { |
| 1473 | static_assert(!std::is_const<LibObjT>::value, |
| 1474 | "Not available with `bt2::ConstStreamClass`."); |
| 1475 | |
| 1476 | bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
| 1477 | return *this; |
| 1478 | } |
| 1479 | |
| 1480 | UserAttributes userAttributes() const noexcept |
| 1481 | { |
| 1482 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
| 1483 | } |
| 1484 | |
| 1485 | Shared shared() const noexcept |
| 1486 | { |
| 1487 | return Shared::createWithRef(*this); |
| 1488 | } |
| 1489 | }; |
| 1490 | |
| 1491 | using StreamClass = CommonStreamClass<bt_stream_class>; |
| 1492 | using ConstStreamClass = CommonStreamClass<const bt_stream_class>; |
| 1493 | |
| 1494 | namespace internal { |
| 1495 | |
| 1496 | struct StreamClassTypeDescr |
| 1497 | { |
| 1498 | using Const = ConstStreamClass; |
| 1499 | using NonConst = StreamClass; |
| 1500 | }; |
| 1501 | |
| 1502 | template <> |
| 1503 | struct TypeDescr<StreamClass> : public StreamClassTypeDescr |
| 1504 | { |
| 1505 | }; |
| 1506 | |
| 1507 | template <> |
| 1508 | struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr |
| 1509 | { |
| 1510 | }; |
| 1511 | |
| 1512 | } /* namespace internal */ |
| 1513 | |
| 1514 | template <typename LibObjT> |
| 1515 | typename CommonEventClass<LibObjT>::_StreamClass |
| 1516 | CommonEventClass<LibObjT>::streamClass() const noexcept |
| 1517 | { |
| 1518 | return _StreamClass {_Spec::streamClass(this->libObjPtr())}; |
| 1519 | } |
| 1520 | |
| 1521 | template <typename LibObjT> |
| 1522 | typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept |
| 1523 | { |
| 1524 | return Class {_Spec::cls(this->libObjPtr())}; |
| 1525 | } |
| 1526 | |
| 1527 | namespace internal { |
| 1528 | |
| 1529 | struct TraceClassRefFuncs final |
| 1530 | { |
| 1531 | static void get(const bt_trace_class * const libObjPtr) noexcept |
| 1532 | { |
| 1533 | bt_trace_class_get_ref(libObjPtr); |
| 1534 | } |
| 1535 | |
| 1536 | static void put(const bt_trace_class * const libObjPtr) noexcept |
| 1537 | { |
| 1538 | bt_trace_class_put_ref(libObjPtr); |
| 1539 | } |
| 1540 | }; |
| 1541 | |
| 1542 | template <typename LibObjT> |
| 1543 | struct CommonTraceClassSpec; |
| 1544 | |
| 1545 | /* Functions specific to mutable stream classes */ |
| 1546 | template <> |
| 1547 | struct CommonTraceClassSpec<bt_trace_class> final |
| 1548 | { |
| 1549 | static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr, |
| 1550 | const std::uint64_t index) noexcept |
| 1551 | { |
| 1552 | return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index); |
| 1553 | } |
| 1554 | |
| 1555 | static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr, |
| 1556 | const std::uint64_t id) noexcept |
| 1557 | { |
| 1558 | return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id); |
| 1559 | } |
| 1560 | |
| 1561 | static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept |
| 1562 | { |
| 1563 | return bt_trace_class_borrow_user_attributes(libObjPtr); |
| 1564 | } |
| 1565 | }; |
| 1566 | |
| 1567 | /* Functions specific to constant stream classes */ |
| 1568 | template <> |
| 1569 | struct CommonTraceClassSpec<const bt_trace_class> final |
| 1570 | { |
| 1571 | static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr, |
| 1572 | const std::uint64_t index) noexcept |
| 1573 | { |
| 1574 | return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index); |
| 1575 | } |
| 1576 | |
| 1577 | static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr, |
| 1578 | const std::uint64_t id) noexcept |
| 1579 | { |
| 1580 | return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id); |
| 1581 | } |
| 1582 | |
| 1583 | static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept |
| 1584 | { |
| 1585 | return bt_trace_class_borrow_user_attributes_const(libObjPtr); |
| 1586 | } |
| 1587 | }; |
| 1588 | |
| 1589 | } /* namespace internal */ |
| 1590 | |
| 1591 | template <typename LibObjT> |
| 1592 | class CommonTraceClass final : public BorrowedObject<LibObjT> |
| 1593 | { |
| 1594 | private: |
| 1595 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 1596 | |
| 1597 | using _Spec = internal::CommonTraceClassSpec<LibObjT>; |
| 1598 | |
| 1599 | using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>, |
| 1600 | CommonStreamClass<const bt_stream_class>>; |
| 1601 | |
| 1602 | public: |
| 1603 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 1604 | using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>; |
| 1605 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 1606 | |
| 1607 | explicit CommonTraceClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
| 1608 | { |
| 1609 | } |
| 1610 | |
| 1611 | template <typename OtherLibObjT> |
| 1612 | CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept : |
| 1613 | _ThisBorrowedObject {traceClass} |
| 1614 | { |
| 1615 | } |
| 1616 | |
| 1617 | template <typename OtherLibObjT> |
| 1618 | CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept |
| 1619 | { |
| 1620 | _ThisBorrowedObject::operator=(traceClass); |
| 1621 | return *this; |
| 1622 | } |
| 1623 | |
| 1624 | CommonTraceClass<const bt_trace_class> asConst() const noexcept |
| 1625 | { |
| 1626 | return CommonTraceClass<const bt_trace_class> {*this}; |
| 1627 | } |
| 1628 | |
| 1629 | Trace::Shared instantiate() const |
| 1630 | { |
| 1631 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1632 | |
| 1633 | const auto libObjPtr = bt_trace_create(this->libObjPtr()); |
| 1634 | |
| 1635 | internal::validateCreatedObjPtr(libObjPtr); |
| 1636 | return Trace::Shared::createWithoutRef(libObjPtr); |
| 1637 | } |
| 1638 | |
| 1639 | StreamClass::Shared createStreamClass() const |
| 1640 | { |
| 1641 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1642 | |
| 1643 | const auto libObjPtr = bt_stream_class_create(this->libObjPtr()); |
| 1644 | |
| 1645 | internal::validateCreatedObjPtr(libObjPtr); |
| 1646 | return StreamClass::Shared::createWithoutRef(libObjPtr); |
| 1647 | } |
| 1648 | |
| 1649 | StreamClass::Shared createStreamClass(const std::uint64_t id) const |
| 1650 | { |
| 1651 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1652 | |
| 1653 | const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id); |
| 1654 | |
| 1655 | internal::validateCreatedObjPtr(libObjPtr); |
| 1656 | return StreamClass::Shared::createWithoutRef(libObjPtr); |
| 1657 | } |
| 1658 | |
| 1659 | FieldClass::Shared createBoolFieldClass() const |
| 1660 | { |
| 1661 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1662 | |
| 1663 | const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr()); |
| 1664 | |
| 1665 | internal::validateCreatedObjPtr(libObjPtr); |
| 1666 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
| 1667 | } |
| 1668 | |
| 1669 | BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const |
| 1670 | { |
| 1671 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1672 | |
| 1673 | const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length); |
| 1674 | |
| 1675 | internal::validateCreatedObjPtr(libObjPtr); |
| 1676 | return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1677 | } |
| 1678 | |
| 1679 | IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const |
| 1680 | { |
| 1681 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1682 | |
| 1683 | const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr()); |
| 1684 | |
| 1685 | internal::validateCreatedObjPtr(libObjPtr); |
| 1686 | return IntegerFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1687 | } |
| 1688 | |
| 1689 | IntegerFieldClass::Shared createSignedIntegerFieldClass() const |
| 1690 | { |
| 1691 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1692 | |
| 1693 | const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr()); |
| 1694 | |
| 1695 | internal::validateCreatedObjPtr(libObjPtr); |
| 1696 | return IntegerFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1697 | } |
| 1698 | |
| 1699 | UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const |
| 1700 | { |
| 1701 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1702 | |
| 1703 | const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr()); |
| 1704 | |
| 1705 | internal::validateCreatedObjPtr(libObjPtr); |
| 1706 | return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1707 | } |
| 1708 | |
| 1709 | SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const |
| 1710 | { |
| 1711 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1712 | |
| 1713 | const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr()); |
| 1714 | |
| 1715 | internal::validateCreatedObjPtr(libObjPtr); |
| 1716 | return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1717 | } |
| 1718 | |
| 1719 | FieldClass::Shared createSinglePrecisionRealFieldClass() const |
| 1720 | { |
| 1721 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1722 | |
| 1723 | const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr()); |
| 1724 | |
| 1725 | internal::validateCreatedObjPtr(libObjPtr); |
| 1726 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
| 1727 | } |
| 1728 | |
| 1729 | FieldClass::Shared createDoublePrecisionRealFieldClass() const |
| 1730 | { |
| 1731 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1732 | |
| 1733 | const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr()); |
| 1734 | |
| 1735 | internal::validateCreatedObjPtr(libObjPtr); |
| 1736 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
| 1737 | } |
| 1738 | |
| 1739 | FieldClass::Shared createStringFieldClass() const |
| 1740 | { |
| 1741 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1742 | |
| 1743 | const auto libObjPtr = bt_field_class_string_create(this->libObjPtr()); |
| 1744 | |
| 1745 | internal::validateCreatedObjPtr(libObjPtr); |
| 1746 | return FieldClass::Shared::createWithoutRef(libObjPtr); |
| 1747 | } |
| 1748 | |
| 1749 | StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass, |
| 1750 | const std::uint64_t length) const |
| 1751 | { |
| 1752 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1753 | |
| 1754 | const auto libObjPtr = bt_field_class_array_static_create( |
| 1755 | this->libObjPtr(), elementFieldClass.libObjPtr(), length); |
| 1756 | |
| 1757 | internal::validateCreatedObjPtr(libObjPtr); |
| 1758 | return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1759 | } |
| 1760 | |
| 1761 | ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const |
| 1762 | { |
| 1763 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1764 | |
| 1765 | const auto libObjPtr = bt_field_class_array_dynamic_create( |
| 1766 | this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr); |
| 1767 | |
| 1768 | internal::validateCreatedObjPtr(libObjPtr); |
| 1769 | return ArrayFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1770 | } |
| 1771 | |
| 1772 | DynamicArrayWithLengthFieldClass::Shared |
| 1773 | createDynamicArrayFieldClass(const FieldClass elementFieldClass, |
| 1774 | const IntegerFieldClass lengthFieldClass) const |
| 1775 | { |
| 1776 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1777 | |
| 1778 | const auto libObjPtr = bt_field_class_array_dynamic_create( |
| 1779 | this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr()); |
| 1780 | |
| 1781 | internal::validateCreatedObjPtr(libObjPtr); |
| 1782 | return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1783 | } |
| 1784 | |
| 1785 | StructureFieldClass::Shared createStructureFieldClass() const |
| 1786 | { |
| 1787 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1788 | |
| 1789 | const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr()); |
| 1790 | |
| 1791 | internal::validateCreatedObjPtr(libObjPtr); |
| 1792 | return StructureFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1793 | } |
| 1794 | |
| 1795 | OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const |
| 1796 | { |
| 1797 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1798 | |
| 1799 | const auto libObjPtr = bt_field_class_option_without_selector_create( |
| 1800 | this->libObjPtr(), optionalFieldClass.libObjPtr()); |
| 1801 | |
| 1802 | internal::validateCreatedObjPtr(libObjPtr); |
| 1803 | return OptionFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1804 | } |
| 1805 | |
| 1806 | OptionWithBoolSelectorFieldClass::Shared |
| 1807 | createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass, |
| 1808 | const FieldClass selectorFieldClass) const |
| 1809 | { |
| 1810 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1811 | |
| 1812 | const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create( |
| 1813 | this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr()); |
| 1814 | |
| 1815 | internal::validateCreatedObjPtr(libObjPtr); |
| 1816 | return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1817 | } |
| 1818 | |
| 1819 | OptionWithUnsignedIntegerSelectorFieldClass::Shared |
| 1820 | createOptionWithUnsignedIntegerSelectorFieldClass( |
| 1821 | const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass, |
| 1822 | const ConstUnsignedIntegerRangeSet ranges) const |
| 1823 | { |
| 1824 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1825 | |
| 1826 | const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create( |
| 1827 | this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(), |
| 1828 | ranges.libObjPtr()); |
| 1829 | |
| 1830 | internal::validateCreatedObjPtr(libObjPtr); |
| 1831 | return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1832 | } |
| 1833 | |
| 1834 | OptionWithSignedIntegerSelectorFieldClass::Shared |
| 1835 | createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass, |
| 1836 | const IntegerFieldClass selectorFieldClass, |
| 1837 | const ConstSignedIntegerRangeSet ranges) const |
| 1838 | { |
| 1839 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1840 | |
| 1841 | const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create( |
| 1842 | this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(), |
| 1843 | ranges.libObjPtr()); |
| 1844 | |
| 1845 | internal::validateCreatedObjPtr(libObjPtr); |
| 1846 | return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1847 | } |
| 1848 | |
| 1849 | VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const |
| 1850 | { |
| 1851 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1852 | |
| 1853 | const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr); |
| 1854 | |
| 1855 | internal::validateCreatedObjPtr(libObjPtr); |
| 1856 | return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr); |
| 1857 | } |
| 1858 | |
| 1859 | VariantWithUnsignedIntegerSelectorFieldClass::Shared |
| 1860 | createVariantWithUnsignedIntegerSelectorFieldClass( |
| 1861 | const IntegerFieldClass selectorFieldClass) const |
| 1862 | { |
| 1863 | return this->_createVariantWithIntegerSelectorFieldClass< |
| 1864 | VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass); |
| 1865 | } |
| 1866 | |
| 1867 | VariantWithSignedIntegerSelectorFieldClass::Shared |
| 1868 | createVariantWithSignedIntegerSelectorFieldClass( |
| 1869 | const IntegerFieldClass selectorFieldClass) const |
| 1870 | { |
| 1871 | return this->_createVariantWithIntegerSelectorFieldClass< |
| 1872 | VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass); |
| 1873 | } |
| 1874 | |
| 1875 | CommonTraceClass assignsAutomaticStreamClassId(const bool val) const noexcept |
| 1876 | { |
| 1877 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1878 | |
| 1879 | bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(), |
| 1880 | static_cast<bt_bool>(val)); |
| 1881 | return *this; |
| 1882 | } |
| 1883 | |
| 1884 | bool assignsAutomaticStreamClassId() const noexcept |
| 1885 | { |
| 1886 | return static_cast<bool>( |
| 1887 | bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr())); |
| 1888 | } |
| 1889 | |
| 1890 | std::uint64_t length() const noexcept |
| 1891 | { |
| 1892 | return bt_trace_class_get_stream_class_count(this->libObjPtr()); |
| 1893 | } |
| 1894 | |
| 1895 | _StreamClass operator[](const std::uint64_t index) const noexcept |
| 1896 | { |
| 1897 | return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)}; |
| 1898 | } |
| 1899 | |
| 1900 | OptionalBorrowedObject<_StreamClass> streamClassById(const std::uint64_t id) const noexcept |
| 1901 | { |
| 1902 | return _Spec::streamClassById(this->libObjPtr(), id); |
| 1903 | } |
| 1904 | |
| 1905 | template <typename LibValT> |
| 1906 | CommonTraceClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 1907 | { |
| 1908 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1909 | |
| 1910 | bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
| 1911 | return *this; |
| 1912 | } |
| 1913 | |
| 1914 | UserAttributes userAttributes() const noexcept |
| 1915 | { |
| 1916 | return UserAttributes {_Spec::userAttributes(this->libObjPtr())}; |
| 1917 | } |
| 1918 | |
| 1919 | Shared shared() const noexcept |
| 1920 | { |
| 1921 | return Shared::createWithRef(*this); |
| 1922 | } |
| 1923 | |
| 1924 | private: |
| 1925 | template <typename ObjT> |
| 1926 | typename ObjT::Shared |
| 1927 | _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const |
| 1928 | { |
| 1929 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`."); |
| 1930 | |
| 1931 | const auto libObjPtr = |
| 1932 | bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr()); |
| 1933 | |
| 1934 | internal::validateCreatedObjPtr(libObjPtr); |
| 1935 | return ObjT::Shared::createWithoutRef(libObjPtr); |
| 1936 | } |
| 1937 | }; |
| 1938 | |
| 1939 | using TraceClass = CommonTraceClass<bt_trace_class>; |
| 1940 | using ConstTraceClass = CommonTraceClass<const bt_trace_class>; |
| 1941 | |
| 1942 | namespace internal { |
| 1943 | |
| 1944 | struct TraceClassTypeDescr |
| 1945 | { |
| 1946 | using Const = ConstTraceClass; |
| 1947 | using NonConst = TraceClass; |
| 1948 | }; |
| 1949 | |
| 1950 | template <> |
| 1951 | struct TypeDescr<TraceClass> : public TraceClassTypeDescr |
| 1952 | { |
| 1953 | }; |
| 1954 | |
| 1955 | template <> |
| 1956 | struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr |
| 1957 | { |
| 1958 | }; |
| 1959 | |
| 1960 | } /* namespace internal */ |
| 1961 | |
| 1962 | template <typename LibObjT> |
| 1963 | typename CommonStreamClass<LibObjT>::_TraceClass |
| 1964 | CommonStreamClass<LibObjT>::traceClass() const noexcept |
| 1965 | { |
| 1966 | return _TraceClass {_Spec::traceClass(this->libObjPtr())}; |
| 1967 | } |
| 1968 | |
| 1969 | template <typename LibObjT> |
| 1970 | typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept |
| 1971 | { |
| 1972 | return Class {_Spec::cls(this->libObjPtr())}; |
| 1973 | } |
| 1974 | |
| 1975 | } /* namespace bt2 */ |
| 1976 | |
| 1977 | #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */ |