void msn_cmdproc_process_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) { MsnTransCb cb = NULL; MsnTransaction *trans = NULL; if (cmd->trId) trans = msn_history_find(cmdproc->history, cmd->trId); if (trans != NULL) if (trans->timer) purple_timeout_remove(trans->timer); if (g_ascii_isdigit(cmd->command[0])) { if (trans != NULL) { MsnErrorCb error_cb = NULL; int error; error = atoi(cmd->command); if (trans->error_cb != NULL) error_cb = trans->error_cb; if (error_cb == NULL && cmdproc->cbs_table->errors != NULL) error_cb = g_hash_table_lookup(cmdproc->cbs_table->errors, trans->command); if (error_cb != NULL) { error_cb(cmdproc, trans, error); } else { #if 1 msn_error_handle(cmdproc->session, error); #else purple_debug_warning("msn", "Unhandled error '%s'\n", cmd->command); #endif } return; } } if (cmdproc->cbs_table->async != NULL) cb = g_hash_table_lookup(cmdproc->cbs_table->async, cmd->command); if (cb == NULL && trans != NULL) { cmd->trans = trans; if (trans->callbacks != NULL) cb = g_hash_table_lookup(trans->callbacks, cmd->command); } if (cb == NULL && cmdproc->cbs_table->fallback != NULL) cb = g_hash_table_lookup(cmdproc->cbs_table->fallback, cmd->command); if (cb != NULL) { cb(cmdproc, cmd); } else { purple_debug_warning("msn", "Unhandled command '%s'\n", cmd->command); } if (trans != NULL && trans->pendent_cmd != NULL) msn_transaction_unqueue_cmd(trans, cmdproc); }
void machine_t::error(const char* s) const { if ( error_cb ) error_cb(s); }
static void pt_read_raw(FILE *in, void *context, void (*config_cb)(unsigned interval, double rec_int_secs, unsigned wheel_sz_mm, void *context), void (*time_cb)(struct tm *time, time_t since_epoch, void *context), void (*data_cb)(double secs, double nm, double mph, double watts, double miles, double alt, unsigned cad, unsigned hr, unsigned interval, void *context), void (*error_cb)(const char *msg, void *context)) { unsigned interval = 0; unsigned last_interval = 0; unsigned wheel_sz_mm = 0; double rec_int_secs = 0.0; int i, n, row = 0; unsigned char buf[6]; unsigned sbuf[6]; double meters = 0.0; double secs = 0.0, start_secs = 0.0; double miles; double mph; double nm; double watts; double alt = 0; unsigned cad; unsigned hr; struct tm time; time_t since_epoch; char ebuf[256]; bool bIsVer81 = false; while ((n = fscanf(in, "%x %x %x %x %x %x\n", sbuf, sbuf+1, sbuf+2, sbuf+3, sbuf+4, sbuf+5)) == 6) { ++row; for (i = 0; i < 6; ++i) { if (sbuf[i] > 0xff) { n = 1; break; } buf[i] = sbuf[i]; } if (row == 1) { /* Serial number? */ bIsVer81 = PowerTapUtil::is_Ver81(buf); } else if (PowerTapUtil::is_ignore_record(buf, bIsVer81)) { // do nothing } else if (PowerTapUtil::is_config(buf, bIsVer81)) { double new_rec_int_secs = 0.0; if (PowerTapUtil::unpack_config(buf, &interval, &last_interval, &new_rec_int_secs, &wheel_sz_mm, bIsVer81) < 0) { sprintf(ebuf, "Couldn't unpack config record."); if (error_cb) error_cb(ebuf, context); return; } if ((rec_int_secs != 0.0) && (rec_int_secs != new_rec_int_secs)) { sprintf(ebuf, "Ride has multiple recording intervals, which " "is not yet supported.<br>(Recording interval changes " "from %0.2f to %0.2f after %0.2f minutes of ride data.)\n", rec_int_secs, new_rec_int_secs, secs / 60.0); if (error_cb) error_cb(ebuf, context); return; } rec_int_secs = new_rec_int_secs; if (config_cb) config_cb(interval, rec_int_secs, wheel_sz_mm, context); } else if (PowerTapUtil::is_time(buf, bIsVer81)) { since_epoch = PowerTapUtil::unpack_time(buf, &time, bIsVer81); bool ignore = false; if (start_secs == 0.0) start_secs = since_epoch; else if (since_epoch - start_secs > secs) secs = since_epoch - start_secs; else { sprintf(ebuf, "Warning: %0.3f minutes into the ride, " "time jumps backwards by %0.3f minutes; ignoring it.", secs / 60.0, (secs - since_epoch + start_secs) / 60.0); if (error_cb) error_cb(ebuf, context); ignore = true; } if (time_cb && !ignore) time_cb(&time, since_epoch, context); } else if (PowerTapUtil::is_data(buf, bIsVer81)) { if (wheel_sz_mm == 0) { sprintf(ebuf, "Read data row before wheel size set."); if (error_cb) error_cb(ebuf, context); return; } PowerTapUtil::unpack_data(buf, rec_int_secs, wheel_sz_mm, &secs, &nm, &mph, &watts, &meters, &cad, &hr, bIsVer81); miles = meters / 1000.0 * MILES_PER_KM; if (data_cb) data_cb(secs, nm, mph, watts, miles, alt, cad, hr, interval, context); } else { sprintf(ebuf, "Unknown record type 0x%x on row %d.", buf[0], row); if (error_cb) error_cb(ebuf, context); return; } } if (n != -1) { sprintf(ebuf, "Parse error on row %d.", row); if (error_cb) error_cb(ebuf, context); return; } }