/** * @brief 임의의 책과 관련된 뷰를 View pool 에서 제거하는 함수 * @param pBook : 뷰를 제거할 책 * @return success(ture)/fail(false) */ BOOL CViewPoolManager::RemoveView(CWnd* pBook) { TRACEMSG(_T("CViewPoolManager::RemoveView() START")); // ViewPool::iterator iter = m_pool.find(pBook); if(iter == m_pool.end()) { TRACEMSG_ERR(_T("CViewPoolManager::RemoveView() - The map m_pool dosen't have an element with a key of \"pWnd\"")); return FALSE; } // 뷰 개수 업데이트 CViewManager *pMgr = (CViewManager *)iter->second; if(pMgr) { if(pMgr->GetCount() > 0 ) m_nPoolCnt -= pMgr->GetCount(); } // 뷰 매니져 리스트에서 해당 책의 매니져 삭제 m_pool.erase(iter); // TRACEMSG(_T("CViewPoolManager::RemoveView() END")); // return FALSE; }
int skTimerDestroy( sk_timer_t *timer) { if (NULL == timer) { return 0; } TRACEMSG(1, ("Timer %p: Starting to destroy", (void *)timer)); /* Grab the mutex */ sk_timer_lock(timer); timer->stopping = 1; if (timer->started) { /* Wake the timer thread so it can check 'stopping' */ sk_timer_wake(timer); /* Wait for timer process to end */ while (!timer->stopped) { sk_timer_wait(timer); } } /* Unlock and destroy mutexes */ sk_timer_unlock(timer); TRACEMSG(1, ("Timer %p: Freeing all resources", (void *)timer)); pthread_mutex_destroy(&timer->mutex); pthread_cond_destroy(&timer->cond); free(timer); return 0; }
/** * @brief 소멸자 */ CViewPoolManager::~CViewPoolManager(void) { TRACEMSG(_T("CViewPoolManager::~CViewPoolManager() START")); // if(m_pool.size() > 0) m_pool.clear(); // TRACEMSG(_T("CViewPoolManager::~CViewPoolManager() END")); }
/*! * This function is used to unsubscribe on an event. * * @param event_unsub structure of event, it contains type of event and callback * * @return This function returns 0 if successful. */ int mc13783_event_unsubscribe_internal(type_event_notification event_unsub) { notify_event *del_notify_event; notify_event **notify_event_var; notify_event *notify_event_var2; down_interruptible(&sem_event); TRACEMSG(_K_D("event unsubscribe\n")); notify_event_var = ¬ify_event_tab[event_unsub.event]; notify_event_var2 = *notify_event_var; if (*notify_event_var == NULL) { TRACEMSG(_K_I("unsubsribe error (event not found)")); return ERROR_UNSUBSCRIBE; } if (event_unsub.param == (void *)NO_PARAM) { while ((notify_event_var2)->callback != event_unsub.callback) { if (notify_event_var2->next_notify_event != NULL) { (notify_event_var) = (notify_event **) & (notify_event_var2->next_notify_event); (notify_event_var2) = (notify_event *) (notify_event_var2)->next_notify_event; } else { TRACEMSG(_K_I("Error (callback not found)")); return ERROR_UNSUBSCRIBE; } } } else { while ((notify_event_var2)->callback_p != event_unsub.callback_p) { if (notify_event_var2->next_notify_event != NULL) { (notify_event_var) = (notify_event **) & (notify_event_var2->next_notify_event); (notify_event_var2) = (notify_event *) (notify_event_var2)->next_notify_event; } else { TRACEMSG(_K_I("Error (callback not found)")); return ERROR_UNSUBSCRIBE; } } } (*notify_event_var) = (notify_event *) (notify_event_var2)->next_notify_event; del_notify_event = (notify_event_var2); kfree(del_notify_event); del_notify_event = NULL; up(&sem_event); CHECK_ERROR(mask(event_unsub.event)); return 0; }
void SetUpWorkingDirectories(const char* argv0) { // set up working directories workingDir = wxGetCwd().c_str(); #ifdef __WXGTK__ if (getenv("CN3D_HOME") != NULL) programDir = getenv("CN3D_HOME"); else #endif if (wxIsAbsolutePath(argv0)) programDir = wxPathOnly(argv0).c_str(); else if (wxPathOnly(argv0) == "") programDir = workingDir; else programDir = workingDir + wxFILE_SEP_PATH + wxPathOnly(argv0).c_str(); workingDir = workingDir + wxFILE_SEP_PATH; programDir = programDir + wxFILE_SEP_PATH; // find or create preferences folder wxString localDir; wxSplitPath((wxFileConfig::GetLocalFileName("unused")).c_str(), &localDir, NULL, NULL); wxString prefsDirLocal = localDir + wxFILE_SEP_PATH + "Cn3D_User"; wxString prefsDirProg = wxString(programDir.c_str()) + wxFILE_SEP_PATH + "Cn3D_User"; if (wxDirExists(prefsDirLocal)) prefsDir = prefsDirLocal.c_str(); else if (wxDirExists(prefsDirProg)) prefsDir = prefsDirProg.c_str(); else { // try to create the folder if (wxMkdir(prefsDirLocal) && wxDirExists(prefsDirLocal)) prefsDir = prefsDirLocal.c_str(); else if (wxMkdir(prefsDirProg) && wxDirExists(prefsDirProg)) prefsDir = prefsDirProg.c_str(); } if (prefsDir.size() == 0) WARNINGMSG("Can't create Cn3D_User folder at either:" << "\n " << prefsDirLocal << "\nor " << prefsDirProg); else prefsDir += wxFILE_SEP_PATH; // set data dir, and register the path in C toolkit registry (mainly for BLAST code) #ifdef __WXMAC__ dataDir = programDir + "../Resources/data/"; #else dataDir = programDir + "data" + wxFILE_SEP_PATH; #endif TRACEMSG("working dir: " << workingDir.c_str()); TRACEMSG("program dir: " << programDir.c_str()); TRACEMSG("data dir: " << dataDir.c_str()); TRACEMSG("prefs dir: " << prefsDir.c_str()); }
int skTimerCreateAtTime( sk_timer_t **new_timer, uint32_t interval, sktime_t start, skTimerFn_t callback_fn, void *callback_data) { #if TRACEMSG_LEVEL > 0 char tstamp[SKTIMESTAMP_STRLEN]; #endif sk_timer_t *timer; pthread_t thread; int err; timer = (sk_timer_t *)calloc(1, sizeof(sk_timer_t)); if (NULL == timer) { return errno; } timer->interval = (int64_t)interval; timer->callback_fn = callback_fn; timer->callback_data = callback_data; timer->base_time.tv_sec = sktimeGetSeconds(start); timer->base_time.tv_usec = sktimeGetMilliseconds(start) * 1000; pthread_mutex_init(&timer->mutex, NULL); pthread_cond_init(&timer->cond, NULL); TRACEMSG(1, (("Timer %p: Created with interval=%" PRId64 ", start_time=%sZ"), (void *)timer, timer->interval, sktimestamp_r(tstamp, start, SKTIMESTAMP_UTC))); /* Mutex starts locked */ sk_timer_lock(timer); timer->started = 1; err = skthread_create_detached("sktimer", &thread, sk_timer_thread, (void *)timer); if (err) { timer->started = 0; sk_timer_unlock(timer); TRACEMSG(1, ("Timer %p: Failed to start; errno = %d", (void *)timer, err)); skTimerDestroy(timer); return err; } sk_timer_unlock(timer); TRACEMSG(1, ("Timer %p: Started", (void *)timer)); *new_timer = timer; return 0; }
/*! * This function is the bottom half of the mc13783 Interrupt. * It checks the IT and launch client callback. * */ void mc13783_wq_handler(void *code) { unsigned int status = 0, j = 0; unsigned int reg_value = 0; unsigned int mask_value = 0; TRACEMSG(_K_I("mc13783 IT bottom half")); TRACEMSG(_K_D("Test first it regs")); /* read and clear the status bit */ status = ISR_MASK_EVENT_IT_0; mc13783_hs_write_reg(REG_INTERRUPT_STATUS_0, &status); /* reset unused bits */ reg_value &= ISR_MASK_EVENT_IT_0; reg_value = status & ~mc13783_mask_0; if (reg_value != 0) { for (j = 0; j < ISR_NB_BITS; j++) { mask_value = 1 << j; if (mask_value & reg_value) { launch_all_call_back_event((type_event) mask_bit_event_0[j]); } } } TRACEMSG(_K_D("Test second IT regs")); /* read and clear the status bit */ status = ISR_MASK_EVENT_IT_1; mc13783_hs_write_reg(REG_INTERRUPT_STATUS_1, &status); reg_value = status & ~mc13783_mask_1; /* reset unused bits */ reg_value &= ISR_MASK_EVENT_IT_1; if (reg_value != 0) { for (j = 0; j < ISR_NB_BITS; j++) { mask_value = 1 << j; if (mask_value & reg_value) { launch_all_call_back_event((type_event) mask_bit_event_1[j]); } } } }
PUBLIC NET_StreamClass * NET_ProxyConverter(int format_out, void *data_obj, URL_Struct *URL_s, MWContext *window_id) { NET_StreamClass* stream; ProxyObj * obj; TRACEMSG(("Setting up display stream. Have URL: %s \n%s\n", URL_s->address, URL_s->content_type)); stream = XP_NEW(NET_StreamClass); if(stream == NULL) return(NULL); obj = XP_NEW(ProxyObj); if(obj == NULL) { FREE(stream); return(NULL); } XP_MEMSET(obj, 0, sizeof(ProxyObj)); stream->data_object = obj; stream->name = "ProxyWriter"; stream->complete = (MKStreamCompleteFunc) net_proxy_complete; stream->abort = (MKStreamAbortFunc) net_proxy_abort; stream->put_block = (MKStreamWriteFunc) net_proxy_write; stream->is_write_ready = (MKStreamWriteReadyFunc) net_proxy_WriteReady; stream->window_id = window_id; TRACEMSG(("Returning stream from display_converter\n")); /* send HTTP headers if not already getting an HTTP doc */ if(strncasecomp(URL_s->address,"http:",5)) { obj->definately_send_headers = TRUE; } StrAllocCopy(obj->content_type, URL_s->content_type); StrAllocCopy(obj->content_encoding, URL_s->content_encoding); return stream; }
void Sequence::AddMMDBAnnotTag(int mmdbID) const { CBioseq::TAnnot::const_iterator a, ae = bioseqASN->GetAnnot().end(); CSeq_annot::C_Data::TIds::const_iterator i, ie; bool found = false; for (a=bioseqASN->GetAnnot().begin(); a!=ae; ++a) { if ((*a)->GetData().IsIds()) { for (i=(*a)->GetData().GetIds().begin(), ie=(*a)->GetData().GetIds().end(); i!=ie; ++i) { if ((*i)->IsGeneral() && (*i)->GetGeneral().GetDb() == "mmdb" && (*i)->GetGeneral().GetTag().IsId()) { found = true; TRACEMSG("mmdb link already present in sequence " << identifier->ToString()); if ((*i)->GetGeneral().GetTag().GetId() != mmdbID || (identifier->mmdbID != MoleculeIdentifier::VALUE_NOT_SET && identifier->mmdbID != mmdbID)) ERRORMSG("Sequence::AddMMDBAnnotTag() - mmdbID mismatch"); break; } } } if (found) break; } if (!found) { CRef < CSeq_id > seqid(new CSeq_id()); seqid->SetGeneral().SetDb("mmdb"); seqid->SetGeneral().SetTag().SetId(mmdbID); CRef < CSeq_annot > annot(new CSeq_annot()); annot->SetData().SetIds().push_back(seqid); (const_cast<Sequence*>(this))->bioseqASN->SetAnnot().push_back(annot); } }
PUBLIC NET_StreamClass * #endif XML_XMLConverter(FO_Present_Types format_out, void *data_object, URL_Struct *URL_s, MWContext *window_id) { NET_StreamClass* stream; XMLFile xmlf; TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address)); xmlf = (XMLFile) getMem(sizeof(XMLFileStruct)); xmlf->holdOver = getMem(XML_BUF_SIZE); xmlf->lineSize = XML_LINE_SIZE; xmlf->line = (char*)getMem(XML_LINE_SIZE); xmlf->urls = URL_s; xmlf->address = copyString(URL_s->address); xmlf->mwcontext = window_id; xmlf->numOpenStreams = 1; /* URL_s->fedata = xmlf; */ stream = NET_NewStream("XML", (MKStreamWriteFunc)parseNextXMLBlob, (MKStreamCompleteFunc)xml_complete, (MKStreamAbortFunc)xml_abort, (MKStreamWriteReadyFunc)xml_write_ready, xmlf, window_id); if (stream == NULL) freeMem(xmlf); return(stream); }
std::unique_ptr<UConverter, UConverterDeleter> make_uconv(const std::string& encoding) { icu::ErrorCode ec{}; UConverter* conv_ptr = ucnv_open(encoding.c_str(), ec); if (!ec.isSuccess()) throw IcuUtilsException(TRACEMSG(std::string() + "Error creating converter for encoding: [" + encoding + "]," " error: [" + ec.errorName() + "]")); return std::unique_ptr<UConverter, UConverterDeleter>{conv_ptr, UConverterDeleter{}}; }
SequenceSet::SequenceSet(StructureBase *parent, SeqEntryList& seqEntries) : StructureBase(parent) { SeqEntryList::iterator s, se = seqEntries.end(); for (s=seqEntries.begin(); s!=se; ++s) UnpackSeqEntry(s->GetObject(), this, sequences); TRACEMSG("number of sequences: " << sequences.size()); }
void test() { auto line = __LINE__; auto msg = TRACEMSG("foo"); auto expected = std::string("foo\n") .append(" at myfancynamespace::test(tracemsg_test.cpp:") .append(ss::to_string(line + 1)) .append(")"); slassert(expected == msg); }
void ViewerWindowBase::OnTitleView(wxCommandEvent& event) { TRACEMSG("in OnTitleView()"); switch (event.GetId()) { case MID_SHOW_TITLES: viewerWidget->TitleAreaOn(); break; case MID_HIDE_TITLES: viewerWidget->TitleAreaOff(); break; } }
void ShowHideManager::ShowHideCallbackFunction(const vector < bool >& itemsEnabled) { if (itemsEnabled.size() != structureInfo.size()) { ERRORMSG("ShowHideManager::ShowHideCallbackFunction() - wrong size list"); return; } for (unsigned int i=0; i<itemsEnabled.size(); ++i) structureInfo[i]->Show(this, itemsEnabled[i]); TRACEMSG("entities hidden: " << entitiesHidden.size()); }
PUBLIC NET_StreamClass * #endif XML_CSSConverter(FO_Present_Types format_out, void *data_object, URL_Struct *URL_s, MWContext *window_id) { StyleSheet ss = (StyleSheet) URL_s->fe_data; TRACEMSG(("Setting up style sheet stream. Have URL: %s\n", URL_s->address)); return NET_NewStream("XML-CSS", (MKStreamWriteFunc)parseNextXMLCSSBlob, (MKStreamCompleteFunc)xmlcss_complete, (MKStreamAbortFunc)xmlcss_abort, (MKStreamWriteReadyFunc)xmlcss_write_ready, ss, window_id); }
/** * @brief 책의 뷰를 만드는 함수 * @param pBook : 뷰를 만들 책의 인스턴스 포인터 * @param pRuntimeClass : 생성할 뷰의 런타임 클래스 * @return true(success)/false(fail) */ BOOL CViewPoolManager::CreateView(CWnd* pBook, CRuntimeClass* pRuntimeClass) { TRACEMSG(_T("CViewPoolManager::CreateView() START")); // BOOL bRes = FALSE; CEPubBook *pEpub = (CEPubBook *)pBook; if(pEpub){ // 처음 open 할 때는 무조건 모든 spine 파일을 Read 한다. // STEP 1) Create CViewManager *pViewMgr = new CViewManager; if(pViewMgr) { if(pRuntimeClass ==NULL) bRes = pViewMgr->CreateView(pBook); else bRes = pViewMgr->CreateView(pBook, pRuntimeClass); if(bRes) { pEpub->SetViewManager(pViewMgr); // STEP 2) Add view to pool m_nPoolCnt += pViewMgr->GetCount(); m_pool.insert( ViewPool::value_type(pBook, pViewMgr)); } else { TRACEMSG_ERR(_T("CViewManager failed to create views")); delete pViewMgr; } } } // TRACEMSG(_T("CViewPoolManager::CreateView() END")); // return bRes; }
/*! * This function calls all callback of a specific event. * * @param event structure of event, it contains type of event */ void launch_all_call_back_event(type_event event) { notify_event *notify_event_var; void (*cur_callback) (void); void (*cur_callback_p) (void *param); void *param; down_interruptible(&sem_event); if (notify_event_tab[event] != NULL) { notify_event_var = notify_event_tab[event]; do { if (notify_event_var->callback != NULL) { TRACEMSG(_K_D("Callback without param")); cur_callback = notify_event_var->callback; up(&sem_event); cur_callback(); down_interruptible(&sem_event); } else if (notify_event_var->callback_p != NULL) { TRACEMSG(_K_D("Callback with param")); cur_callback_p = notify_event_var->callback_p; param = notify_event_var->param; up(&sem_event); cur_callback_p(param); down_interruptible(&sem_event); } TRACEMSG(_K_D("Callback done")); notify_event_var = (notify_event *) notify_event_var->next_notify_event; } while (notify_event_var != NULL); } else { TRACEMSG(_K_I ("it mc13783 event %d detected but not subscribed"), event); } up(&sem_event); }
// it may be better to get such information through // "ThreadStart" and "ThreadEnd" events instead of this direct method std::string handle_GetLiveThreadsCount(jvmtiEnv* jvmti, JNIEnv* jni, const std::string&) { jthread* threads = nullptr; jint count = -1; auto error = jvmti->GetAllThreads(&count, &threads); auto error_str = to_error_message(jvmti, error); if (!error_str.empty()) { throw std::runtime_error(TRACEMSG(error_str)); } // release threads for (jint i = 0; i < count; i++) { jni->DeleteLocalRef(threads[i]); } jvmti->Deallocate(reinterpret_cast<unsigned char*> (threads)); return std::to_string(count); }
/*! * This function sets a bit in mask register of mc13783 to mask an event IT. * * @param event structure of event, it contains type of event * * @return This function returns 0 if successful. */ int unmask(type_event event) { int bit_index = 0, j = 0, k = 0, *mc13783_mask; unsigned int mask_value = 0, mask = 0; unsigned int mask_reg = 0, status_reg = 0; int event_test = 0, *mask_done; if (event < EVENT_E1HZI) { mask_reg = REG_INTERRUPT_MASK_0; status_reg = REG_INTERRUPT_STATUS_0; mc13783_mask = &mc13783_mask_0; } else { mask_reg = REG_INTERRUPT_MASK_1; status_reg = REG_INTERRUPT_STATUS_1; mc13783_mask = &mc13783_mask_1; } for (j = 0; j < ISR_NB_BITS; j++) { k = 1 << j; if (event < EVENT_E1HZI) { event_test = mask_bit_event_0[j]; } else { event_test = mask_bit_event_1[j]; } if (event_test == event) { mask = k; bit_index = j + 1; } } if (event < EVENT_E1HZI) { mask_done = &mask_done_0[bit_index]; } else { mask_done = &mask_done_1[bit_index]; } if (*mask_done == 0) { /* Unmask MASK bit */ CHECK_ERROR(mc13783_hs_read_reg(mask_reg, &mask_value)); mask_value &= ~mask; *mc13783_mask = mask_value; CHECK_ERROR(mc13783_hs_write_reg(mask_reg, &mask_value)); } (*mask_done)++; TRACEMSG(_K_D("IT Number : %d"), (*mask_done)); return 0; }
PUBLIC NET_StreamClass * NET_HTMLHelpMapToURL(int format_out, void *data_object, URL_Struct *URL_s, MWContext *window_id) { html_help_map_stream* obj; NET_StreamClass* stream; TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address)); stream = XP_NEW(NET_StreamClass); if(stream == NULL) return(NULL); obj = XP_NEW(html_help_map_stream); if (obj == NULL) { FREE(stream); return(NULL); } XP_MEMSET(obj, 0, sizeof(html_help_map_stream)); if(URL_s->cache_file || URL_s->memory_copy) obj->file_is_local = TRUE; else obj->file_is_local = NET_IsLocalFileURL(URL_s->address); obj->parse_obj = net_ParseHTMLHelpInit(URL_s->address, URL_s->fe_data); if(!obj->parse_obj) { FREE(stream); FREE(obj); } obj->context = window_id; stream->name = "HTML Help Map File converter"; stream->complete = (MKStreamCompleteFunc) net_HMFConvComplete; stream->abort = (MKStreamAbortFunc) net_HMFConvAbort; stream->put_block = (MKStreamWriteFunc) net_HMFConvPut; stream->is_write_ready = (MKStreamWriteReadyFunc) net_HMFConvWriteReady; stream->data_object = obj; /* document info object */ stream->window_id = window_id; return(stream); }
AlignmentSet::AlignmentSet(StructureBase *parent, const Sequence *masterSequence, const SeqAnnotList& seqAnnots) : StructureBase(parent), master(masterSequence), newAsnAlignmentData(NULL) { if (!master || !parentSet->sequenceSet) { ERRORMSG("AlignmentSet::AlignmentSet() - need sequenceSet and master before parsing alignments"); return; } // assume the data manager has collapsed all valid seqaligns into a single seqannot CSeq_annot::C_Data::TAlign::const_iterator a, ae = seqAnnots.front()->GetData().GetAlign().end(); for (a=seqAnnots.front()->GetData().GetAlign().begin(); a!=ae; ++a) alignments.push_back(new MasterDependentAlignment(this, master, **a)); TRACEMSG("number of alignments: " << alignments.size()); }
int CConnectMR::Offline() { if ((*_ppatmr) == NULL) { (*_ppatmr) = new CAudioTalkMR(_pcmt); } if ((*_ppatmr) == NULL) { TRACEMSG("new memory fault!\n"); return 1; } int ret = (*_ppatmr)->InitOffline(); return ret; }
void LoadRegistry(void) { // first set up defaults, then override any/all with stuff from registry file SetRegistryDefaults(); if (GetPrefsDir().size() > 0) registryFile = GetPrefsDir() + "Preferences"; else registryFile = GetProgramDir() + "Preferences"; auto_ptr<CNcbiIfstream> iniIn(new CNcbiIfstream(registryFile.c_str(), IOS_BASE::in | IOS_BASE::binary)); if (*iniIn) { TRACEMSG("loading program registry " << registryFile); registry.Read(*iniIn, (CNcbiRegistry::ePersistent | CNcbiRegistry::eOverride)); } registryChanged = false; }
/*! * This function is used to subscribe on an event. * * @param event_sub structure of event, it contains type of event and callback * * @return This function returns 0 if successful. */ int mc13783_event_subscribe_internal(type_event_notification event_sub) { notify_event *new_notify_event; void *pmem = kmalloc(sizeof(notify_event), GFP_KERNEL); /*check? */ TRACEMSG(_K_D("event subscribe\n")); down_interruptible(&sem_event); new_notify_event = notify_event_tab[event_sub.event]; if (new_notify_event == NULL) { notify_event_tab[event_sub.event] = (notify_event *) pmem; new_notify_event = notify_event_tab[event_sub.event]; new_notify_event->callback = NULL; new_notify_event->callback_p = NULL; new_notify_event->param = (void *)NO_PARAM; } else { while (new_notify_event->next_notify_event != NULL) { new_notify_event = (notify_event *) new_notify_event->next_notify_event; } new_notify_event->next_notify_event = (notify_event *) pmem; new_notify_event = (notify_event *) new_notify_event->next_notify_event; new_notify_event->callback = NULL; new_notify_event->callback_p = NULL; new_notify_event->param = (void *)NO_PARAM; } if (event_sub.param != (void *)NO_PARAM) { new_notify_event->callback_p = event_sub.callback_p; new_notify_event->param = event_sub.param; } else { new_notify_event->callback = event_sub.callback; } new_notify_event->next_notify_event = NULL; up(&sem_event); CHECK_ERROR(unmask(event_sub.event)); /* test if event is not available */ mc13783_wq_handler(NULL); return 0; }
int CConnectMR::InitATMR(char* listenerIp) { if ((*_ppatmr) == NULL) { (*_ppatmr) = new CAudioTalkMR(_pcmt); } if ((*_ppatmr) == NULL) { TRACEMSG("new memory fault!\n"); return 1; } int ret = (*_ppatmr)->Initialize(listenerIp, RTP_PORT, RTP_PORT, _type); //if (ret == 0) //{ // MessageBox(NULL, _T("begin"), NULL, MB_OK); //} return ret; }
/* * This function takes an error code and associated error data * and creates a string containing a textual description of * what the error is and why it happened. * * The returned string is allocated and thus should be freed * once it has been used. */ PUBLIC char * NET_ExplainErrorDetails (int code, ...) { va_list args; char *msg = 0; int sub_error; va_start (args, code); if (IS_SSL_ERROR(code) || IS_SEC_ERROR(code)) { const char *s = XP_GetString(code); msg = (s ? XP_STRDUP(s) : 0); } if (!msg) switch(code) { case MK_INTERRUPTED: case MK_USE_FTP_INSTEAD: case MK_USE_COPY_FROM_CACHE: case MK_MAILTO_NOT_READY: case MK_UNABLE_TO_LOGIN: case MK_UNABLE_TO_CONVERT: case MK_IMAGE_LOSSAGE: /* image library generic error */ case MK_ERROR_SENDING_DATA_COMMAND: case MK_OFFLINE: msg = NULL; break; case MK_REDIRECT_ATTEMPT_NOT_ALLOWED: case MK_SERVER_TIMEOUT: case MK_CONNECTION_TIMED_OUT: case MK_OUT_OF_MEMORY: case MK_TIMEBOMB_URL_PROHIBIT: case MK_TIMEBOMB_MESSAGE: case MK_RELATIVE_TIMEBOMB_MESSAGE: case MK_NO_WAIS_PROXY: case MK_CREATING_NEWSRC_FILE: case MK_NNTP_SERVER_NOT_CONFIGURED: case MK_NNTP_NEWSGROUP_SCAN_ERROR: case MK_ZERO_LENGTH_FILE: case MK_BAD_CONNECT: case MK_UNABLE_TO_USE_PASV_FTP: case MK_UNABLE_TO_CHANGE_FTP_MODE: case MK_UNABLE_TO_FTP_CWD: case MK_UNABLE_TO_SEND_PORT_COMMAND: case MK_UNABLE_TO_ACCEPT_SOCKET: case MK_UNABLE_TO_CONNECT2: case MK_BAD_NNTP_CONNECTION: case MK_NNTP_SERVER_ERROR: case MK_SERVER_DISCONNECTED: case MK_NEWS_ITEM_UNAVAILABLE: case MK_UNABLE_TO_OPEN_NEWSRC: case MK_COULD_NOT_LOGIN_TO_SMTP_SERVER: case MK_MSG_NO_SMTP_HOST: case MK_COULD_NOT_GET_USERS_MAIL_ADDRESS: case MK_UNABLE_TO_CONNECT_TO_PROXY: case MK_UNABLE_TO_LOCATE_PROXY: case MK_DISK_FULL: case MK_PRINT_LOSSAGE: case MK_SECURE_NEWS_PROXY_ERROR: case MK_SIGNATURE_TOO_LONG: case MK_SIGNATURE_TOO_WIDE: case MK_POP3_SERVER_ERROR: case MK_POP3_USERNAME_UNDEFINED: case MK_POP3_PASSWORD_UNDEFINED: case MK_POP3_USERNAME_FAILURE: case MK_POP3_PASSWORD_FAILURE: case MK_POP3_NO_MESSAGES: case MK_POP3_LIST_FAILURE: case MK_POP3_LAST_FAILURE: case MK_POP3_RETR_FAILURE: case MK_POP3_DELE_FAILURE: case MK_POP3_OUT_OF_DISK_SPACE: case MK_POP3_MESSAGE_WRITE_ERROR: case MK_MIME_NO_SENDER: case MK_MIME_NO_RECIPIENTS: case MK_MIME_NO_SUBJECT: case MK_MIME_ERROR_WRITING_FILE: case MK_MIME_MULTIPART_BLURB: case MK_MSG_CANT_COPY_TO_SAME_FOLDER: case MK_MSG_CANT_COPY_TO_QUEUE_FOLDER: case MK_MSG_CANT_COPY_TO_QUEUE_FOLDER_OLD: case MK_MSG_CANT_COPY_TO_DRAFTS_FOLDER: case MK_MSG_CANT_CREATE_FOLDER: case MK_MSG_FOLDER_ALREADY_EXISTS: case MK_MSG_FOLDER_NOT_EMPTY: case MK_MSG_CANT_DELETE_FOLDER: case MK_MSG_CANT_CREATE_INBOX: case MK_MSG_CANT_CREATE_MAIL_DIR: case MK_MSG_NO_POP_HOST: case MK_MSG_MESSAGE_CANCELLED: case MK_MSG_FOLDER_UNREADABLE: case MK_MSG_FOLDER_SUMMARY_UNREADABLE: case MK_MSG_TMP_FOLDER_UNWRITABLE: case MK_MSG_ID_NOT_IN_FOLDER: case MK_MSG_NEWSRC_UNPARSABLE: case MK_MSG_NO_RETURN_ADDRESS: case MK_MSG_ERROR_WRITING_NEWSRC: case MK_MSG_ERROR_WRITING_MAIL_FOLDER: case MK_MSG_SEARCH_FAILED: case MK_MSG_FOLDER_BUSY: msg = XP_STRDUP(XP_GetString(code)); break; case MK_TCP_READ_ERROR: case MK_TCP_WRITE_ERROR: case MK_UNABLE_TO_CREATE_SOCKET: case MK_UNABLE_TO_CONNECT: case MK_HTTP_TYPE_CONFLICT: case MK_TCP_ERROR: sub_error = va_arg(args, int); if (IS_SSL_ERROR(sub_error) || IS_SEC_ERROR(sub_error)) { /* * For SSL/SEC errors, use the message without a wrapper. */ msg = XP_STRDUP(XP_GetString(sub_error)); } else if (code == MK_UNABLE_TO_CONNECT && (sub_error == XP_ERRNO_EINVAL || sub_error == XP_ERRNO_EADDRINUSE)) { /* * With unable-to-connect errors, some errno values/strings * are not more helpful, so just use a plain message for these. */ msg = XP_STRDUP(XP_GetString(MK_UNABLE_TO_CONNECT2)); } else { msg = PR_smprintf(XP_GetString(code), XP_GetString(sub_error)); } break; case MK_MALFORMED_URL_ERROR: case MK_COULD_NOT_PUT_FILE: case MK_UNABLE_TO_LOCATE_FILE: case MK_NNTP_AUTH_FAILED: case MK_UNABLE_TO_LOCATE_HOST: case MK_UNABLE_TO_LOCATE_SOCKS_HOST: case MK_UNABLE_TO_OPEN_FILE: case MK_UNABLE_TO_OPEN_TMP_FILE: case MK_CONNECTION_REFUSED: case MK_NNTP_ERROR_MESSAGE: case MK_MSG_COULDNT_OPEN_FCC_FILE: case MK_TIMEBOMB_WARNING_MESSAGE: case MK_RELATIVE_TIMEBOMB_WARNING_MESSAGE: case MK_ERROR_SENDING_FROM_COMMAND: case MK_ERROR_SENDING_RCPT_COMMAND: case MK_ERROR_SENDING_MESSAGE: case MK_SMTP_SERVER_ERROR: msg = PR_vsmprintf(XP_GetString(code), args); break; case -1: default: msg = PR_smprintf(XP_GetString(MK_COMMUNICATIONS_ERROR), code); break; } va_end (args); TRACEMSG(("NET_ExplainErrorDetails generated: %s", msg ? msg : "(none)")); return(msg); }
/* * THREAD ENTRY POINT * * This is the function the timer thread runs until the callback_fn * function returns SK_TIMER_END or the timer is destroyed. */ static void * sk_timer_thread( void *v_timer) { sk_timer_t *timer = (sk_timer_t *)v_timer; int rv; skTimerRepeat_t repeat; /* wait_time is when the timer is scheduled to fire */ struct timespec wait_time; /* next_time is one interval ahead of wait_time */ struct timeval next_time; /* current_time is now */ struct timeval current_time; /* Lock the mutex */ sk_timer_lock(timer); /* Have we been destroyed before we've even started? */ if (timer->stopping) { TRACEMSG(1, ("Timer %p: Thread stopped before initial run", v_timer)); goto END; } /* We do no calculations with fractional seconds in this function; * simply initialize the wait_time fractional seconds from the * fractional seconds on the base_time */ wait_time.tv_nsec = timer->base_time.tv_usec * 1000; /* Initialize next_time to the base_time */ next_time = timer->base_time; do { /* Skip to the next interval greater than the current time; * this way we avoid calling the function multiple times if * the function takes longer than 'interval' seconds to * complete. */ gettimeofday(¤t_time, NULL); if (next_time.tv_sec < current_time.tv_sec) { int64_t seconds_into_interval = ((int64_t)(current_time.tv_sec - timer->base_time.tv_sec) % timer->interval); TRACEMSG(1, (("Timer %p: next_time < current_time (%" PRId64 " < %" PRId64 "); %" PRId64 " seconds into an" " interval; setting next_time to %" PRId64), v_timer, (int64_t)next_time.tv_sec, (int64_t)current_time.tv_sec, seconds_into_interval, (int64_t)((current_time.tv_sec + timer->interval - seconds_into_interval)))); next_time.tv_sec = (current_time.tv_sec + timer->interval - seconds_into_interval); } wait_time.tv_sec = next_time.tv_sec; next_time.tv_sec += timer->interval; TRACEMSG(1, (("Timer %p: Scheduled to wake at %" PRId64 ".%09" PRId64), v_timer, (int64_t)wait_time.tv_sec, (int64_t)wait_time.tv_nsec)); /* Loop around pthread_cond_timedwait() forever until the * timer actually fires or the condition variable is signaled * (for example, during shutdown). When the timer fires, * invoke the callback_fn function and exit this for() loop. */ for (;;) { /* Mutex is released while within pthread_cond_timedwait */ TRACEMSG(2, ("Timer %p: Releasing lock and waiting [%d]", v_timer, __LINE__)); rv = pthread_cond_timedwait(&timer->cond, &timer->mutex, &wait_time); TRACEMSG(2, ("Timer %p: Acquired lock due to %s after waiting [%d]", v_timer, ((ETIMEDOUT == rv) ? "time-out" : ((0 == rv) ? "signal" : "other")), __LINE__)); if (timer->stopping) { TRACEMSG(1, ("Timer %p: Noticed stopping variable", v_timer)); goto END; } if (ETIMEDOUT == rv) { /* Timer timed out */ #ifdef CHECK_PTHREAD_COND_TIMEDWAIT /* Well, at least the timer thinks it timed out. * Let's see whether it did.... * * THIS IS A HORRIBLE HACK!! BACKGROUND: We have seen * instances where pthread_cond_timedwait() will fire * before it is supposed to. Since we only have * second resolution in the log, it may be firing a * full second early or it may firing a few * milliseconds early. This shouldn't really matter, * but the early timedwait() return is causing flowcap * files to get timestamps that are a second earlier * than expected, which means that the --clock-time * switch isn't operating as advertised. */ struct timeval now; gettimeofday(&now, NULL); if (now.tv_sec < wait_time.tv_sec) { /* Timer fired early. Call timedwait() again. * timedwait() may return immediately, so this has * the potential to spike the CPU until the * wait_time is reached. */ TRACEMSG(1, (("Timer %p: pthread_cond_timedwait() fired" " %" PRId64 " nanoseconds early"), v_timer, (((int64_t)(wait_time.tv_sec - now.tv_sec) * 1000000000) + (int64_t)wait_time.tv_nsec - ((int64_t)now.tv_usec * 1000)))); continue; } /* else timer fired at correct time (or later) */ #endif /* CHECK_PTHREAD_COND_TIMEDWAIT */ TRACEMSG(1, ("Timer %p: Invoking callback", v_timer)); repeat = timer->callback_fn(timer->callback_data); TRACEMSG(1, ("Timer %p: Callback returned %d", v_timer, (int)repeat)); break; } /* else, a signal interrupted the call; continue waiting */ TRACEMSG(1, (("Timer %p: pthread_cond_timedwait()" " returned unexpected value %d"), v_timer, rv)); } } while (SK_TIMER_REPEAT == repeat); END: /* Notify destroy function that we have ended properly. */ TRACEMSG(1, ("Timer %p: Thread is ending", v_timer)); timer->stopped = 1; sk_timer_wake(timer); sk_timer_unlock(timer); return NULL; }
/* * sortRandom(); * * Don't make any assumptions about the input. Store the input * records in a large buffer, and sort those in-core records once * all records are processed or the buffer is full. If the buffer * fills up, store the sorted records into temporary files. Once * all records are read, use mergeFiles() above to merge-sort the * temporary files. * * Exits the application if an error occurs. */ static void sortRandom( void) { int temp_file_idx = -1; skstream_t *input_rwios = NULL; /* input stream */ uint8_t *record_buffer = NULL; /* Region of memory for records */ uint8_t *cur_node = NULL; /* Ptr into record_buffer */ uint8_t *next_node = NULL; /* Ptr into record_buffer */ uint32_t buffer_max_recs; /* max buffer size (in number of recs) */ uint32_t buffer_recs; /* current buffer size (# records) */ uint32_t buffer_chunk_recs; /* how to grow from current to max buf */ uint32_t num_chunks; /* how quickly to grow buffer */ uint32_t record_count = 0; /* Number of records read */ int rv; /* Determine the maximum number of records that will fit into the * buffer if it grows the maximum size */ buffer_max_recs = buffer_size / NODE_SIZE; TRACEMSG((("buffer_size = %" PRIu64 "\nnode_size = %" PRIu32 "\nbuffer_max_recs = %" PRIu32), buffer_size, NODE_SIZE, buffer_max_recs)); /* We will grow to the maximum size in chunks */ num_chunks = NUM_CHUNKS; if (num_chunks <= 0) { num_chunks = 1; } /* Attempt to allocate the initial chunk. If we fail, increment * the number of chunks---which will decrease the amount we * attempt to allocate at once---and try again. */ for (;;) { buffer_chunk_recs = buffer_max_recs / num_chunks; TRACEMSG((("num_chunks = %" PRIu32 "\nbuffer_chunk_recs = %" PRIu32), num_chunks, buffer_chunk_recs)); record_buffer = (uint8_t*)malloc(NODE_SIZE * buffer_chunk_recs); if (record_buffer) { /* malloc was successful */ break; } else if (buffer_chunk_recs < MIN_IN_CORE_RECORDS) { /* give up at this point */ skAppPrintErr("Error allocating space for %d records", MIN_IN_CORE_RECORDS); appExit(EXIT_FAILURE); } else { /* reduce the amount we allocate at once by increasing the * number of chunks and try again */ TRACEMSG(("malloc() failed")); ++num_chunks; } } buffer_recs = buffer_chunk_recs; TRACEMSG((("buffer_recs = %" PRIu32), buffer_recs)); /* open first file */ rv = appNextInput(&input_rwios); if (rv < 0) { free(record_buffer); appExit(EXIT_FAILURE); } record_count = 0; cur_node = record_buffer; while (input_rwios != NULL) { /* read record */ if ((rv = skStreamReadRecord(input_rwios, (rwRec*)cur_node)) != SKSTREAM_OK) { if (rv != SKSTREAM_ERR_EOF) { skStreamPrintLastErr(input_rwios, rv, &skAppPrintErr); } /* end of file: close current and open next */ skStreamDestroy(&input_rwios); rv = appNextInput(&input_rwios); if (rv < 0) { free(record_buffer); appExit(EXIT_FAILURE); } continue; } ++record_count; cur_node += NODE_SIZE; if (record_count == buffer_recs) { /* Filled the current buffer */ /* If buffer not at max size, see if we can grow it */ if (buffer_recs < buffer_max_recs) { uint8_t *old_buf = record_buffer; /* add a chunk of records. if we are near the max, * set the size to the max */ buffer_recs += buffer_chunk_recs; if (buffer_recs + buffer_chunk_recs > buffer_max_recs) { buffer_recs = buffer_max_recs; } TRACEMSG((("Buffer full---attempt to grow to %" PRIu32 " records, %" PRIu32 " bytes"), buffer_recs, NODE_SIZE * buffer_recs)); /* attempt to grow */ record_buffer = (uint8_t*)realloc(record_buffer, NODE_SIZE * buffer_recs); if (record_buffer) { /* Success, make certain cur_node points into the * new buffer */ cur_node = (record_buffer + (record_count * NODE_SIZE)); } else { /* Unable to grow it */ TRACEMSG(("realloc() failed")); record_buffer = old_buf; buffer_max_recs = buffer_recs = record_count; } } /* Either buffer at maximum size or attempt to grow it * failed. */ if (record_count == buffer_max_recs) { /* Sort */ skQSort(record_buffer, record_count, NODE_SIZE, &rwrecCompare); /* Write to temp file */ if (skTempFileWriteBufferStream( tmpctx, &temp_file_idx, record_buffer, NODE_SIZE, record_count)) { skAppPrintSyserror( "Error writing sorted buffer to temporary file"); free(record_buffer); appExit(EXIT_FAILURE); } /* Reset record buffer to 'empty' */ record_count = 0; cur_node = record_buffer; } } } /* Sort (and maybe store) last batch of records */ if (record_count > 0) { skQSort(record_buffer, record_count, NODE_SIZE, &rwrecCompare); if (temp_file_idx >= 0) { /* Write last batch to temp file */ if (skTempFileWriteBufferStream( tmpctx, &temp_file_idx, record_buffer, NODE_SIZE, record_count)) { skAppPrintSyserror( "Error writing sorted buffer to temporary file"); free(record_buffer); appExit(EXIT_FAILURE); } } } /* Generate the output */ if (record_count == 0 && temp_file_idx == -1) { /* No records were read at all; write the header to the output * file */ rv = skStreamWriteSilkHeader(out_rwios); if (0 != rv) { skStreamPrintLastErr(out_rwios, rv, &skAppPrintErr); } } else if (temp_file_idx == -1) { /* No temp files written, just output batch of records */ uint32_t c; TRACEMSG((("Writing %" PRIu32 " records to '%s'"), record_count, skStreamGetPathname(out_rwios))); /* get first two records from the sorted buffer */ cur_node = record_buffer; next_node = record_buffer + NODE_SIZE; for (c = 1; c < record_count; ++c, next_node += NODE_SIZE) { if (0 != rwrecCompare(cur_node, next_node)) { /* records differ. print earlier record */ rv = skStreamWriteRecord(out_rwios, (rwRec*)cur_node); if (0 != rv) { skStreamPrintLastErr(out_rwios, rv, &skAppPrintErr); if (SKSTREAM_ERROR_IS_FATAL(rv)) { free(record_buffer); appExit(EXIT_FAILURE); } } cur_node = next_node; } /* else records are duplicates: ignore latter record */ } /* print remaining record */ rv = skStreamWriteRecord(out_rwios, (rwRec*)cur_node); if (0 != rv) { skStreamPrintLastErr(out_rwios, rv, &skAppPrintErr); if (SKSTREAM_ERROR_IS_FATAL(rv)) { free(record_buffer); appExit(EXIT_FAILURE); } } } else { /* no longer have a need for the record buffer */ free(record_buffer); record_buffer = NULL; /* now merge all the temp files */ mergeFiles(temp_file_idx); } if (record_buffer) { free(record_buffer); } }
void ViewerWindowBase::OnEditMenu(wxCommandEvent& event) { bool turnEditorOn = menuBar->IsChecked(MID_ENABLE_EDIT); switch (event.GetId()) { case MID_ENABLE_EDIT: if (turnEditorOn) { TRACEMSG("turning on editor"); if (!RequestEditorEnable(true)) { menuBar->Check(MID_ENABLE_EDIT, false); break; } EnableBaseEditorMenuItems(true); viewer->GetCurrentDisplay()->AddBlockBoundaryRows(); // add before push! viewer->EnableStacks(); // start up undo/redo stack system ProcessCommand(MID_DRAG_HORIZ); // switch to drag mode } else { TRACEMSG("turning off editor"); if (!RequestEditorEnable(false)) { // cancelled menuBar->Check(MID_ENABLE_EDIT, true); break; } EnableBaseEditorMenuItems(false); viewer->GetCurrentDisplay()->RemoveBlockBoundaryRows(); if (!(menuBar->IsChecked(MID_SELECT_COLS) || menuBar->IsChecked(MID_SELECT_ROWS) || menuBar->IsChecked(MID_SELECT_BLOCKS))) ProcessCommand(MID_SELECT_RECT); } break; case MID_UNDO: TRACEMSG("undoing..."); viewer->Undo(); UpdateDisplay(viewer->GetCurrentDisplay()); if (AlwaysSyncStructures()) SyncStructures(); break; case MID_REDO: TRACEMSG("redoing..."); viewer->Redo(); UpdateDisplay(viewer->GetCurrentDisplay()); if (AlwaysSyncStructures()) SyncStructures(); break; case MID_SPLIT_BLOCK: CancelAllSpecialModesExcept(MID_SPLIT_BLOCK); if (DoSplitBlock()) SetCursor(*wxCROSS_CURSOR); else SplitBlockOff(); break; case MID_MERGE_BLOCKS: CancelAllSpecialModesExcept(MID_MERGE_BLOCKS); if (DoMergeBlocks()) { SetCursor(*wxCROSS_CURSOR); prevMouseMode = viewerWidget->GetMouseMode(); viewerWidget->SetMouseMode(GetMouseModeForCreateAndMerge()); } else MergeBlocksOff(); break; case MID_CREATE_BLOCK: CancelAllSpecialModesExcept(MID_CREATE_BLOCK); if (DoCreateBlock()) { SetCursor(*wxCROSS_CURSOR); prevMouseMode = viewerWidget->GetMouseMode(); viewerWidget->SetMouseMode(GetMouseModeForCreateAndMerge()); } else CreateBlockOff(); break; case MID_DELETE_BLOCK: CancelAllSpecialModesExcept(MID_DELETE_BLOCK); if (DoDeleteBlock()) SetCursor(*wxCROSS_CURSOR); else DeleteBlockOff(); break; case MID_SYNC_STRUCS: viewer->GetCurrentDisplay()->RedrawAlignedMolecules(); break; } }