| 1 | /* |
| 2 | * clock-class.c |
| 3 | * |
| 4 | * Babeltrace CTF writer - Clock class |
| 5 | * |
| 6 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 7 | * |
| 8 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 9 | * |
| 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | * of this software and associated documentation files (the "Software"), to deal |
| 12 | * in the Software without restriction, including without limitation the rights |
| 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | * copies of the Software, and to permit persons to whom the Software is |
| 15 | * furnished to do so, subject to the following conditions: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice shall be included in |
| 18 | * all copies or substantial portions of the Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | * SOFTWARE. |
| 27 | */ |
| 28 | |
| 29 | #define BT_LOG_TAG "CTF-WRITER-CLOCK-CLASS" |
| 30 | #include <babeltrace/lib-logging-internal.h> |
| 31 | |
| 32 | #include <babeltrace/assert-pre-internal.h> |
| 33 | #include <babeltrace/compat/uuid-internal.h> |
| 34 | #include <babeltrace/ctf-writer/clock-class-internal.h> |
| 35 | #include <babeltrace/ctf-writer/utils.h> |
| 36 | #include <babeltrace/ctf-writer/object.h> |
| 37 | #include <babeltrace/compiler-internal.h> |
| 38 | #include <babeltrace/types.h> |
| 39 | #include <babeltrace/compat/string-internal.h> |
| 40 | #include <inttypes.h> |
| 41 | #include <babeltrace/ctf-writer/object-internal.h> |
| 42 | #include <babeltrace/assert-internal.h> |
| 43 | |
| 44 | static |
| 45 | void bt_ctf_clock_class_destroy(struct bt_ctf_object *obj); |
| 46 | |
| 47 | BT_HIDDEN |
| 48 | bt_bool bt_ctf_clock_class_is_valid(struct bt_ctf_clock_class *clock_class) |
| 49 | { |
| 50 | return clock_class && clock_class->name; |
| 51 | } |
| 52 | |
| 53 | BT_HIDDEN |
| 54 | int bt_ctf_clock_class_set_name(struct bt_ctf_clock_class *clock_class, |
| 55 | const char *name) |
| 56 | { |
| 57 | int ret = 0; |
| 58 | |
| 59 | if (!clock_class) { |
| 60 | BT_LOGW_STR("Invalid parameter: clock class is NULL."); |
| 61 | ret = -1; |
| 62 | goto end; |
| 63 | } |
| 64 | |
| 65 | if (clock_class->frozen) { |
| 66 | BT_LOGW("Invalid parameter: clock class is frozen: addr=%p, name=\"%s\"", |
| 67 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 68 | ret = -1; |
| 69 | goto end; |
| 70 | } |
| 71 | |
| 72 | if (!bt_ctf_identifier_is_valid(name)) { |
| 73 | BT_LOGW("Clock class's name is not a valid CTF identifier: " |
| 74 | "addr=%p, name=\"%s\"", |
| 75 | clock_class, name); |
| 76 | ret = -1; |
| 77 | goto end; |
| 78 | } |
| 79 | |
| 80 | if (clock_class->name) { |
| 81 | g_string_assign(clock_class->name, name); |
| 82 | } else { |
| 83 | clock_class->name = g_string_new(name); |
| 84 | if (!clock_class->name) { |
| 85 | BT_LOGE_STR("Failed to allocate a GString."); |
| 86 | ret = -1; |
| 87 | goto end; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | BT_LOGV("Set clock class's name: addr=%p, name=\"%s\"", |
| 92 | clock_class, name); |
| 93 | |
| 94 | end: |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | static |
| 99 | bool validate_freq(struct bt_ctf_clock_class *clock_class, |
| 100 | const char *name, uint64_t freq) |
| 101 | { |
| 102 | bool is_valid = true; |
| 103 | |
| 104 | if (freq == -1ULL || freq == 0) { |
| 105 | BT_LOGW("Invalid parameter: frequency is invalid: " |
| 106 | "addr=%p, name=\"%s\", freq=%" PRIu64, |
| 107 | clock_class, name, freq); |
| 108 | is_valid = false; |
| 109 | goto end; |
| 110 | } |
| 111 | |
| 112 | end: |
| 113 | return is_valid; |
| 114 | } |
| 115 | |
| 116 | BT_HIDDEN |
| 117 | struct bt_ctf_clock_class *bt_ctf_clock_class_create(const char *name, |
| 118 | uint64_t freq) |
| 119 | { |
| 120 | int ret; |
| 121 | struct bt_ctf_clock_class *clock_class = NULL; |
| 122 | |
| 123 | BT_LOGD("Creating default clock class object: name=\"%s\"", |
| 124 | name); |
| 125 | |
| 126 | if (!validate_freq(NULL, name, freq)) { |
| 127 | /* validate_freq() logs errors */ |
| 128 | goto error; |
| 129 | } |
| 130 | |
| 131 | clock_class = g_new0(struct bt_ctf_clock_class, 1); |
| 132 | if (!clock_class) { |
| 133 | BT_LOGE_STR("Failed to allocate one clock class."); |
| 134 | goto error; |
| 135 | } |
| 136 | |
| 137 | clock_class->precision = 1; |
| 138 | clock_class->frequency = freq; |
| 139 | bt_ctf_object_init_shared(&clock_class->base, bt_ctf_clock_class_destroy); |
| 140 | |
| 141 | if (name) { |
| 142 | ret = bt_ctf_clock_class_set_name(clock_class, name); |
| 143 | if (ret) { |
| 144 | /* bt_ctf_clock_class_set_name() logs errors */ |
| 145 | goto error; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | BT_LOGD("Created clock class object: addr=%p, name=\"%s\"", |
| 150 | clock_class, name); |
| 151 | return clock_class; |
| 152 | error: |
| 153 | BT_CTF_OBJECT_PUT_REF_AND_RESET(clock_class); |
| 154 | return clock_class; |
| 155 | } |
| 156 | |
| 157 | BT_HIDDEN |
| 158 | const char *bt_ctf_clock_class_get_name(struct bt_ctf_clock_class *clock_class) |
| 159 | { |
| 160 | const char *ret = NULL; |
| 161 | |
| 162 | if (!clock_class) { |
| 163 | BT_LOGW_STR("Invalid parameter: clock class is NULL."); |
| 164 | goto end; |
| 165 | } |
| 166 | |
| 167 | if (clock_class->name) { |
| 168 | ret = clock_class->name->str; |
| 169 | } |
| 170 | |
| 171 | end: |
| 172 | return ret; |
| 173 | } |
| 174 | |
| 175 | BT_HIDDEN |
| 176 | const char *bt_ctf_clock_class_get_description( |
| 177 | struct bt_ctf_clock_class *clock_class) |
| 178 | { |
| 179 | const char *ret = NULL; |
| 180 | |
| 181 | if (!clock_class) { |
| 182 | BT_LOGW_STR("Invalid parameter: clock class is NULL."); |
| 183 | goto end; |
| 184 | } |
| 185 | |
| 186 | if (clock_class->description) { |
| 187 | ret = clock_class->description->str; |
| 188 | } |
| 189 | end: |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | BT_HIDDEN |
| 194 | int bt_ctf_clock_class_set_description(struct bt_ctf_clock_class *clock_class, |
| 195 | const char *desc) |
| 196 | { |
| 197 | int ret = 0; |
| 198 | |
| 199 | if (!clock_class || !desc) { |
| 200 | BT_LOGW("Invalid parameter: clock class or description is NULL: " |
| 201 | "clock-class-addr=%p, name=\"%s\", desc-addr=%p", |
| 202 | clock_class, bt_ctf_clock_class_get_name(clock_class), |
| 203 | desc); |
| 204 | ret = -1; |
| 205 | goto end; |
| 206 | } |
| 207 | |
| 208 | if (clock_class->frozen) { |
| 209 | BT_LOGW("Invalid parameter: clock class is frozen: addr=%p, name=\"%s\"", |
| 210 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 211 | ret = -1; |
| 212 | goto end; |
| 213 | } |
| 214 | |
| 215 | clock_class->description = g_string_new(desc); |
| 216 | ret = clock_class->description ? 0 : -1; |
| 217 | BT_LOGV("Set clock class's description: addr=%p, " |
| 218 | "name=\"%s\", desc=\"%s\"", |
| 219 | clock_class, bt_ctf_clock_class_get_name(clock_class), desc); |
| 220 | end: |
| 221 | return ret; |
| 222 | } |
| 223 | |
| 224 | BT_HIDDEN |
| 225 | uint64_t bt_ctf_clock_class_get_frequency( |
| 226 | struct bt_ctf_clock_class *clock_class) |
| 227 | { |
| 228 | uint64_t ret = -1ULL; |
| 229 | |
| 230 | if (!clock_class) { |
| 231 | BT_LOGW_STR("Invalid parameter: clock class is NULL."); |
| 232 | goto end; |
| 233 | } |
| 234 | |
| 235 | ret = clock_class->frequency; |
| 236 | end: |
| 237 | return ret; |
| 238 | } |
| 239 | |
| 240 | BT_HIDDEN |
| 241 | int bt_ctf_clock_class_set_frequency(struct bt_ctf_clock_class *clock_class, |
| 242 | uint64_t freq) |
| 243 | { |
| 244 | int ret = 0; |
| 245 | |
| 246 | if (!clock_class) { |
| 247 | BT_LOGW("Invalid parameter: clock class is NULL or frequency is invalid: " |
| 248 | "addr=%p, name=\"%s\"", |
| 249 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 250 | ret = -1; |
| 251 | goto end; |
| 252 | } |
| 253 | |
| 254 | if (!validate_freq(clock_class, bt_ctf_clock_class_get_name(clock_class), |
| 255 | freq)) { |
| 256 | /* validate_freq() logs errors */ |
| 257 | goto end; |
| 258 | } |
| 259 | |
| 260 | if (clock_class->frozen) { |
| 261 | BT_LOGW("Invalid parameter: clock class is frozen: addr=%p, name=\"%s\"", |
| 262 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 263 | ret = -1; |
| 264 | goto end; |
| 265 | } |
| 266 | |
| 267 | clock_class->frequency = freq; |
| 268 | BT_LOGV("Set clock class's frequency: addr=%p, name=\"%s\", freq=%" PRIu64, |
| 269 | clock_class, bt_ctf_clock_class_get_name(clock_class), freq); |
| 270 | end: |
| 271 | return ret; |
| 272 | } |
| 273 | |
| 274 | BT_HIDDEN |
| 275 | uint64_t bt_ctf_clock_class_get_precision(struct bt_ctf_clock_class *clock_class) |
| 276 | { |
| 277 | uint64_t ret = -1ULL; |
| 278 | |
| 279 | if (!clock_class) { |
| 280 | BT_LOGW_STR("Invalid parameter: clock class is NULL."); |
| 281 | goto end; |
| 282 | } |
| 283 | |
| 284 | ret = clock_class->precision; |
| 285 | end: |
| 286 | return ret; |
| 287 | } |
| 288 | |
| 289 | BT_HIDDEN |
| 290 | int bt_ctf_clock_class_set_precision(struct bt_ctf_clock_class *clock_class, |
| 291 | uint64_t precision) |
| 292 | { |
| 293 | int ret = 0; |
| 294 | |
| 295 | if (!clock_class || precision == -1ULL) { |
| 296 | BT_LOGW("Invalid parameter: clock class is NULL or precision is invalid: " |
| 297 | "addr=%p, name=\"%s\", precision=%" PRIu64, |
| 298 | clock_class, bt_ctf_clock_class_get_name(clock_class), |
| 299 | precision); |
| 300 | ret = -1; |
| 301 | goto end; |
| 302 | } |
| 303 | |
| 304 | if (clock_class->frozen) { |
| 305 | BT_LOGW("Invalid parameter: clock class is frozen: addr=%p, name=\"%s\"", |
| 306 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 307 | ret = -1; |
| 308 | goto end; |
| 309 | } |
| 310 | |
| 311 | clock_class->precision = precision; |
| 312 | BT_LOGV("Set clock class's precision: addr=%p, name=\"%s\", precision=%" PRIu64, |
| 313 | clock_class, bt_ctf_clock_class_get_name(clock_class), |
| 314 | precision); |
| 315 | end: |
| 316 | return ret; |
| 317 | } |
| 318 | |
| 319 | BT_HIDDEN |
| 320 | int bt_ctf_clock_class_get_offset_s(struct bt_ctf_clock_class *clock_class, |
| 321 | int64_t *offset_s) |
| 322 | { |
| 323 | int ret = 0; |
| 324 | |
| 325 | if (!clock_class || !offset_s) { |
| 326 | BT_LOGW("Invalid parameter: clock class or offset pointer is NULL: " |
| 327 | "clock-class-addr=%p, name=\"%s\", offset-addr=%p", |
| 328 | clock_class, bt_ctf_clock_class_get_name(clock_class), |
| 329 | offset_s); |
| 330 | ret = -1; |
| 331 | goto end; |
| 332 | } |
| 333 | |
| 334 | *offset_s = clock_class->offset_s; |
| 335 | end: |
| 336 | return ret; |
| 337 | } |
| 338 | |
| 339 | BT_HIDDEN |
| 340 | int bt_ctf_clock_class_set_offset_s(struct bt_ctf_clock_class *clock_class, |
| 341 | int64_t offset_s) |
| 342 | { |
| 343 | int ret = 0; |
| 344 | |
| 345 | if (!clock_class) { |
| 346 | BT_LOGW_STR("Invalid parameter: clock class is NULL."); |
| 347 | ret = -1; |
| 348 | goto end; |
| 349 | } |
| 350 | |
| 351 | if (clock_class->frozen) { |
| 352 | BT_LOGW("Invalid parameter: clock class is frozen: addr=%p, name=\"%s\"", |
| 353 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 354 | ret = -1; |
| 355 | goto end; |
| 356 | } |
| 357 | |
| 358 | clock_class->offset_s = offset_s; |
| 359 | BT_LOGV("Set clock class's offset (seconds): " |
| 360 | "addr=%p, name=\"%s\", offset-s=%" PRId64, |
| 361 | clock_class, bt_ctf_clock_class_get_name(clock_class), |
| 362 | offset_s); |
| 363 | end: |
| 364 | return ret; |
| 365 | } |
| 366 | |
| 367 | BT_HIDDEN |
| 368 | int bt_ctf_clock_class_get_offset_cycles(struct bt_ctf_clock_class *clock_class, |
| 369 | int64_t *offset) |
| 370 | { |
| 371 | int ret = 0; |
| 372 | |
| 373 | if (!clock_class || !offset) { |
| 374 | BT_LOGW("Invalid parameter: clock class or offset pointer is NULL: " |
| 375 | "clock-class-addr=%p, name=\"%s\", offset-addr=%p", |
| 376 | clock_class, bt_ctf_clock_class_get_name(clock_class), |
| 377 | offset); |
| 378 | ret = -1; |
| 379 | goto end; |
| 380 | } |
| 381 | |
| 382 | *offset = clock_class->offset; |
| 383 | end: |
| 384 | return ret; |
| 385 | } |
| 386 | |
| 387 | BT_HIDDEN |
| 388 | int bt_ctf_clock_class_set_offset_cycles(struct bt_ctf_clock_class *clock_class, |
| 389 | int64_t offset) |
| 390 | { |
| 391 | int ret = 0; |
| 392 | |
| 393 | if (!clock_class) { |
| 394 | BT_LOGW_STR("Invalid parameter: clock class is NULL."); |
| 395 | ret = -1; |
| 396 | goto end; |
| 397 | } |
| 398 | |
| 399 | if (clock_class->frozen) { |
| 400 | BT_LOGW("Invalid parameter: clock class is frozen: addr=%p, name=\"%s\"", |
| 401 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 402 | ret = -1; |
| 403 | goto end; |
| 404 | } |
| 405 | |
| 406 | clock_class->offset = offset; |
| 407 | BT_LOGV("Set clock class's offset (cycles): addr=%p, name=\"%s\", offset-cycles=%" PRId64, |
| 408 | clock_class, bt_ctf_clock_class_get_name(clock_class), offset); |
| 409 | end: |
| 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | BT_HIDDEN |
| 414 | bt_bool bt_ctf_clock_class_is_absolute(struct bt_ctf_clock_class *clock_class) |
| 415 | { |
| 416 | int ret = -1; |
| 417 | |
| 418 | if (!clock_class) { |
| 419 | BT_LOGW_STR("Invalid parameter: clock class is NULL."); |
| 420 | goto end; |
| 421 | } |
| 422 | |
| 423 | ret = clock_class->absolute; |
| 424 | end: |
| 425 | return ret; |
| 426 | } |
| 427 | |
| 428 | BT_HIDDEN |
| 429 | int bt_ctf_clock_class_set_is_absolute(struct bt_ctf_clock_class *clock_class, |
| 430 | bt_bool is_absolute) |
| 431 | { |
| 432 | int ret = 0; |
| 433 | |
| 434 | if (!clock_class) { |
| 435 | BT_LOGW_STR("Invalid parameter: clock class is NULL."); |
| 436 | ret = -1; |
| 437 | goto end; |
| 438 | } |
| 439 | |
| 440 | if (clock_class->frozen) { |
| 441 | BT_LOGW("Invalid parameter: clock class is frozen: addr=%p, name=\"%s\"", |
| 442 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 443 | ret = -1; |
| 444 | goto end; |
| 445 | } |
| 446 | |
| 447 | clock_class->absolute = !!is_absolute; |
| 448 | BT_LOGV("Set clock class's absolute flag: addr=%p, name=\"%s\", is-absolute=%d", |
| 449 | clock_class, bt_ctf_clock_class_get_name(clock_class), |
| 450 | is_absolute); |
| 451 | end: |
| 452 | return ret; |
| 453 | } |
| 454 | |
| 455 | BT_HIDDEN |
| 456 | const unsigned char *bt_ctf_clock_class_get_uuid( |
| 457 | struct bt_ctf_clock_class *clock_class) |
| 458 | { |
| 459 | const unsigned char *ret; |
| 460 | |
| 461 | if (!clock_class) { |
| 462 | BT_LOGW_STR("Invalid parameter: clock class is NULL."); |
| 463 | ret = NULL; |
| 464 | goto end; |
| 465 | } |
| 466 | |
| 467 | if (!clock_class->uuid_set) { |
| 468 | BT_LOGV("Clock class's UUID is not set: addr=%p, name=\"%s\"", |
| 469 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 470 | ret = NULL; |
| 471 | goto end; |
| 472 | } |
| 473 | |
| 474 | ret = clock_class->uuid; |
| 475 | end: |
| 476 | return ret; |
| 477 | } |
| 478 | |
| 479 | BT_HIDDEN |
| 480 | int bt_ctf_clock_class_set_uuid(struct bt_ctf_clock_class *clock_class, |
| 481 | const unsigned char *uuid) |
| 482 | { |
| 483 | int ret = 0; |
| 484 | |
| 485 | if (!clock_class || !uuid) { |
| 486 | BT_LOGW("Invalid parameter: clock class or UUID is NULL: " |
| 487 | "clock-class-addr=%p, name=\"%s\", uuid-addr=%p", |
| 488 | clock_class, bt_ctf_clock_class_get_name(clock_class), |
| 489 | uuid); |
| 490 | ret = -1; |
| 491 | goto end; |
| 492 | } |
| 493 | |
| 494 | if (clock_class->frozen) { |
| 495 | BT_LOGW("Invalid parameter: clock class is frozen: addr=%p, name=\"%s\"", |
| 496 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 497 | ret = -1; |
| 498 | goto end; |
| 499 | } |
| 500 | |
| 501 | memcpy(clock_class->uuid, uuid, BABELTRACE_UUID_LEN); |
| 502 | clock_class->uuid_set = 1; |
| 503 | BT_LOGV("Set clock class's UUID: addr=%p, name=\"%s\", " |
| 504 | "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"", |
| 505 | clock_class, bt_ctf_clock_class_get_name(clock_class), |
| 506 | (unsigned int) uuid[0], |
| 507 | (unsigned int) uuid[1], |
| 508 | (unsigned int) uuid[2], |
| 509 | (unsigned int) uuid[3], |
| 510 | (unsigned int) uuid[4], |
| 511 | (unsigned int) uuid[5], |
| 512 | (unsigned int) uuid[6], |
| 513 | (unsigned int) uuid[7], |
| 514 | (unsigned int) uuid[8], |
| 515 | (unsigned int) uuid[9], |
| 516 | (unsigned int) uuid[10], |
| 517 | (unsigned int) uuid[11], |
| 518 | (unsigned int) uuid[12], |
| 519 | (unsigned int) uuid[13], |
| 520 | (unsigned int) uuid[14], |
| 521 | (unsigned int) uuid[15]); |
| 522 | end: |
| 523 | return ret; |
| 524 | } |
| 525 | |
| 526 | BT_HIDDEN |
| 527 | void bt_ctf_clock_class_freeze(struct bt_ctf_clock_class *clock_class) |
| 528 | { |
| 529 | if (!clock_class || clock_class->frozen) { |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | BT_LOGD("Freezing clock class: addr=%p, name=\"%s\"", |
| 534 | clock_class, bt_ctf_clock_class_get_name(clock_class)); |
| 535 | clock_class->frozen = 1; |
| 536 | } |
| 537 | |
| 538 | static |
| 539 | void bt_ctf_clock_class_destroy(struct bt_ctf_object *obj) |
| 540 | { |
| 541 | struct bt_ctf_clock_class *clock_class; |
| 542 | |
| 543 | clock_class = container_of(obj, struct bt_ctf_clock_class, base); |
| 544 | BT_LOGD("Destroying clock class: addr=%p, name=\"%s\"", |
| 545 | obj, bt_ctf_clock_class_get_name(clock_class)); |
| 546 | |
| 547 | if (clock_class->name) { |
| 548 | g_string_free(clock_class->name, TRUE); |
| 549 | } |
| 550 | |
| 551 | if (clock_class->description) { |
| 552 | g_string_free(clock_class->description, TRUE); |
| 553 | } |
| 554 | |
| 555 | g_free(clock_class); |
| 556 | } |
| 557 | |
| 558 | BT_HIDDEN |
| 559 | int bt_ctf_clock_class_compare(struct bt_ctf_clock_class *clock_class_a, |
| 560 | struct bt_ctf_clock_class *clock_class_b) |
| 561 | { |
| 562 | int ret = 1; |
| 563 | BT_ASSERT(clock_class_a); |
| 564 | BT_ASSERT(clock_class_b); |
| 565 | |
| 566 | /* Name */ |
| 567 | if (strcmp(clock_class_a->name->str, clock_class_b->name->str) != 0) { |
| 568 | BT_LOGV("Clock classes differ: different names: " |
| 569 | "cc-a-name=\"%s\", cc-b-name=\"%s\"", |
| 570 | clock_class_a->name->str, |
| 571 | clock_class_b->name->str); |
| 572 | goto end; |
| 573 | } |
| 574 | |
| 575 | /* Description */ |
| 576 | if (clock_class_a->description) { |
| 577 | if (!clock_class_b->description) { |
| 578 | BT_LOGV_STR("Clock classes differ: clock class A has a " |
| 579 | "description, but clock class B does not."); |
| 580 | goto end; |
| 581 | } |
| 582 | |
| 583 | if (strcmp(clock_class_a->name->str, clock_class_b->name->str) |
| 584 | != 0) { |
| 585 | BT_LOGV("Clock classes differ: different descriptions: " |
| 586 | "cc-a-descr=\"%s\", cc-b-descr=\"%s\"", |
| 587 | clock_class_a->description->str, |
| 588 | clock_class_b->description->str); |
| 589 | goto end; |
| 590 | } |
| 591 | } else { |
| 592 | if (clock_class_b->description) { |
| 593 | BT_LOGV_STR("Clock classes differ: clock class A has " |
| 594 | "no description, but clock class B has one."); |
| 595 | goto end; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | /* Frequency */ |
| 600 | if (clock_class_a->frequency != clock_class_b->frequency) { |
| 601 | BT_LOGV("Clock classes differ: different frequencies: " |
| 602 | "cc-a-freq=%" PRIu64 ", cc-b-freq=%" PRIu64, |
| 603 | clock_class_a->frequency, |
| 604 | clock_class_b->frequency); |
| 605 | goto end; |
| 606 | } |
| 607 | |
| 608 | /* Precision */ |
| 609 | if (clock_class_a->precision != clock_class_b->precision) { |
| 610 | BT_LOGV("Clock classes differ: different precisions: " |
| 611 | "cc-a-freq=%" PRIu64 ", cc-b-freq=%" PRIu64, |
| 612 | clock_class_a->precision, |
| 613 | clock_class_b->precision); |
| 614 | goto end; |
| 615 | } |
| 616 | |
| 617 | /* Offset (seconds) */ |
| 618 | if (clock_class_a->offset_s != clock_class_b->offset_s) { |
| 619 | BT_LOGV("Clock classes differ: different offsets (seconds): " |
| 620 | "cc-a-offset-s=%" PRId64 ", cc-b-offset-s=%" PRId64, |
| 621 | clock_class_a->offset_s, |
| 622 | clock_class_b->offset_s); |
| 623 | goto end; |
| 624 | } |
| 625 | |
| 626 | /* Offset (cycles) */ |
| 627 | if (clock_class_a->offset != clock_class_b->offset) { |
| 628 | BT_LOGV("Clock classes differ: different offsets (cycles): " |
| 629 | "cc-a-offset-s=%" PRId64 ", cc-b-offset-s=%" PRId64, |
| 630 | clock_class_a->offset, |
| 631 | clock_class_b->offset); |
| 632 | goto end; |
| 633 | } |
| 634 | |
| 635 | /* UUIDs */ |
| 636 | if (clock_class_a->uuid_set) { |
| 637 | if (!clock_class_b->uuid_set) { |
| 638 | BT_LOGV_STR("Clock classes differ: clock class A has a " |
| 639 | "UUID, but clock class B does not."); |
| 640 | goto end; |
| 641 | } |
| 642 | |
| 643 | if (memcmp(clock_class_a->uuid, clock_class_b->uuid, |
| 644 | BABELTRACE_UUID_LEN) != 0) { |
| 645 | BT_LOGV("Clock classes differ: different UUIDs: " |
| 646 | "cc-a-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", " |
| 647 | "cc-b-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"", |
| 648 | (unsigned int) clock_class_a->uuid[0], |
| 649 | (unsigned int) clock_class_a->uuid[1], |
| 650 | (unsigned int) clock_class_a->uuid[2], |
| 651 | (unsigned int) clock_class_a->uuid[3], |
| 652 | (unsigned int) clock_class_a->uuid[4], |
| 653 | (unsigned int) clock_class_a->uuid[5], |
| 654 | (unsigned int) clock_class_a->uuid[6], |
| 655 | (unsigned int) clock_class_a->uuid[7], |
| 656 | (unsigned int) clock_class_a->uuid[8], |
| 657 | (unsigned int) clock_class_a->uuid[9], |
| 658 | (unsigned int) clock_class_a->uuid[10], |
| 659 | (unsigned int) clock_class_a->uuid[11], |
| 660 | (unsigned int) clock_class_a->uuid[12], |
| 661 | (unsigned int) clock_class_a->uuid[13], |
| 662 | (unsigned int) clock_class_a->uuid[14], |
| 663 | (unsigned int) clock_class_a->uuid[15], |
| 664 | (unsigned int) clock_class_b->uuid[0], |
| 665 | (unsigned int) clock_class_b->uuid[1], |
| 666 | (unsigned int) clock_class_b->uuid[2], |
| 667 | (unsigned int) clock_class_b->uuid[3], |
| 668 | (unsigned int) clock_class_b->uuid[4], |
| 669 | (unsigned int) clock_class_b->uuid[5], |
| 670 | (unsigned int) clock_class_b->uuid[6], |
| 671 | (unsigned int) clock_class_b->uuid[7], |
| 672 | (unsigned int) clock_class_b->uuid[8], |
| 673 | (unsigned int) clock_class_b->uuid[9], |
| 674 | (unsigned int) clock_class_b->uuid[10], |
| 675 | (unsigned int) clock_class_b->uuid[11], |
| 676 | (unsigned int) clock_class_b->uuid[12], |
| 677 | (unsigned int) clock_class_b->uuid[13], |
| 678 | (unsigned int) clock_class_b->uuid[14], |
| 679 | (unsigned int) clock_class_b->uuid[15]); |
| 680 | goto end; |
| 681 | } |
| 682 | } else { |
| 683 | if (clock_class_b->uuid_set) { |
| 684 | BT_LOGV_STR("Clock classes differ: clock class A has " |
| 685 | "no UUID, but clock class B has one."); |
| 686 | goto end; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | /* Absolute */ |
| 691 | if (!!clock_class_a->absolute != !!clock_class_b->absolute) { |
| 692 | BT_LOGV("Clock classes differ: one is absolute, the other " |
| 693 | "is not: cc-a-is-absolute=%d, cc-b-is-absolute=%d", |
| 694 | !!clock_class_a->absolute, |
| 695 | !!clock_class_b->absolute); |
| 696 | goto end; |
| 697 | } |
| 698 | |
| 699 | /* Equal */ |
| 700 | ret = 0; |
| 701 | |
| 702 | end: |
| 703 | return ret; |
| 704 | } |