static void TargPrintNode(GNode *gn, bool full) { if (OP_NOP(gn->type)) return; switch((gn->special & SPECIAL_MASK)) { case SPECIAL_SUFFIXES: case SPECIAL_PHONY: case SPECIAL_ORDER: case SPECIAL_NOTHING: case SPECIAL_MAIN: case SPECIAL_IGNORE: return; default: break; } if (full) { printf("# %d unmade prerequisites\n", gn->unmade); if (! (gn->type & (OP_JOIN|OP_USE|OP_EXEC))) { if (!is_out_of_date(gn->mtime)) { printf("# last modified %s: %s\n", time_to_string(&gn->mtime), status_to_string(gn)); } else if (gn->built_status != UNKNOWN) { printf("# non-existent (maybe): %s\n", status_to_string(gn)); } else { printf("# unmade\n"); } } } if (!Lst_IsEmpty(&gn->parents)) { printf("# parent targets: "); Lst_Every(&gn->parents, TargPrintName); fputc('\n', stdout); } if (gn->impliedsrc) printf("# implied prerequisite: %s\n", gn->impliedsrc->name); printf("%-16s", gn->name); switch (gn->type & OP_OPMASK) { case OP_DEPENDS: printf(": "); break; case OP_FORCE: printf("! "); break; case OP_DOUBLEDEP: printf(":: "); break; } Targ_PrintType(gn->type); Lst_Every(&gn->children, TargPrintName); fputc('\n', stdout); Lst_Every(&gn->commands, Targ_PrintCmd); printf("\n\n"); if (gn->type & OP_DOUBLEDEP) { LstNode ln; for (ln = Lst_First(&gn->cohorts); ln != NULL; ln = Lst_Adv(ln)) TargPrintNode((GNode *)Lst_Datum(ln), full); } }
/* Change the status and safety of a dragon. In addition, if the new * status is not DEAD, make all worms of the dragon essential, so that * results found by semeai code don't get ignored. */ static void update_status(int dr, enum dragon_status new_status, enum dragon_status new_safety) { int pos; if (dragon[dr].status != new_status && (dragon[dr].status != CRITICAL || new_status != DEAD)) { DEBUG(DEBUG_SEMEAI, "Changing status of %1m from %s to %s.\n", dr, status_to_string(dragon[dr].status), status_to_string(new_status)); for (pos = BOARDMIN; pos < BOARDMAX; pos++) if (IS_STONE(board[pos]) && is_same_dragon(dr, pos)) { dragon[pos].status = new_status; if (new_status != DEAD) worm[pos].inessential = 0; } } if (DRAGON2(dr).safety != new_safety && (DRAGON2(dr).safety != CRITICAL || new_safety != DEAD)) { DEBUG(DEBUG_SEMEAI, "Changing safety of %1m from %s to %s.\n", dr, status_to_string(DRAGON2(dr).safety), status_to_string(new_safety)); DRAGON2(dr).safety = new_safety; } }
/** * Allows to attempt the sub-m-gram payload retrieval for m==n * @see GenericTrieBase */ inline void get_n_gram_payload(m_gram_query & query, MGramStatusEnum & status) const { //First ensure the context of the given sub-m-gram LAYERED_BASE_ENSURE_CONTEXT(query, status); //If the context is successfully ensured, then move on to the m-gram and try to obtain its payload if (status == MGramStatusEnum::GOOD_PRESENT_MGS) { //Store the shorthand for the context and end word id TLongId & ctx_id = query.get_curr_ctx_ref(); const TShortId & word_id = query.get_curr_end_word_id(); LOG_DEBUG << "ctx_id: " << ctx_id << ", m_end_word_idx: " << SSTR(query.m_curr_end_word_idx) << ", end word id: " << word_id << END_LOG; //Get the next context id const phrase_length & level_idx = query.get_curr_level_m2(); if (get_ctx_id(level_idx, word_id, ctx_id)) { LOG_DEBUG << "ctx_id: " << ctx_id << END_LOG; TNGramsMap::const_iterator result = m_n_gram_map_ptr->find(ctx_id); if (result == m_n_gram_map_ptr->end()) { //The payload could not be found LOG_DEBUG1 << "Unable to find " << SSTR(LM_M_GRAM_LEVEL_MAX) << "-gram data for ctx_id: " << SSTR(ctx_id) << ", word_id: " << SSTR(word_id) << END_LOG; status = MGramStatusEnum::BAD_NO_PAYLOAD_MGS; } else { //There is data found under this context query.set_curr_payload(&result->second); LOG_DEBUG << "The payload is retrieved: " << result->second << END_LOG; } } else { //The payload could not be found LOG_DEBUG << "The payload id could not be found!" << END_LOG; status = MGramStatusEnum::BAD_NO_PAYLOAD_MGS; } LOG_DEBUG << "Context ensure status is: " << status_to_string(status) << END_LOG; } }
/** * Allows to retrieve the payload for the M-gram defined by the end word_id and ctx_id. * @see GenericTrieBase */ inline void get_m_gram_payload(typename BASE::T_Query_Exec_Data & query, MGramStatusEnum & status) const { LOG_DEBUG << "Getting the payload for sub-m-gram : [" << SSTR(query.m_begin_word_idx) << ", " << SSTR(query.m_end_word_idx) << "]" << END_LOG; //First ensure the context of the given sub-m-gram LAYERED_BASE_ENSURE_CONTEXT(query, status); //If the context is successfully ensured, then move on to the m-gram and try to obtain its payload if (status == MGramStatusEnum::GOOD_PRESENT_MGS) { //Store the shorthand for the context and end word id TLongId & ctx_id = query.m_last_ctx_ids[query.m_begin_word_idx]; const TShortId & word_id = query.m_gram[query.m_end_word_idx]; //Compute the distance between words const TModelLevel & curr_level = CURR_LEVEL_MAP[query.m_begin_word_idx][query.m_end_word_idx]; LOG_DEBUG << "curr_level: " << SSTR(curr_level) << ", ctx_id: " << ctx_id << ", m_end_word_idx: " << SSTR(query.m_end_word_idx) << ", end word id: " << word_id << END_LOG; //Get the next context id const TModelLevel & level_idx = CURR_LEVEL_MIN_2_MAP[query.m_begin_word_idx][query.m_end_word_idx]; if (get_ctx_id(level_idx, word_id, ctx_id)) { LOG_DEBUG << "level_idx: " << SSTR(level_idx) << ", ctx_id: " << ctx_id << END_LOG; //There is data found under this context query.m_payloads[query.m_begin_word_idx][query.m_end_word_idx] = &m_m_gram_data[level_idx][ctx_id]; LOG_DEBUG << "The payload is retrieved: " << (string) m_m_gram_data[level_idx][ctx_id] << END_LOG; } else { //The payload could not be found LOG_DEBUG1 << "Unable to find m-gram data for ctx_id: " << SSTR(ctx_id) << ", word_id: " << SSTR(word_id) << END_LOG; status = MGramStatusEnum::BAD_NO_PAYLOAD_MGS; } LOG_DEBUG << "Context ensure status is: " << status_to_string(status) << END_LOG; } }
static void verify(struct algorithm *params, const char *mode, const char *params_str, meego_parameter_status_t expected_status) { pa_log_debug("Expected: status=%s, mode=%s, params=%s", status_to_string(expected_status), pa_strnull(mode), pa_strnull(params_str)); pa_log_debug("Got: status=%s, mode=%s, params=%s", status_to_string(params->status), pa_strnull(params->mode), pa_strnull(params->parameters)); if (mode) { pa_assert(params->mode); pa_assert(pa_streq(params->mode, mode)); } if (params_str) { pa_assert(params->parameters); pa_assert(pa_streq(params->parameters, params_str)); } pa_assert(params->status == expected_status); }
char *response_obj_to_string(Response resobj) { char *res = ""; res = status_to_string(res, resobj.status); res = connection_to_string(res, resobj.connection); res = cache_control_to_string(res, resobj.cache_control); res = content_length_to_string(res, resobj.content_length); res = content_type_to_string(res, resobj.content_type); res = date_to_string(res, resobj.date); res = body_to_string(res, resobj.body); return res; }
enum STATUS_RESPONSE send_and_receive (int fd, uint8_t *send_buf, unsigned int send_buf_len, uint8_t *recv_buf, unsigned int recv_buf_len, struct timespec *wait_time) { struct timespec tim_rem; enum STATUS_RESPONSE rsp = RSP_AWAKE; const unsigned int NUM_RETRIES = 10; unsigned int x = 0; ssize_t result = 0; assert (NULL != send_buf); assert (NULL != recv_buf); assert (NULL != wait_time); /* Send the data at first. During a read, if the device responds with an "I'm Awake" flag, we've lost synchronization, so send the data again in that case only. Arbitrarily retry this procedure NUM_RETRIES times */ for (x=0; x < NUM_RETRIES && rsp == RSP_AWAKE; x++) { print_hex_string ("Sending", send_buf, send_buf_len); result = i2c_write (fd,send_buf,send_buf_len); if (result > 1) { do { nanosleep (wait_time , &tim_rem); } while ((rsp = read_and_validate (fd, recv_buf, recv_buf_len)) == RSP_NAK); CTX_LOG (DEBUG, "Command Response: %s", status_to_string (rsp)); } else { perror ("Send failed\n"); exit (1); } } return rsp; }
int Response_write(Response *response, char *data) { if (response->statusCode == 0) { response->statusCode = STATUS_OK; } // Status-line: "HTTP/1.1 302 Found" write(response->conn, response->version, strlen(response->version)); char code[3] = {0}; sprintf(code, " %d ", response->statusCode); write(response->conn, code, 5); char *codeStr = status_to_string(response->statusCode); write(response->conn, codeStr, strlen(codeStr)); write(response->conn, "\r\n", 2); Header *header = response->headers; for (int i = 0; i < response->headerNum; i++) { write(response->conn, header->name, strlen(header->name)); write(response->conn, ": ", 2); write(response->conn, header->value, strlen(header->value)); write(response->conn, "\r\n", 2); header++; } if (data == NULL) { return 0; } char length[256] = {0}; sprintf(length, "%lu", strlen(data)); write(response->conn, "Content-Length: ", 16); write(response->conn, length, strlen(length)); write(response->conn, "\r\n", 2); write(response->conn, "\r\n", 2); write(response->conn, data, strlen(data)); return 0; }
static pa_hook_result_t parameters_changed_cb(pa_core *c, meego_parameter_update_args *ua, struct algorithm *alg) { pa_assert(c); pa_assert(ua); pa_assert(alg); alg->status = ua->status; algorithm_reset(alg); if (ua->mode) alg->mode = pa_xstrdup(ua->mode); if (ua->parameters) { pa_assert(ua->length > 0); alg->parameters = pa_xstrndup(ua->parameters, ua->length); } pa_log_debug("parameters_changed_cb, status=%s, mode=%s, params=%s", status_to_string(alg->status), pa_strnull(alg->mode), pa_strnull(alg->parameters)); return PA_HOOK_OK; }
/*- *----------------------------------------------------------------------- * Make_Run -- * Initialize the nodes to remake and the list of nodes which are * ready to be made by doing a breadth-first traversal of the graph * starting from the nodes in the given list. Once this traversal * is finished, all the 'leaves' of the graph are in the toBeMade * queue. * Using this queue and the Job module, work back up the graph, * calling on MakeStartJobs to keep the job table as full as * possible. * * Results: * true if work was done. false otherwise. * * Side Effects: * The must_make field of all nodes involved in the creation of the given * targets is set to 1. The toBeMade list is set to contain all the * 'leaves' of these subgraphs. *----------------------------------------------------------------------- */ bool Make_Run(Lst targs) /* the initial list of targets */ { int errors; /* Number of errors the Job module reports */ GNode *gn; unsigned int i; bool cycle; /* wild guess at initial sizes */ Array_Init(&toBeMade, 500); Array_Init(&examine, 150); ohash_init(&targets, 10, &gnode_info); if (DEBUG(PARALLEL)) random_setup(); add_targets_to_make(targs); if (queryFlag) { /* * We wouldn't do any work unless we could start some jobs in * the next loop... (we won't actually start any, of course, * this is just to see if any of the targets was out of date) */ return MakeStartJobs(); } else { /* * Initialization. At the moment, no jobs are running and until * some get started, nothing will happen since the remaining * upward traversal of the graph is performed by the routines * in job.c upon the finishing of a job. So we fill the Job * table as much as we can before going into our loop. */ (void)MakeStartJobs(); } /* * Main Loop: The idea here is that the ending of jobs will take * care of the maintenance of data structures and the waiting for output * will cause us to be idle most of the time while our children run as * much as possible. Because the job table is kept as full as possible, * the only time when it will be empty is when all the jobs which need * running have been run, so that is the end condition of this loop. * Note that the Job module will exit if there were any errors unless * the keepgoing flag was given. */ while (!Job_Empty()) { handle_running_jobs(); (void)MakeStartJobs(); } errors = Job_Finish(); cycle = false; for (gn = ohash_first(&targets, &i); gn != NULL; gn = ohash_next(&targets, &i)) { if (has_been_built(gn)) continue; cycle = true; errors++; printf("Error: target %s unaccounted for (%s)\n", gn->name, status_to_string(gn)); } /* * Print the final status of each target. E.g. if it wasn't made * because some inferior reported an error. */ Lst_ForEach(targs, MakePrintStatus, &cycle); if (errors) Fatal("Errors while building"); return true; }
enum STATUS_RESPONSE read_and_validate (int fd, uint8_t *buf, unsigned int len) { uint8_t* tmp = NULL; const int PAYLOAD_LEN_SIZE = 1; const int CRC_SIZE = 2; enum STATUS_RESPONSE status = RSP_COMM_ERROR; unsigned int recv_buf_len = 0; bool crc_valid; unsigned int crc_offset; int read_bytes; const unsigned int STATUS_RSP = 4; assert (NULL != buf); recv_buf_len = len + PAYLOAD_LEN_SIZE + CRC_SIZE; crc_offset = recv_buf_len - 2; /* The buffer that comes back has a length byte at the front and a * two byte crc at the end. */ tmp = malloc_wipe (recv_buf_len); read_bytes = i2c_read (fd, tmp, recv_buf_len); /* First Case: We've read the buffer and it's a status packet */ if (read_bytes == recv_buf_len && tmp[0] == STATUS_RSP) { print_hex_string ("Status RSP", tmp, tmp[0]); status = get_status_response (tmp); CTX_LOG (DEBUG, status_to_string (status)); } /* Second case: We received the expected message length */ else if (read_bytes == recv_buf_len && tmp[0] == recv_buf_len) { print_hex_string ("Received RSP", tmp, recv_buf_len); crc_valid = is_crc_16_valid (tmp, tmp[0] - CRC_16_LEN, tmp + crc_offset); if (true == crc_valid) { wipe (buf, len); memcpy (buf, &tmp[1], len); status = RSP_SUCCESS; } else { perror ("CRC FAIL!\n"); } } else { CTX_LOG (DEBUG,"Read failed, retrying"); status = RSP_NAK; } free_wipe (tmp, recv_buf_len); return status; }