static int waitjob_cb (const char *jcbstr, void *arg, int errnum) { JSON jcb = NULL; int64_t os = 0, ns = 0, j = 0; flux_t h = (flux_t)arg; wjctx_t *ctx = getctx (h); if (errnum > 0) { flux_log (ctx->h, LOG_ERR, "waitjob_cb: errnum passed in"); return -1; } if (!(jcb = Jfromstr (jcbstr))) { flux_log (ctx->h, LOG_ERR, "waitjob_cb: error parsing JSON string"); return -1; } get_jobid (jcb, &j); get_states (jcb, &os, &ns); Jput (jcb); if ((j == ctx->jobid) && (ns == J_COMPLETE)) { if (ctx->complete) touch_outfile (ctx->complete); flux_log (ctx->h, LOG_INFO, "waitjob_cb: completion notified"); raise (SIGINT); } return 0; }
static int job_status_cb (const char *jcbstr, void *arg, int errnum) { int64_t os = 0; int64_t ns = 0; int64_t j = 0; jstatctx_t *ctx = NULL; flux_t h = (flux_t)arg; JSON jcb = NULL; ctx = getctx (h); if (errnum > 0) { flux_log (ctx->h, LOG_ERR, "job_status_cb: errnum passed in"); return -1; } if (!(jcb = Jfromstr (jcbstr))) { flux_log (ctx->h, LOG_ERR, "job_status_cb: error parsing JSON string"); return -1; } get_jobid (jcb, &j); get_states (jcb, &os, &ns); Jput (jcb); fprintf (ctx->op, "%s->%s\n", jsc_job_num2state ((job_state_t)os), jsc_job_num2state ((job_state_t)ns)); fflush (ctx->op); return 0; }
static void add_rules(StateMachinePtr sm, BindingsPtr bindings, NodePtr root) { if (root->get_op() == Op::sm_rules) { add_rules(sm, bindings, root->get_operand(0)); root = root->get_operand(1); } assert(root->get_op() == Op::sm_rule); if (root->size() == 1) { // handler root = root->get_operand(0); assert(root->get_op() == Op::ON); assert(root->get_operand(0)->get_op() == Op::CLOSE); root = root->get_operand(1); assert(root->get_op() == Op::sm_handler); if (root->size() == 1) { StateSet states; sm->add_close_handler(states, root->get_operand(0)); } else { StateSet states(sm->get_nofstates()); get_states(sm, root->get_operand(0), states); sm->add_close_handler(states, root->get_operand(1)); } } else { // regular rule NodePtr smcond = root->get_operand(0); StateMachineRulePtr rule; NodePtr node_expr; if (smcond->size() == 2) { NodePtr tree_expr = smcond->get_operand(0); NodeTypeSet nodetypes(nof_node_types(bindings)); get_node_expression(bindings, smcond->get_operand(1), nodetypes, node_expr); rule = std::make_shared<StateMachineRule>(sm, tree_expr, nodetypes, bindings->get_rules()); } else { if (smcond->get_operand(0)->get_op() == Op::cfg_node_expression) { NodeTypeSet nodetypes(nof_node_types(bindings)); get_node_expression(bindings, smcond->get_operand(0), nodetypes, node_expr); rule = std::make_shared<StateMachineRule>(sm, nodetypes, bindings->get_rules()); } else { NodePtr tree_expr = smcond->get_operand(0); rule = std::make_shared<StateMachineRule>(sm, tree_expr, bindings->get_rules()); } } if (node_expr) { rule->add_node_condition(node_expr); } if (root->get_operand(1)->get_op() == Op::sm_block) { NodePtr smblock = root->get_operand(1); rule->add_alternative(create_alternative(sm, smblock)); } else { add_alternatives(sm, rule, bindings, root->get_operand(1)); } sm->add_rule(rule); } }
int getQTIs(int highPin, int lowPin) // Function - getQTIs { int dt = (CLKFREQ / 1000000) * 230; // Set up 230 us time increment set_outputs(highPin, lowPin, 0b1111); // highPin...lowPin set high set_directions(highPin, lowPin, 0b1111); // highPin...lowPin set to output waitcnt(dt + CNT); // Wait 230 us set_directions(highPin, lowPin, 0b0000); // highPin...lowPin st to input waitcnt(dt + CNT); // Wait 230 us int qtis = get_states(highPin, lowPin); // Get 4-bit pattern QTIs apply return qtis; // Return val containing pattern }
static int dump_states_binary(int fd, int verbose, const char* filename) { int wfd; struct pfioc_states ps; struct pfsync_state *p = NULL; int nb_states; int i; int error = 0; int errno_saved = 0; wfd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0600); if (wfd == -1) err(EXIT_FAILURE, "Cannot open %s", filename); nb_states = get_states(fd, verbose, &ps); if (nb_states <= 0) { close(wfd); return nb_states; } /* * In the file, write the number of states, then store the different states * When we will switch to text format, we probably don't care any more about the len */ if (write(wfd, &nb_states, sizeof(nb_states)) != sizeof(nb_states)) { error = EXIT_FAILURE; errno_saved = errno; goto done; } p = ps.ps_states; for (i = 0; i < nb_states; i++) { if (write(wfd, &p[i], sizeof(*p)) != sizeof(*p)) { error = EXIT_FAILURE; errno_saved = errno; goto done; } } done: free(p); close(wfd); // close can't modify errno if (error) { errno = errno_saved; err(error, NULL); } return 0; }
static int print_states(int fd, int verbose, FILE* f) { struct pfioc_states ps; int nb_states; nb_states = get_states(fd, verbose, &ps); if (nb_states <= 0) { return nb_states; } display_states(&ps, verbose, f); free(ps.ps_states); return 0; }
int get_args(char* filename, args_t* args) { FILE* fp; int ret = 0; if ((fp = fopen(filename, "r")) != NULL) { ret = get_mode(fp, args) && get_states(fp, args) && get_symbols(fp, args) && get_transitions(fp, args); fclose(fp); } return ret; }
static void get_states(StateMachinePtr sm, NodePtr root, StateSet& states) { assert(root->get_op() == Op::sm_state_condition); if (root->size() == 2) { get_states(sm, root->get_operand(0), states); root = root->get_operand(1); } else { root = root->get_operand(0); } std::string statename = root->get_token().get_text(); int index = sm->get_state_by_name(statename); if (index < 0) { throw Exception(root->get_location(), "unknown state: " + statename); } states.set(index); }
static void add_alternatives(StateMachinePtr sm, StateMachineRulePtr rule, BindingsPtr bindings, NodePtr root) { if (root->get_op() == Op::sm_alternatives) { add_alternatives(sm, rule, bindings, root->get_operand(0)); root = root->get_operand(1); } assert(root->get_op() == Op::sm_alternative); NodePtr smblock = root->get_operand(root->size() - 1); StateMachineRuleAlternativePtr alternative = create_alternative(sm, smblock); std::size_t nextop = 0; if (root->get_operand(nextop)->get_op() == Op::cfg_edge_condition) { NodePtr edge_cond = root->get_operand(nextop++); LabelSet labels(nof_labels(bindings)); get_labelset(bindings, edge_cond, labels); alternative->set_labels(labels); } if (nextop + 1 < root->size()) { NodePtr state_cond = root->get_operand(nextop++); StateSet states(sm->get_nofstates()); get_states(sm, state_cond, states); alternative->set_states(states); } rule->add_alternative(alternative); }
void print_states() { read_states(); matrix_t *state_matrix = get_states(); print_matrix(state_matrix, info->state_bits); }