void CCommentaryReadWindow::applyProfileSettings(const QString & windowGroup) { CLexiconReadWindow::applyProfileSettings(windowGroup); BT_ASSERT(windowGroup.endsWith('/')); BT_ASSERT(m_syncButton); m_syncButton->setChecked(btConfig().sessionValue<bool>(windowGroup + "syncEnabled", false)); }
QString BtConfigCore::addSession(const QString & name) { BT_ASSERT(!name.isEmpty()); // Generate a new session key: QString key = QString::number(0u, 36); QMutexLocker lock(&m_mutex); if (m_sessionNames.contains(key)) { QString keyPrefix; std::size_t i = 1u; for (;;) { key = QString::number(i, 36); if (!m_sessionNames.contains(keyPrefix + key)) break; if (i == std::numeric_limits<std::size_t>::max()) { i = 0u; keyPrefix.append('_'); } else { i++; } }; } BT_ASSERT(!m_sessionNames.contains(key)); m_sessionNames.insert(key, name); m_settings.setValue(KEY_SESSION_NAME.arg(key), name); m_settings.sync(); return key; }
const QString Rendering::CChapterDisplay::text( const BtConstModuleList &modules, const QString &keyName, const DisplayOptions &displayOptions, const FilterOptions &filterOptions) { using CSBMI = CSwordBibleModuleInfo; BT_ASSERT(modules.count() >= 1); BT_ASSERT(!keyName.isEmpty()); const CSwordModuleInfo *module = modules.first(); if (modules.count() == 1) module->module().setSkipConsecutiveLinks( true ); //skip empty, linked verses CTextRendering::KeyTreeItem::Settings settings; settings.keyRenderingFace = displayOptions.verseNumbers ? CTextRendering::KeyTreeItem::Settings::SimpleKey : CTextRendering::KeyTreeItem::Settings::NoKey; QString startKey = keyName; QString endKey = startKey; //check whether there's an intro we have to include BT_ASSERT((module->type() == CSwordModuleInfo::Bible)); if (module->type() == CSwordModuleInfo::Bible) { // HACK: enable headings for VerseKeys: static_cast<sword::VerseKey *>(module->module().getKey()) ->setIntros(true); BT_ASSERT(dynamic_cast<CSBMI const *>(module)); const CSBMI *bible = static_cast<const CSBMI*>(module); CSwordVerseKey k1(module); k1.setIntros(true); k1.setKey(keyName); if (k1.getChapter() == 1) k1.setChapter(0); // Chapter 1, start with 0:0, otherwise X:0 k1.setVerse(0); startKey = k1.key(); if (k1.getChapter() == 0) k1.setChapter(1); k1.setVerse(bible->verseCount(k1.book(), k1.getChapter())); endKey = k1.key(); } CDisplayRendering render(displayOptions, filterOptions); return render.renderKeyRange( startKey, endKey, modules, keyName, settings ); }
void BtConfigCore::deleteSession(const QString & key) { QMutexLocker lock(&m_mutex); BT_ASSERT(m_sessionNames.contains(key)); BT_ASSERT(key != m_currentSessionKey); m_sessionNames.remove(key); m_settings.remove(GROUP_SESSIONS + key); m_settings.sync(); }
void CCommentaryReadWindow::storeProfileSettings(QString const & windowGroup) const { CLexiconReadWindow::storeProfileSettings(windowGroup); BT_ASSERT(windowGroup.endsWith('/')); BT_ASSERT(m_syncButton); btConfig().setSessionValue(windowGroup + "syncEnabled", m_syncButton->isChecked()); }
void BtBookshelfWidget::setTreeModel(BtBookshelfTreeModel *model) { BT_ASSERT(model); BT_ASSERT(!m_treeModel); m_treeModel = model; if (m_sourceModel != nullptr) { model->setSourceModel(m_sourceModel); } m_postFilterModel->setSourceModel(model); }
void BtConfigCore::setCurrentSession(const QString & key) { BT_ASSERT(!key.isEmpty()); QMutexLocker lock(&m_mutex); BT_ASSERT(m_sessionNames.contains(key)); m_currentSessionKey = key; m_cachedCurrentSessionGroup = GROUP_SESSION.arg(key); m_settings.setValue(KEY_CURRENT_SESSION, key); m_settings.sync(); }
static GList *ctf_fs_create_trace_names(GList *trace_paths, const char *base_path) { GList *trace_names = NULL; GList *node; const char *last_sep; size_t base_dist; /* * At this point we know that all the trace paths are * normalized, and so is the base path. This means that * they are absolute and they don't end with a separator. * We can simply find the location of the last separator * in the base path, which gives us the name of the actual * directory to look into, and use this location as the * start of each trace name within each trace path. * * For example: * * Base path: /home/user/my-traces/some-trace * Trace paths: * - /home/user/my-traces/some-trace/host1/trace1 * - /home/user/my-traces/some-trace/host1/trace2 * - /home/user/my-traces/some-trace/host2/trace * - /home/user/my-traces/some-trace/other-trace * * In this case the trace names are: * * - some-trace/host1/trace1 * - some-trace/host1/trace2 * - some-trace/host2/trace * - some-trace/other-trace */ last_sep = strrchr(base_path, G_DIR_SEPARATOR); /* We know there's at least one separator */ BT_ASSERT(last_sep); /* Distance to base */ base_dist = last_sep - base_path + 1; /* Create the trace names */ for (node = trace_paths; node; node = g_list_next(node)) { GString *trace_name = g_string_new(NULL); GString *trace_path = node->data; BT_ASSERT(trace_name); g_string_assign(trace_name, &trace_path->str[base_dist]); trace_names = g_list_append(trace_names, trace_name); } return trace_names; }
static void merge_ctf_fs_traces(struct ctf_fs_trace **traces, unsigned int num_traces) { unsigned int winner_count; struct ctf_fs_trace *winner; guint i; char uuid_str[BABELTRACE_UUID_STR_LEN]; BT_ASSERT(num_traces >= 2); winner_count = metadata_count_stream_and_event_classes(traces[0]); winner = traces[0]; /* Find the trace with the largest metadata. */ for (i = 1; i < num_traces; i++) { struct ctf_fs_trace *candidate; unsigned int candidate_count; candidate = traces[i]; /* A bit of sanity check. */ BT_ASSERT(bt_uuid_compare(winner->metadata->tc->uuid, candidate->metadata->tc->uuid) == 0); candidate_count = metadata_count_stream_and_event_classes(candidate); if (candidate_count > winner_count) { winner_count = candidate_count; winner = candidate; } } /* Merge all the other traces in the winning trace. */ for (i = 0; i < num_traces; i++) { struct ctf_fs_trace *trace = traces[i]; /* Don't merge the winner into itself. */ if (trace == winner) { continue; } /* Merge trace's data stream file groups into winner's. */ merge_matching_ctf_fs_ds_file_groups(winner, trace); /* Free the trace that got merged into winner, clear the slot in the array. */ ctf_fs_trace_destroy(trace); traces[i] = NULL; } /* Use the string representation of the UUID as the trace name. */ bt_uuid_unparse(winner->metadata->tc->uuid, uuid_str); g_string_printf(winner->name, "%s", uuid_str); }
static struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) { int i; int ret; struct bt_value *copy_obj; struct bt_value_array *typed_array_obj; BT_LOGD("Copying array value: addr=%p", array_obj); typed_array_obj = BT_VALUE_TO_ARRAY(array_obj); copy_obj = bt_value_array_create(); if (!copy_obj) { BT_LOGE_STR("Cannot create empty array value."); goto end; } for (i = 0; i < typed_array_obj->garray->len; ++i) { struct bt_value *element_obj_copy = NULL; const struct bt_value *element_obj = bt_value_array_borrow_element_by_index_const( array_obj, i); BT_ASSERT(element_obj); BT_LOGD("Copying array value's element: element-addr=%p, " "index=%d", element_obj, i); ret = bt_value_copy(element_obj, &element_obj_copy); if (ret) { BT_LOGE("Cannot copy array value's element: " "array-addr=%p, index=%d", array_obj, i); BT_OBJECT_PUT_REF_AND_RESET(copy_obj); goto end; } BT_ASSERT(element_obj_copy); ret = bt_value_array_append_element(copy_obj, (void *) element_obj_copy); BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy); if (ret) { BT_LOGE("Cannot append to array value: addr=%p", array_obj); BT_OBJECT_PUT_REF_AND_RESET(copy_obj); goto end; } } BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p", array_obj, copy_obj); end: return copy_obj; }
static struct bt_value *bt_value_map_copy(const struct bt_value *map_obj) { int ret; GHashTableIter iter; gpointer key, element_obj; struct bt_value *copy_obj; struct bt_value *element_obj_copy = NULL; struct bt_value_map *typed_map_obj; BT_LOGD("Copying map value: addr=%p", map_obj); typed_map_obj = BT_VALUE_TO_MAP(map_obj); copy_obj = bt_value_map_create(); if (!copy_obj) { goto end; } g_hash_table_iter_init(&iter, typed_map_obj->ght); while (g_hash_table_iter_next(&iter, &key, &element_obj)) { const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key)); BT_ASSERT(key_str); BT_LOGD("Copying map value's element: element-addr=%p, " "key=\"%s\"", element_obj, key_str); ret = bt_value_copy(element_obj, &element_obj_copy); if (ret) { BT_LOGE("Cannot copy map value's element: " "map-addr=%p, key=\"%s\"", map_obj, key_str); BT_OBJECT_PUT_REF_AND_RESET(copy_obj); goto end; } BT_ASSERT(element_obj_copy); ret = bt_value_map_insert_entry(copy_obj, key_str, (void *) element_obj_copy); BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy); if (ret) { BT_LOGE("Cannot insert into map value: addr=%p, key=\"%s\"", map_obj, key_str); BT_OBJECT_PUT_REF_AND_RESET(copy_obj); goto end; } } BT_LOGD("Copied map value: addr=%p", map_obj); end: return copy_obj; }
void BTHistory::move(QAction* historyItem) { //BT_ASSERT(historyItem); BT_ASSERT(m_historyList.count()); m_inHistoryFunction = true; //find the action in the list m_index = m_historyList.indexOf(historyItem); //move to the selected item in the list, it will be the current item emit historyMoved(m_historyList.at(m_index)->property(ActionText).toString()); // signal to "outsiders"; key has been changed sendChangedSignal(); m_inHistoryFunction = false; BT_ASSERT(class_invariant()); }
void BtConfigDialog::setButtonBox(QDialogButtonBox * const box) { BT_ASSERT(box); BT_ASSERT(m_pageLayout->count() == 1); // Only m_pageWidget in layout // First add a horizontal ruler: QFrame * const buttonBoxRuler = new QFrame(this); buttonBoxRuler->setGeometry(QRect(1, 1, 1, 3)); buttonBoxRuler->setFrameShape(QFrame::HLine); buttonBoxRuler->setFrameShadow(QFrame::Sunken); buttonBoxRuler->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); m_pageLayout->addWidget(buttonBoxRuler); // Add button box: m_pageLayout->addWidget(box); }
void BTHistory::add(CSwordKey* newKey) { BT_ASSERT(newKey); // Add new key Action after current index if we were not using the history functions, // if it's not a duplicate and if it's not empty. if (!m_inHistoryFunction && ((m_index < 0) || (newKey->key() != m_historyList.at(m_index)->property(ActionText).toString()) )) { if (!newKey->key().isEmpty()) { auto * const a = new QAction(newKey->key(), this); a->setProperty(ActionText, newKey->key()); m_historyList.insert(++m_index, a); } // \todo history limit? sendChangedSignal(); } BT_ASSERT(class_invariant()); }
BT_HIDDEN int bt_ctf_event_class_common_validate_single_clock_class( struct bt_ctf_event_class_common *event_class, struct bt_ctf_clock_class **expected_clock_class) { int ret = 0; BT_ASSERT(event_class); BT_ASSERT(expected_clock_class); ret = bt_ctf_field_type_common_validate_single_clock_class( event_class->context_field_type, expected_clock_class); if (ret) { BT_LOGW("Event class's context field type " "is not recursively mapped to the " "expected clock class: " "event-class-addr=%p, " "event-class-name=\"%s\", " "event-class-id=%" PRId64 ", " "ft-addr=%p", event_class, bt_ctf_event_class_common_get_name(event_class), event_class->id, event_class->context_field_type); goto end; } ret = bt_ctf_field_type_common_validate_single_clock_class( event_class->payload_field_type, expected_clock_class); if (ret) { BT_LOGW("Event class's payload field type " "is not recursively mapped to the " "expected clock class: " "event-class-addr=%p, " "event-class-name=\"%s\", " "event-class-id=%" PRId64 ", " "ft-addr=%p", event_class, bt_ctf_event_class_common_get_name(event_class), event_class->id, event_class->payload_field_type); goto end; } end: return ret; }
int64_t bt_ctf_event_class_get_payload_type_field_count( struct bt_ctf_event_class *event_class) { int64_t ret; if (!event_class) { BT_LOGW_STR("Invalid parameter: event class is NULL."); ret = (int64_t) -1; goto end; } if (!event_class->common.payload_field_type) { BT_LOGV("Event class has no payload field type: " "addr=%p, name=\"%s\", id=%" PRId64, event_class, bt_ctf_event_class_get_name(event_class), bt_ctf_event_class_get_id(event_class)); ret = (int64_t) -1; goto end; } BT_ASSERT(bt_ctf_field_type_common_get_type_id( event_class->common.payload_field_type) == BT_CTF_FIELD_TYPE_ID_STRUCT); ret = bt_ctf_field_type_common_structure_get_field_count( event_class->common.payload_field_type); end: return ret; }
struct bt_ctf_clock *bt_ctf_clock_create(const char *name) { int ret; struct bt_ctf_clock *clock = NULL; unsigned char cc_uuid[BABELTRACE_UUID_LEN]; BT_ASSERT_PRE_NON_NULL(name, "Name"); clock = g_new0(struct bt_ctf_clock, 1); if (!clock) { goto error; } bt_ctf_object_init_shared(&clock->base, bt_ctf_clock_destroy); clock->value = 0; /* Pre-2.0.0 backward compatibility: default frequency is 1 GHz */ clock->clock_class = (void *) bt_ctf_clock_class_create(name, 1000000000); if (!clock->clock_class) { goto error; } /* Automatically set clock class's UUID. */ ret = bt_uuid_generate(cc_uuid); if (ret) { goto error; } ret = bt_ctf_clock_class_set_uuid(clock->clock_class, cc_uuid); BT_ASSERT(ret == 0); return clock; error: BT_CTF_OBJECT_PUT_REF_AND_RESET(clock); return clock; }
BT_HIDDEN struct bt_clock_snapshot *bt_clock_snapshot_create( struct bt_clock_class *clock_class) { struct bt_clock_snapshot *clock_snapshot = NULL; BT_ASSERT(clock_class); clock_snapshot = bt_object_pool_create_object(&clock_class->cs_pool); if (!clock_snapshot) { BT_LIB_LOGE("Cannot allocate one clock snapshot from clock class's clock snapshot pool: " "%![cc-]+K", clock_class); goto error; } if (likely(!clock_snapshot->clock_class)) { clock_snapshot->clock_class = clock_class; bt_object_get_no_null_check(clock_class); } goto end; error: if (clock_snapshot) { bt_clock_snapshot_recycle(clock_snapshot); clock_snapshot = NULL; } end: return clock_snapshot; }
static struct ctf_fs_ds_file_group *ctf_fs_ds_file_group_create( struct ctf_fs_trace *ctf_fs_trace, struct ctf_stream_class *sc, uint64_t stream_instance_id) { struct ctf_fs_ds_file_group *ds_file_group; ds_file_group = g_new0(struct ctf_fs_ds_file_group, 1); if (!ds_file_group) { goto error; } ds_file_group->ds_file_infos = g_ptr_array_new_with_free_func( (GDestroyNotify) ctf_fs_ds_file_info_destroy); if (!ds_file_group->ds_file_infos) { goto error; } ds_file_group->stream_id = stream_instance_id; BT_ASSERT(sc); ds_file_group->sc = sc; ds_file_group->ctf_fs_trace = ctf_fs_trace; goto end; error: ctf_fs_ds_file_group_destroy(ds_file_group); ds_file_group = NULL; end: return ds_file_group; }
static int msg_iter_data_set_current_ds_file(struct ctf_fs_msg_iter_data *msg_iter_data) { struct ctf_fs_ds_file_info *ds_file_info; int ret = 0; BT_ASSERT(msg_iter_data->ds_file_info_index < msg_iter_data->ds_file_group->ds_file_infos->len); ds_file_info = g_ptr_array_index( msg_iter_data->ds_file_group->ds_file_infos, msg_iter_data->ds_file_info_index); ctf_fs_ds_file_destroy(msg_iter_data->ds_file); msg_iter_data->ds_file = ctf_fs_ds_file_create( msg_iter_data->ds_file_group->ctf_fs_trace, msg_iter_data->pc_msg_iter, msg_iter_data->msg_iter, msg_iter_data->ds_file_group->stream, ds_file_info->path->str); if (!msg_iter_data->ds_file) { ret = -1; } return ret; }
static bool stream_classes_all_have_default_clock_class(bt_trace_class *tc) { uint64_t i, sc_count; const bt_clock_class *cc = NULL; const bt_stream_class *sc; bool ret = true; sc_count = bt_trace_class_get_stream_class_count(tc); for (i = 0; i < sc_count; i++) { sc = bt_trace_class_borrow_stream_class_by_index_const(tc, i); BT_ASSERT(sc); cc = bt_stream_class_borrow_default_clock_class_const(sc); if (!cc) { ret = false; BT_LOGE("Stream class doesn't have a default clock class: " "sc-id=%" PRIu64 ", sc-name=\"%s\"", bt_stream_class_get_id(sc), bt_stream_class_get_name(sc)); goto end; } } end: return ret; }
/** \returns index of this item in parent's child array. */ inline int index() const { BT_ASSERT(parent()); for(int i = 0; i < parent()->childCount(); ++i) if(parent()->child(i) == this) return i; return -1; }
static int add_trace_path(GList **trace_paths, const char *path) { GString *norm_path = NULL; int ret = 0; norm_path = bt_common_normalize_path(path, NULL); if (!norm_path) { BT_LOGE("Failed to normalize path `%s`.", path); ret = -1; goto end; } // FIXME: Remove or ifdef for __MINGW32__ if (strcmp(norm_path->str, "/") == 0) { BT_LOGE("Opening a trace in `/` is not supported."); ret = -1; goto end; } *trace_paths = g_list_prepend(*trace_paths, norm_path); BT_ASSERT(*trace_paths); norm_path = NULL; end: if (norm_path) { g_string_free(norm_path, TRUE); } return ret; }
inline BookmarkItemBase(BookmarkItemBase * parent = nullptr) : m_parent(parent) { if(m_parent) { BT_ASSERT(!m_parent->m_children.contains(this)); m_parent->m_children.append(this); } }
struct bt_packet_context_field *bt_packet_context_field_create( struct bt_stream_class *stream_class) { struct bt_field_wrapper *field_wrapper; BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); BT_ASSERT_PRE(stream_class->frozen, "Stream class is not part of a trace class: %!+S", stream_class); BT_ASSERT_PRE(stream_class->packet_context_fc, "Stream class has no packet context field class: %!+S", stream_class); field_wrapper = bt_field_wrapper_create( &stream_class->packet_context_field_pool, (void *) stream_class->packet_context_fc); if (!field_wrapper) { BT_LIB_LOGE("Cannot allocate one packet context field from stream class: " "%![sc-]+S", stream_class); goto error; } BT_ASSERT(field_wrapper->field); bt_stream_class_freeze(stream_class); goto end; error: if (field_wrapper) { bt_field_wrapper_destroy(field_wrapper); field_wrapper = NULL; } end: return (void *) field_wrapper; }
void BtBookshelfDockWidget::slotModuleActivated(CSwordModuleInfo *module) { if (!module->isLocked()) { emit moduleOpenTriggered(module); } else { /** \todo Implement a better unlock dialog, which could incorporate the following warning message. Actually the whole case when the user tries to open a locked module needs to be rethought and refactored. */ message::showWarning(this, tr("Warning: Module locked!"), tr("You are trying to access an encrypted module. Please " "provide an unlock key in the following dialog to open the " "module.")); /// \todo We need to keep the module name because unlocking currently reloads sword. const QString moduleName(module->name()); if (BibleTime::moduleUnlock(module)) { // Re-initialize module pointer: module = CSwordBackend::instance()->findModuleByName(moduleName); BT_ASSERT(module); emit moduleOpenTriggered(module); } } }
void BtBookshelfWidget::setSourceModel(QAbstractItemModel *model) { BT_ASSERT(model); m_sourceModel = model; if (m_treeModel != nullptr) { m_treeModel->setSourceModel(model); } }
int bt_ctf_event_class_get_payload_type_field_by_index( struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, uint64_t index) { int ret; if (!event_class) { BT_LOGW_STR("Invalid parameter: event class is NULL."); ret = -1; goto end; } if (!event_class->common.payload_field_type) { BT_LOGV("Event class has no payload field type: " "addr=%p, name=\"%s\", id=%" PRId64 ", index=%" PRIu64, event_class, bt_ctf_event_class_get_name(event_class), bt_ctf_event_class_get_id(event_class), index); ret = -1; goto end; } BT_ASSERT(bt_ctf_field_type_common_get_type_id( event_class->common.payload_field_type) == BT_CTF_FIELD_TYPE_ID_STRUCT); ret = bt_ctf_field_type_structure_get_field_by_index( (void *) event_class->common.payload_field_type, field_name, (void *) field_type, index); end: return ret; }
QString BtBookshelfWizard::installPath() const { WizardTaskType const iType = m_taskPage->taskType(); if (iType == WizardTaskType::installWorks) return m_installWorksPage->installPath(); BT_ASSERT(iType == WizardTaskType::updateWorks); return m_updateWorksPage->installPath(); }
BTHistory::BTHistory(QWidget* parent) : m_historyList(), m_index(-1), m_inHistoryFunction(false) { setParent(parent); BT_ASSERT(class_invariant()); }