/////////////////////////////////////////////////////////////////////////////// ///@author Ghervase Gabriel ///@brief Checks if a full messasge can be read from the usb ///@param [in]p_nMiliSec - How much to wait for data before abandoning the operation ///@retval false if no data or error ///@retval true if we have data /////////////////////////////////////////////////////////////////////////////// bool CFragmentedUSBLink::HaveData(unsigned int p_nMiliSec/* = 10*/) { if (m_bHaveFullPacket) { return m_bHaveFullPacket; } USBFragment ofragment; while (getFragment(ofragment, p_nMiliSec)) { //check messageId - if unexpected, drop previously read data and restart with new messageID if (m_nExpectedMessageId != ofragment.msgId) { //dump previously received data (if any) dropExistingReadData(); m_nExpectedMessageId = ofragment.msgId; } // ignore - duplicate packet received if (ofragment.pktNo < m_u8ExpectedPktNo) { continue; } // packets should arrive in order ; dump previously received data if not if (ofragment.pktNo > m_u8ExpectedPktNo) { NLOG_WARN("[CFragmentedUSBLink][HaveData] Bad pktNo received : %d > expected %d - Discard existing fragments for msgId %d ", (int)(ofragment.pktNo), (int)(m_u8ExpectedPktNo), (int)(ofragment.msgId) ); dropExistingReadData(); continue; } if (m_nBytesReceivedSoFar + FRAGMENT_DATA_SIZE > MAX_USB_PACKET_SIZE) { NLOG_ERR("[CFragmentedUSBLink][HaveData] Internal Buffer too small; is %d and we need %d - Discard existing fragments for msgId %d", (int)MAX_USB_PACKET_SIZE, (int)(m_nBytesReceivedSoFar + FRAGMENT_DATA_SIZE), (int)(ofragment.msgId)); dropExistingReadData(); continue; } memcpy(m_pu8ReadBuf + m_nBytesReceivedSoFar, ofragment.data, FRAGMENT_DATA_SIZE); m_nBytesReceivedSoFar += FRAGMENT_DATA_SIZE; m_u8ExpectedPktNo++; if (ofragment.notLastFragment) { continue; } //we have received the last fragment m_bHaveFullPacket = true; break; } return m_bHaveFullPacket; }
KernelTablePtr KernelTable::get(const Converter& converter) { static string ENTRY_NAME = "KernelTable"; // look up the entry within the fragment manager auto manager = converter.getFragmentManager(); auto res = manager->getFragment(ENTRY_NAME); if(!res) { // create new instance KernelTablePtr table = manager->create<KernelTable>(boost::ref(converter)); manager->bindFragment(ENTRY_NAME, table); res = table; } return static_pointer_cast<KernelTable>(res); }
std::string net::URL::getDocument() const { std::ostringstream doc; std::string path = getPath(); if (!str::startsWith(path, "/")) doc << "/"; doc << path; std::string query = getQuery(); if (!query.empty()) doc << "?" << query; std::string fragment = getFragment(); if (!fragment.empty()) doc << "#" << fragment; return doc.str(); }
void parseURL(Request *req) { char *url; if (req->uri == NULL) { return; } if ((url = malloc((strlen(req->uri) + 1) * sizeof(char))) == NULL) { perror("malloc"); return; } strncpy(url, req->uri, strlen(req->uri) + 1); req->fragment = getFragment(url); req->queryString = getQueryString(url); req->path = getPath(url); req->filename = getFilename(req->path); free(url); }
std::string net::URL::toString() const { return net::urlJoin(getProtocol(), getHost(), getPort(), getPath(), getQuery(), getFragment()); }
/* ---------------- seq_strct_2_duplicated_prob_vec ----------------------- * Duplikate the pvec while structure estimation and also duplicate the sequence, * each n-times. * return: * struct prob_vec *pvec * Notice: not used, but who knows if it will became useful one day ! * (Martin May, 2007) */ struct prob_vec * strct_2_duplicated_prob_vec (struct coord *structure, const struct seq *seq, const struct seqprof *sp, const size_t size, const struct aa_strct_clssfcn *cmodel, const size_t n_duplications) { size_t i, j; float *fragment; struct prob_vec *pvec; float **aa_prob; struct aa_clssfcn *aa_class; const size_t n_pvec = size - cmodel->n_att + 1; if ((pvec = new_pvec (cmodel->n_att, n_duplications * size , n_duplications * n_pvec, cmodel->strct->n_class))!= NULL) { for (i = 0; i < (n_duplications * n_pvec); i++) /* Initialize mship */ for (j = 0; j < cmodel->strct->n_class; j++) pvec->mship[i][j] = cmodel->strct->class_weight[j]; if (structure) { /* Structure membership */ for (i = 0; i < n_pvec; i++){ /* for every fragment...*/ /* twice for every fragment on position i as on i + size */ fragment = getFragment (i , cmodel->n_att, structure); for (j = 0; j < n_duplications; j++){ if (computeMembershipStrct(pvec->mship[ i + j * n_pvec], fragment, cmodel->strct) == NULL) { prob_vec_destroy (pvec); return NULL; } } } free_if_not_null (fragment); } if (sp || seq) { /* Sequence or profile membership */ aa_prob = f_matrix (n_duplications * n_pvec, cmodel->strct->n_class); aa_class = E_MALLOC (sizeof (struct aa_clssfcn)); aa_class->n_class = cmodel->strct->n_class; aa_class->n_att = cmodel->n_att; aa_class->log_pp = cmodel->log_pp; aa_class->class_wt = cmodel->strct->class_weight; if (seq){ struct seq *s = seq_duplicate ( seq , n_duplications ); if (computeMembershipAA (aa_prob, s, aa_class) == EXIT_FAILURE) { prob_vec_destroy (pvec); return NULL; } seq_destroy (s); } else if (sp) { if (computeMembershipAAProf (aa_prob, sp, aa_class) == EXIT_FAILURE) { prob_vec_destroy (pvec); return NULL; } } free (aa_class); for (i = 0; i < n_duplications * n_pvec; i++) for (j = 0; j < cmodel->strct->n_class; j++) pvec->mship[i][j] *= aa_prob[i][j]; kill_f_matrix (aa_prob); } for (i = 0; i < (n_duplications * n_pvec); i++){ double sum = 0.0; for (j = 0; j < cmodel->strct->n_class; j++) sum += pvec->mship[i][j]; for (j = 0; j < cmodel->strct->n_class; j++) pvec->mship[i][j] /= sum; } pvec->norm_type = PVEC_TRUE_PROB; } return pvec; }
/* ---------------- seq_strct_2_prob_vec ----------------------- * This calculates probabilities for using combinations of * sequence and structure, sequence profile and structure, * sequence only, sequence profile only, and structure only. */ static struct prob_vec * seq_strct_2_prob_vec (struct coord *structure, const struct seq *seq, const struct seqprof *sp, const size_t size, const struct aa_strct_clssfcn *cmodel, const enum yes_no norm) { size_t i, j, compnd_len; float *fragment; struct prob_vec *pvec; float **aa_prob; struct aa_clssfcn *aa_class; const size_t n_pvec = size - cmodel->n_att + 1; if ((pvec = new_pvec (cmodel->n_att, size,n_pvec, cmodel->strct->n_class))!= NULL) { for (i = 0; i < n_pvec; i++) /* Initialize mship */ for (j = 0; j < cmodel->strct->n_class; j++) pvec->mship[i][j] = cmodel->strct->class_weight[j]; if (structure) { /* Structure membership */ for (i = 0; i < n_pvec; i++) { /* for every fragment...*/ fragment = getFragment (i, cmodel->n_att, structure); if (computeMembershipStrct(pvec->mship[i], fragment, cmodel->strct) == NULL) { prob_vec_destroy (pvec); return NULL; } } free_if_not_null (fragment); } if (sp || seq) { /* Sequence or profile membership */ aa_prob = f_matrix (n_pvec, cmodel->strct->n_class); aa_class = E_MALLOC (sizeof (struct aa_clssfcn)); aa_class->n_class = cmodel->strct->n_class; aa_class->n_att = cmodel->n_att; aa_class->log_pp = cmodel->log_pp; aa_class->class_wt = cmodel->strct->class_weight; if (seq){ struct seq *s = seq_copy (seq); if (computeMembershipAA (aa_prob, s, aa_class) == EXIT_FAILURE) { prob_vec_destroy (pvec); return NULL; } seq_destroy (s); } else if (sp) { if (computeMembershipAAProf (aa_prob, sp, aa_class) == EXIT_FAILURE) { prob_vec_destroy (pvec); return NULL; } } free (aa_class); for (i = 0; i < n_pvec; i++) for (j = 0; j < cmodel->strct->n_class; j++) pvec->mship[i][j] *= aa_prob[i][j]; kill_f_matrix (aa_prob); } if (norm == YES) { for (i = 0; i < n_pvec; i++){ double sum = 0.0; for (j = 0; j < cmodel->strct->n_class; j++) sum += pvec->mship[i][j]; for (j = 0; j < cmodel->strct->n_class; j++) pvec->mship[i][j] /= sum; } pvec->norm_type = PVEC_TRUE_PROB; } } /*shoffmann*/ compnd_len = structure->compnd_len; /*finally read compound*/ if(compnd_len > 0){ pvec->compnd = E_MALLOC(compnd_len*sizeof(char)); pvec->compnd = memmove(pvec->compnd, structure->compnd, compnd_len); } pvec->compnd_len = compnd_len; return pvec; }