+
+static
+int compare_clock_classes(const bt_clock_class *left_cc,
+ const bt_clock_class *right_cc)
+{
+ int ret;
+ const char *left_clock_class_name, *right_clock_class_name;
+ bt_uuid left_clock_class_uuid, right_clock_class_uuid;
+ uint64_t left_freq, right_freq, left_prec, right_prec;
+
+ left_clock_class_uuid = bt_clock_class_get_uuid(left_cc);
+ right_clock_class_uuid = bt_clock_class_get_uuid(right_cc);
+
+ if (left_clock_class_uuid && !right_clock_class_uuid) {
+ ret = -1;
+ goto end;
+ } else if (!left_clock_class_uuid && right_clock_class_uuid) {
+ ret = 1;
+ goto end;
+ } else if (left_clock_class_uuid && right_clock_class_uuid) {
+ ret = bt_uuid_compare(left_clock_class_uuid,
+ right_clock_class_uuid);
+ if (ret != 0) {
+ goto end;
+ }
+ }
+
+
+ left_clock_class_name = bt_clock_class_get_name(left_cc);
+ right_clock_class_name = bt_clock_class_get_name(right_cc);
+
+ if (left_clock_class_name && !right_clock_class_name) {
+ ret = -1;
+ goto end;
+ } else if (!left_clock_class_name && right_clock_class_name) {
+ ret = 1;
+ goto end;
+ } else if (left_clock_class_name && right_clock_class_name) {
+ ret = strcmp(left_clock_class_name, right_clock_class_name);
+ if (ret != 0) {
+ goto end;
+ }
+ }
+
+ left_freq = bt_clock_class_get_frequency(left_cc);
+ right_freq = bt_clock_class_get_frequency(right_cc);
+
+ ret = right_freq - left_freq;
+ if (ret != 0) {
+ goto end;
+ }
+
+ left_prec = bt_clock_class_get_precision(left_cc);
+ right_prec = bt_clock_class_get_precision(right_cc);
+
+ ret = right_prec - left_prec;
+ if (ret != 0) {
+ goto end;
+ }
+
+end:
+ return ret;
+}
+