/** Returns pointer to default gain/loss policy for book, if one exists in the * KVP, or NULL; does not validate contents nor determine if there is a valid * book-currency, both of which are required, for the 'book-currency' * currency accounting method to apply. Use instead * 'gnc_book_get_default_gains_policy' which does these validations. */ const gchar * qof_book_get_default_gains_policy (QofBook *book) { KvpFrame *kvp; KvpValue *value; if (!book) { PWARN ("No book!!!"); return NULL; } /* Get the KVP from the current book */ kvp = qof_instance_get_slots (QOF_INSTANCE (book)); if (!kvp) { PWARN ("Book has no KVP_Frame"); return NULL; } /* See if there is a default gain/loss policy */ value = kvp->get_slot({KVP_OPTION_PATH, OPTION_SECTION_ACCOUNTS, OPTION_NAME_DEFAULT_GAINS_POLICY}); if (!value) /* No default gain/loss policy, therefore not valid book-currency accounting method */ return nullptr; return g_strdup(value->get<const char*>()); }
gboolean xaccScrubMergeSubSplits (Split *split, gboolean strict) { gboolean rc = FALSE; Transaction *txn; SplitList *node; GNCLot *lot; if (strict && (FALSE == is_subsplit (split))) return FALSE; txn = split->parent; // Don't mess with splits from an invoice transaction // Those are the responsibility of the business code if (gncInvoiceGetInvoiceFromTxn (txn)) return FALSE; lot = xaccSplitGetLot (split); ENTER ("(Lot=%s)", gnc_lot_get_title(lot)); restart: for (node = txn->splits; node; node = node->next) { Split *s = node->data; if (xaccSplitGetLot (s) != lot) continue; if (s == split) continue; if (qof_instance_get_destroying(s)) continue; // Don't mess with splits from an invoice transaction // Those are the responsibility of the business code if (gncInvoiceGetInvoiceFromTxn (s->parent)) return FALSE; if (strict) { /* OK, this split is in the same lot (and thus same account) * as the indicated split. Make sure it is really a subsplit * of the split we started with. It's possible to have two * splits in the same lot and transaction that are not subsplits * of each other, the test-period test suite does this, for * example. Only worry about adjacent sub-splits. By * repeatedly merging adjacent subsplits, we'll get the non- * adjacent ones too. */ if (!xaccSplitIsPeerSplit (split, s)) continue; } merge_splits (split, s); rc = TRUE; goto restart; } if (rc && gnc_numeric_zero_p (split->amount)) { time64 pdate = xaccTransGetDate (txn); gchar *pdatestr = gnc_ctime (&pdate); PWARN ("Result of merge has zero amt!"); PWARN ("Transaction details - posted date %s - description %s", pdatestr, xaccTransGetDescription(txn)); g_free (pdatestr); } LEAVE (" splits merged=%d", rc); return rc; }
gboolean gncTaxTableEntryEqual(const GncTaxTableEntry *a, const GncTaxTableEntry *b) { if (a == NULL && b == NULL) return TRUE; if (a == NULL || b == NULL) return FALSE; if (!xaccAccountEqual(a->account, b->account, TRUE)) { PWARN("accounts differ"); return FALSE; } if (a->type != b->type) { PWARN("types differ"); return FALSE; } if (!gnc_numeric_equal(a->amount, b->amount)) { PWARN("amounts differ"); return FALSE; } return TRUE; }
char * gnc_timespec_to_iso8601_buff (Timespec ts, char * buff) { constexpr size_t max_iso_date_length = 32; const char* format = "%Y-%m-%d %H:%M:%s %q"; if (! buff) return NULL; try { GncDateTime gncdt(ts.tv_sec); auto sstr = gncdt.format(format); memset(buff, 0, sstr.length() + 1); strncpy(buff, sstr.c_str(), sstr.length()); return buff + sstr.length(); } catch(std::logic_error& err) { PWARN("Error processing time64 %" PRId64 ": %s", ts.tv_sec, err.what()); return buff; } catch(std::runtime_error& err) { PWARN("Error processing time64 %" PRId64 ": %s", ts.tv_sec, err.what()); return buff; } }
gint64 qof_book_get_counter (QofBook *book, const char *counter_name) { QofBackend *be; KvpFrame *kvp; KvpValue *value; gint64 counter; if (!book) { PWARN ("No book!!!"); return -1; } if (!counter_name || *counter_name == '\0') { PWARN ("Invalid counter name."); return -1; } /* If we've got a backend with a counter method, call it */ be = book->backend; if (be && be->counter) return ((be->counter)(be, counter_name)); /* If not, then use the KVP in the book */ kvp = qof_book_get_slots (book); if (!kvp) { PWARN ("Book has no KVP_Frame"); return -1; } value = kvp_frame_get_slot_path (kvp, "counters", counter_name, NULL); if (value) { /* found it */ counter = kvp_value_get_gint64 (value); } else { /* New counter */ counter = 0; } /* Counter is now valid; increment it */ counter++; /* Save off the new counter */ qof_book_begin_edit(book); value = kvp_value_new_gint64 (counter); kvp_frame_set_slot_path (kvp, value, "counters", counter_name, NULL); kvp_value_delete (value); qof_book_mark_dirty(book); qof_book_commit_edit(book); /* and return the value */ return counter; }
gchar * qof_book_increment_and_format_counter (QofBook *book, const char *counter_name) { KvpFrame *kvp; KvpValue *value; gint64 counter; gchar* format; gchar* result; if (!book) { PWARN ("No book!!!"); return NULL; } if (!counter_name || *counter_name == '\0') { PWARN ("Invalid counter name."); return NULL; } /* Get the current counter value from the KVP in the book. */ counter = qof_book_get_counter(book, counter_name); /* Check if an error occurred */ if (counter < 0) return NULL; /* Increment the counter */ counter++; /* Get the KVP from the current book */ kvp = qof_instance_get_slots (QOF_INSTANCE (book)); if (!kvp) { PWARN ("Book has no KVP_Frame"); return NULL; } /* Save off the new counter */ qof_book_begin_edit(book); value = new KvpValue(counter); delete kvp->set_path({"counters", counter_name}, value); qof_instance_set_dirty (QOF_INSTANCE (book)); qof_book_commit_edit(book); format = qof_book_get_counter_format(book, counter_name); if (!format) { PWARN("Cannot get format for counter"); return NULL; } /* Generate a string version of the counter */ result = g_strdup_printf(format, counter); g_free (format); return result; }
/** Returns pointer to book-currency name for book, if one exists in the * KVP, or NULL; does not validate contents nor determine if there is a valid * default gain/loss policy, both of which are required, for the * 'book-currency' currency accounting method to apply. Use instead * 'gnc_book_get_book_currency' which does these validations. */ const gchar * qof_book_get_book_currency (QofBook *book) { KvpFrame *kvp; KvpValue *value; if (!book) { PWARN ("No book!!!"); return NULL; } /* Get the KVP from the current book */ kvp = qof_instance_get_slots (QOF_INSTANCE (book)); if (!kvp) { PWARN ("Book has no KVP_Frame"); return NULL; } /* See if there is a book currency. */ value = kvp->get_slot({KVP_OPTION_PATH, OPTION_SECTION_ACCOUNTS, OPTION_NAME_BOOK_CURRENCY}); if (!value) /* No book-currency */ return nullptr; return value->get<const char*>(); }
void xaccQueryAddAccountMatch(QofQuery *q, AccountList *acct_list, QofGuidMatch how, QofQueryOp op) { GList *list = NULL; if (!q) return; for (; acct_list; acct_list = acct_list->next) { Account *acc = acct_list->data; const GncGUID *guid; if (!acc) { PWARN ("acct_list has NULL account"); continue; } guid = qof_entity_get_guid (QOF_INSTANCE(acc)); if (!guid) { PWARN ("acct returns NULL GncGUID"); continue; } list = g_list_prepend (list, (gpointer)guid); } xaccQueryAddAccountGUIDMatch (q, list, how, op); g_list_free (list); }
/* I2C probe: check if the device exists and register with v4l if it is */ static int __devinit tea5764_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct tea5764_device *radio; struct tea5764_regs *r; int ret; PDEBUG("probe"); radio = kmalloc(sizeof(struct tea5764_device), GFP_KERNEL); if (!radio) return -ENOMEM; mutex_init(&radio->mutex); radio->i2c_client = client; ret = tea5764_i2c_read(radio); if (ret) goto errfr; r = &radio->regs; PDEBUG("chipid = %04X, manid = %04X", r->chipid, r->manid); if (r->chipid != TEA5764_CHIPID || (r->manid & 0x0fff) != TEA5764_MANID) { PWARN("This chip is not a TEA5764!"); ret = -EINVAL; goto errfr; } radio->videodev = video_device_alloc(); if (!(radio->videodev)) { ret = -ENOMEM; goto errfr; } memcpy(radio->videodev, &tea5764_radio_template, sizeof(tea5764_radio_template)); i2c_set_clientdata(client, radio); video_set_drvdata(radio->videodev, radio); ret = video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr); if (ret < 0) { PWARN("Could not register video device!"); goto errrel; } /* initialize and power off the chip */ tea5764_i2c_read(radio); tea5764_set_audout_mode(radio, V4L2_TUNER_MODE_STEREO); tea5764_mute(radio, 1); tea5764_power_down(radio); PINFO("registered."); return 0; errrel: video_device_release(radio->videodev); errfr: kfree(radio); return ret; }
void gnc_keyring_set_password (const gchar *access_method, const gchar *server, guint32 port, const gchar *service, const gchar *user, const gchar* password) { #ifdef HAVE_GNOME_KEYRING GnomeKeyringResult gkr_result; guint32 item_id = 0; gkr_result = gnome_keyring_set_network_password_sync (NULL, user, NULL, server, service, access_method, NULL, port, password, &item_id); if (gkr_result != GNOME_KEYRING_RESULT_OK) { PWARN ("Gnome-keyring error: %s", gnome_keyring_result_to_message(gkr_result)); PWARN ("The user will be prompted for a password again next time."); } #endif /* HAVE_GNOME_KEYRING */ #ifdef HAVE_OSX_KEYCHAIN OSStatus status; SecKeychainItemRef *itemRef = NULL; /* mysql and postgres aren't valid protocols on Mac OS X. * So we use the security domain parameter to allow us to * distinguish between these two. */ // FIXME I'm not sure this works if a password was already in the keychain // I may have to do a lookup first and if it exists, run some update // update function instead status = SecKeychainAddInternetPassword ( NULL, /* keychain */ strlen(server), server, /* servername */ strlen(access_method), access_method, /* securitydomain */ strlen(user), user, /* acountname */ strlen(service), service, /* path */ port, /* port */ kSecProtocolTypeAny, /* protocol */ kSecAuthenticationTypeDefault, /* auth type */ strlen(password), password, /* passworddata */ itemRef ); if ( status != noErr ) { CFStringRef osx_resultstring = SecCopyErrorMessageString( status, NULL ); const gchar *resultstring = CFStringGetCStringPtr(osx_resultstring, GetApplicationTextEncoding()); PWARN ( "OS X keychain error: %s", resultstring ); PWARN ( "The user will be prompted for a password again next time." ); CFRelease ( osx_resultstring ); } #endif /* HAVE_OSX_KEYCHAIN */ }
const gchar * qof_book_get_counter_format(const QofBook *book, const char *counter_name) { KvpFrame *kvp; const char *format; KvpValue *value; gchar *error; if (!book) { PWARN ("No book!!!"); return NULL; } if (!counter_name || *counter_name == '\0') { PWARN ("Invalid counter name."); return NULL; } /* Get the KVP from the current book */ kvp = qof_instance_get_slots (QOF_INSTANCE (book)); if (!kvp) { PWARN ("Book has no KVP_Frame"); return NULL; } format = NULL; /* Get the format string */ value = kvp->get_slot({"counter_formats", counter_name}); if (value) { format = value->get<const char*>(); error = qof_book_validate_counter_format(format); if (error != NULL) { PWARN("Invalid counter format string. Format string: '%s' Counter: '%s' Error: '%s')", format, counter_name, error); /* Invalid format string */ format = NULL; g_free(error); } } /* If no (valid) format string was found, use the default format * string */ if (!format) { /* Use the default format */ format = "%.6" G_GINT64_FORMAT; } return format; }
char * qof_book_get_counter_format(const QofBook *book, const char *counter_name) { KvpFrame *kvp; const char *user_format = NULL; gchar *norm_format = NULL; KvpValue *value; gchar *error = NULL; if (!book) { PWARN ("No book!!!"); return NULL; } if (!counter_name || *counter_name == '\0') { PWARN ("Invalid counter name."); return NULL; } /* Get the KVP from the current book */ kvp = qof_instance_get_slots (QOF_INSTANCE (book)); if (!kvp) { PWARN ("Book has no KVP_Frame"); return NULL; } /* Get the format string */ value = kvp->get_slot({"counter_formats", counter_name}); if (value) { user_format = value->get<const char*>(); norm_format = qof_book_normalize_counter_format(user_format, &error); if (!norm_format) { PWARN("Invalid counter format string. Format string: '%s' Counter: '%s' Error: '%s')", user_format, counter_name, error); /* Invalid format string */ user_format = NULL; g_free(error); } } /* If no (valid) format string was found, use the default format * string */ if (!norm_format) { /* Use the default format */ norm_format = g_strdup ("%.6" PRIi64); } return norm_format; }
ssize_t proc_handle_softreboot(struct file *file, const char __user *buffer, unsigned long count, void *data) { int len = count, i, start, k, cdev; u16 devs[4] = { 0 }; char buf[OMAP3_MAX_SEQ]; if (len > OMAP3_MAX_SEQ-1) { PWARN("Too long OMAP boot sequence\n"); return -EFAULT; } if (copy_from_user(buf, buffer, len)) return -EFAULT; buf[len++] = 0; for (i = 0, start = 0, cdev = 0; i < len; i++) { if (buf[i] == ',' || !buf[i] || buf[i] == '\n') { for (k = 0; k < OMAP3_DEV_COUNT; k++) { if (omap3_dev_names[k] && !strncmp(buf+start, omap3_dev_names[k], i-start)) { if (cdev >= 4) { PWARN("You can specify only up to 4 OMAP boot devices\n"); return -EFAULT; } devs[cdev++] = k; break; } } if (k >= OMAP3_DEV_COUNT) { buf[i] = 0; PWARN("Incorrect OMAP boot device name \"%s\"\n", buf+start); return -EFAULT; } start = i+1; if (!buf[i] || buf[i] == '\n') break; } } // Reboot device with new configuration PWARN("New config: %x %x %x %x\n", devs[0], devs[1], devs[2], devs[3]); omap_reset_to(devs); return count; }
int test_3_bitvec(void) { Bitvec a; size_t n = 128; bitvec_initZ(&a, n); for (size_t i = 0; i < n; i++) { if (bitvec_get(&a, i) != 0) { PWARN("Failed for a[i:%zd] != 0\n", i); } bitvec_set1(&a, i); if (bitvec_get(&a, i) != 1) { PWARN("Failed for a[i:%zd] != 1\n", i); } } bitvec_print(&a); printf("\n"); return 0; }
static void gncOwnerOffsetLots (GNCLot *from_lot, GNCLot *to_lot, const GncOwner *owner) { gnc_numeric target_offset; Split *split; /* from lot should not be a document lot because we're removing a split from there ! */ if (gncInvoiceGetInvoiceFromLot (from_lot)) { PWARN ("from_lot %p is a document lot. That is not allowed in gncOwnerOffsetLots", from_lot); return; } /* Get best matching split from from_lot to offset to_lot */ target_offset = gnc_lot_get_balance (to_lot); if (gnc_numeric_zero_p (target_offset)) return; // to_lot is already balanced, nothing more to do split = gncOwnerFindOffsettingSplit (from_lot, target_offset); if (!split) return; // No suitable offsetting split found, nothing more to do /* If the offsetting split is bigger than the amount needed to balance * to_lot, reduce the split so its reduced value closes to_lot exactly. * Note the negation in the reduction function. The split must be of * opposite sign of to_lot's balance in order to be able to close it. */ if (gnc_numeric_compare (gnc_numeric_abs (xaccSplitGetValue (split)), gnc_numeric_abs (target_offset)) > 0) gncOwnerReduceSplitTo (split, gnc_numeric_neg (target_offset)); /* Move the reduced split from from_lot to to_lot */ gnc_lot_add_split (to_lot, split); }
static gboolean gncScrubLotIsSingleLotLinkSplit (GNCLot *lot) { Split *split = NULL; Transaction *trans = NULL; // Lots with a single split which is also a lot link transaction split // may be sign of a dangling payment. Let's try to fix that // Only works for single split lots... if (1 != gnc_lot_count_splits (lot)) return FALSE; split = gnc_lot_get_earliest_split (lot); trans = xaccSplitGetParent (split); if (!trans) { // Ooops - the split doesn't belong to any transaction ! // This is not expected so issue a warning and continue with next split PWARN("Encountered a split in a business lot that's not part of any transaction. " "This is unexpected! Skipping split %p.", split); return FALSE; } // Only works if single split belongs to a lot link transaction... if (xaccTransGetTxnType (trans) != TXN_TYPE_LINK) return FALSE; return TRUE; }
Transaction* GncPreTrans::create_trans (QofBook* book, gnc_commodity* currency) { if (created) return nullptr; /* Gently refuse to create the transaction if the basics are not set correctly * This should have been tested before calling this function though! */ auto check = verify_essentials(); if (!check.empty()) { PWARN ("Refusing to create transaction because essentials not set properly: %s", check.c_str()); return nullptr; } auto trans = xaccMallocTransaction (book); xaccTransBeginEdit (trans); xaccTransSetCurrency (trans, m_commodity ? *m_commodity : currency); xaccTransSetDatePostedSecsNormalized (trans, static_cast<time64>(GncDateTime(*m_date, DayPart::neutral))); if (m_num) xaccTransSetNum (trans, m_num->c_str()); if (m_desc) xaccTransSetDescription (trans, m_desc->c_str()); if (m_notes) xaccTransSetNotes (trans, m_notes->c_str()); created = true; return trans; }
static void load_slot( slot_info_t *pInfo, GncSqlRow* row ) { slot_info_t *slot_info; g_return_if_fail( pInfo != NULL ); g_return_if_fail( pInfo->be != NULL ); g_return_if_fail( row != NULL ); g_return_if_fail( pInfo->pKvpFrame != NULL ); slot_info = slot_info_copy( pInfo, NULL ); g_string_free( slot_info->path, TRUE ); slot_info->path = NULL; gnc_sql_load_object( pInfo->be, row, TABLE_NAME, slot_info, col_table ); if ( slot_info->path != NULL ) { (void)g_string_free( slot_info->path, TRUE ); } if ( slot_info->pList != pInfo->pList ) { if (pInfo->pList != NULL) { PWARN("Load slot returned a different list than the original"); } else { pInfo->pList = slot_info->pList; } } g_slice_free( slot_info_t, slot_info ); }
/** * * @param sensor_id * @return */ int BstSensor::send_flush_event(int32_t sensor_id) { sensors_meta_data_event_t *p_event; int32_t ret; p_event = (sensors_meta_data_event_t *) calloc(1, sizeof(sensors_meta_data_event_t)); if (NULL == p_event) { PWARN("calloc fail"); return -1; } p_event->version = META_DATA_VERSION; p_event->type = SENSOR_TYPE_META_DATA; p_event->meta_data.what = META_DATA_FLUSH_COMPLETE; p_event->meta_data.sensor = sensor_id; ret = write(HALpipe_fd[1], p_event, sizeof(sensors_meta_data_event_t)); if(ret < 0){ PERR("send flush echo fail, errno = %d(%s)", errno, strerror(errno)); } free(p_event); return 0; }
static gboolean owner_type_handler (xmlNodePtr node, gpointer owner_pdata) { struct owner_pdata* pdata = static_cast<decltype (pdata)> (owner_pdata); char* txt = dom_tree_to_text (node); g_return_val_if_fail (txt, FALSE); if (!g_strcmp0 (txt, GNC_ID_CUSTOMER)) gncOwnerInitCustomer (pdata->owner, NULL); else if (!g_strcmp0 (txt, GNC_ID_JOB)) gncOwnerInitJob (pdata->owner, NULL); else if (!g_strcmp0 (txt, GNC_ID_VENDOR)) gncOwnerInitVendor (pdata->owner, NULL); else if (!g_strcmp0 (txt, GNC_ID_EMPLOYEE)) gncOwnerInitEmployee (pdata->owner, NULL); else { PWARN ("Unknown owner type: %s", txt); g_free (txt); return FALSE; } g_free (txt); return TRUE; }
static double qof_gobject_double_getter (gpointer data, QofParam *getter) { GObject *gob = data; double fval; GParamSpec *gps = getter->param_userdata; /* Note that the return type must actually be of type * getter->param_type but we just follow the hard-coded * mapping below ... */ if (G_IS_PARAM_SPEC_FLOAT(gps)) { GValue gval = {G_TYPE_INVALID}; g_value_init (&gval, G_TYPE_FLOAT); g_object_get_property (gob, getter->param_name, &gval); fval = g_value_get_float (&gval); return fval; } else if (G_IS_PARAM_SPEC_DOUBLE(gps)) { GValue gval = {G_TYPE_INVALID}; g_value_init (&gval, G_TYPE_DOUBLE); g_object_get_property (gob, getter->param_name, &gval); fval = g_value_get_double (&gval); return fval; } PWARN ("unhandled parameter type %s for paramter %s", G_PARAM_SPEC_TYPE_NAME(gps), getter->param_name); return 0.0; }
/* gnc_builder_add_from_file: * * a convenience wrapper for gtk_builder_add_objects_from_file. * It takes care of finding the directory for glade files and prints a * warning message in case of an error. */ gboolean gnc_builder_add_from_file (GtkBuilder *builder, const char *filename, const char *root) { GError* error = NULL; char *fname; gchar *gnc_builder_dir; gboolean result; g_return_val_if_fail (builder != NULL, FALSE); g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (root != NULL, FALSE); gnc_builder_dir = gnc_path_get_gtkbuilderdir (); fname = g_build_filename(gnc_builder_dir, filename, (char *)NULL); g_free (gnc_builder_dir); { gchar *localroot = g_strdup(root); gchar *objects[] = { localroot, NULL }; result = gtk_builder_add_objects_from_file (builder, fname, objects, &error); if (!result) { PWARN ("Couldn't load builder file: %s", error->message); g_error_free (error); } g_free (localroot); } g_free (fname); return result; }
void gnc_state_save (const QofSession *session) { GError *error = NULL; if (!qof_session_get_url(session)) { DEBUG("No file associated with session - skip state saving"); return; } gnc_state_set_base (session); /* Write it all out to disk */ if (state_file_name) gnc_key_file_save_to_file(state_file_name, state_file, &error); else PWARN ("No state file name set, can't save state"); if (error) { PERR ("Error: Failure saving state file.\n %s", error->message); g_error_free (error); } }
xmlNodePtr gnc_owner_to_dom_tree (const char* tag, const GncOwner* owner) { xmlNodePtr ret; const char* type_str; switch (gncOwnerGetType (owner)) { case GNC_OWNER_CUSTOMER: type_str = GNC_ID_CUSTOMER; break; case GNC_OWNER_JOB: type_str = GNC_ID_JOB; break; case GNC_OWNER_VENDOR: type_str = GNC_ID_VENDOR; break; case GNC_OWNER_EMPLOYEE: type_str = GNC_ID_EMPLOYEE; break; default: PWARN ("Invalid owner type: %d", gncOwnerGetType (owner)); return NULL; } ret = xmlNewNode (NULL, BAD_CAST tag); xmlSetProp (ret, BAD_CAST "version", BAD_CAST owner_version_string); xmlAddChild (ret, text_to_dom_tree (owner_type_string, type_str)); xmlAddChild (ret, guid_to_dom_tree (owner_id_string, gncOwnerGetGUID (owner))); return ret; }
template<> StrVec GncDbiProviderImpl<DbType::DBI_MYSQL>::get_index_list (dbi_conn conn) { StrVec retval; const char* errmsg; auto tables = get_table_list(conn, ""); for (auto table_name : tables) { auto result = dbi_conn_queryf (conn, "SHOW INDEXES IN %s WHERE Key_name != 'PRIMARY'", table_name.c_str()); if (dbi_conn_error (conn, &errmsg) != DBI_ERROR_NONE) { PWARN ("Index Table Retrieval Error: %s on table %s\n", errmsg, table_name.c_str()); continue; } while (dbi_result_next_row (result) != 0) { std::string index_name {dbi_result_get_string_idx (result, 3)}; retval.push_back(index_name + " " + table_name); } dbi_result_free (result); } return retval; }
static int hw_acc_set_grange(struct sensor_hw_a *hw, uint32_t range) { int err = 0; char path[128] = ""; int tmp; int i; PDEBUG("grange: %d", range); sprintf(path, "%s/input%d/%s", SYSFS_PATH_INPUT_DEV, g_input_dev_num_a, SYSFS_NODE_NAME_BMA_GRANGE); for (i = 0; i < ARRAY_SIZE(map_a_range); i++) { if (map_a_range[i].l == (int)range) { break; } } if (i < ARRAY_SIZE(map_a_range)) { tmp = map_a_range[i].r; err = sysfs_write_int(path, tmp); if (!err) { hw->range = range; } } else { PWARN("invalid grange"); err = -EINVAL; } return err; }
static GSettings * gnc_gsettings_get_settings_ptr (const gchar *schema_str) { GSettings *gset = NULL; gchar *full_name = gnc_gsettings_normalize_schema_name (schema_str); ENTER(""); if (!schema_hash) schema_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); gset = g_hash_table_lookup (schema_hash, full_name); DEBUG ("Looking for schema %s returned gsettings %p", full_name, gset); if (!gset) { gset = g_settings_new (full_name); DEBUG ("Created gsettings object %p for schema %s", gset, full_name); if (G_IS_SETTINGS(gset)) g_hash_table_insert (schema_hash, full_name, gset); else PWARN ("Ignoring attempt to access unknown gsettings schema %s", full_name); } else { g_free(full_name); } LEAVE(""); return gset; }
static void load_slot (slot_info_t* pInfo, GncSqlRow& row) { slot_info_t* slot_info; g_return_if_fail (pInfo != NULL); g_return_if_fail (pInfo->be != NULL); g_return_if_fail (pInfo->pKvpFrame != NULL); slot_info = slot_info_copy (pInfo, NULL); gnc_sql_load_object (pInfo->be, row, TABLE_NAME, slot_info, col_table); if (slot_info->pList != pInfo->pList) { if (pInfo->pList != NULL) { PWARN ("Load slot returned a different list than the original"); } else { pInfo->pList = slot_info->pList; } } delete slot_info; }
/* for each invoice, check the bill terms. If the bill terms are * grandchildren, then fix them to point to the most senior child */ static void billterm_scrub_invoices (QofInstance * invoice_p, gpointer ht_p) { GHashTable *ht = ht_p; GncInvoice *invoice = GNC_INVOICE(invoice_p); GncBillTerm *term, *new_bt; gint32 count; term = gncInvoiceGetTerms(invoice); if (term) { if (billterm_is_grandchild(term)) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(invoice)),guidstr); PWARN("Fixing i-billterm on invoice %s\n", guidstr); new_bt = billterm_find_senior(term); gncInvoiceBeginEdit(invoice); gncInvoiceSetTerms(invoice, new_bt); gncInvoiceCommitEdit(invoice); term = new_bt; } if (term) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); count++; g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); } } }
gboolean qof_instance_kvp_has_guid (const QofInstance *inst, const char *path, const char* key, const GncGUID *guid) { g_return_val_if_fail (inst->kvp_data != NULL, FALSE); g_return_val_if_fail (guid != NULL, FALSE); auto v = inst->kvp_data->get_slot(path); if (v == nullptr) return FALSE; switch (v->get_type()) { case KvpValue::Type::FRAME: return kvp_match_guid (v, key, guid); break; case KvpValue::Type::GLIST: { auto list = v->get<GList*>(); for (auto node = list; node != NULL; node = node->next) { auto val = static_cast<KvpValue*>(node->data); if (kvp_match_guid (val, key, guid)) { return TRUE; } } break; } default: PWARN ("Instance KVP on path %s contains the wrong type.", path); break; } return FALSE; }