JNIEXPORT jstring JNICALL Java_excute_readMsgFromMsgQ(JNIEnv *env, jobject, jint msgQKey) { char buff[2048]; mMsgQ mq(msgQKey); mq.recvMsg(buff); jstring result = stoJstring(env, (const char*)buff); return result; }
void WebEmberManager::sendMessage(const std::string& msg) { try { boost::interprocess::message_queue mq(boost::interprocess::open_only, "WEBEMBER_PLUGIN"); mq.send(msg.c_str(), msg.size() + 1, 0); } catch (const std::exception& ex) { S_LOG_WARNING("Failed to send a message to the plugin. " << ex); } catch (...) { S_LOG_WARNING("Failed to send a message to the plugin."); } }
void LocalFileOffsetStore::load() { std::ifstream ifs(m_storeFile.c_str(), std::ios::in); if (ifs.good()) { if (ifs.is_open()) { if (ifs.peek() != std::ifstream::traits_type::eof()) { map<string, int64> m_offsetTable_tmp; boost::system::error_code e; try { boost::archive::text_iarchive ia(ifs); ia >> m_offsetTable_tmp; } catch (...) { LOG_ERROR( "load offset store file failed, please check whether file: %s is " "cleared by operator, if so, delete this offsets.Json file and " "then restart consumer", m_storeFile.c_str()); ifs.close(); string errorMsg("load offset store file: "); errorMsg.append(m_storeFile) .append( " failed, please check whether offsets.Json is cleared by " "operator, if so, delete this offsets.Json file and then " "restart consumer"); THROW_MQEXCEPTION(MQClientException, errorMsg, -1); } ifs.close(); for (map<string, int64>::iterator it = m_offsetTable_tmp.begin(); it != m_offsetTable_tmp.end(); ++it) { // LOG_INFO("it->first:%s, it->second:%lld", it->first.c_str(), // it->second); Json::Reader reader; Json::Value object; reader.parse(it->first.c_str(), object); MQMessageQueue mq(object["topic"].asString(), object["brokerName"].asString(), object["queueId"].asInt()); updateOffset(mq, it->second); } m_offsetTable_tmp.clear(); } else { LOG_ERROR( "open offset store file failed, please check whether file: %s is " "cleared by operator, if so, delete this offsets.Json file and " "then restart consumer", m_storeFile.c_str()); THROW_MQEXCEPTION(MQClientException, "open offset store file failed, please check whether " "offsets.Json is cleared by operator, if so, delete " "this offsets.Json file and then restart consumer", -1); } } else {
int DataProcessHelper::CallHandleFunction(map<string,string> mapped_v) { connectMysql mq(mapped_v); if(mapped_v["DML_type"] == "1") mq.Insert(mapped_v); else if(mapped_v["DML_type"] == "2") mq.Update(mapped_v); else if(mapped_v["DML_type"] == "3") mq.Delete(mapped_v); else mq.Replace(mapped_v); }
// usage: WavePlayer [options] [file1 [file2 ... [fileN]]] // v# - volume (0-100) // i# - device index (0 - default) // l - loop (stop playing when closed) int main(int argc, char **argv) { AnchorBlock ab; MessageQueue mq(ab); HWND hwndFrame = NULLHANDLE; HWND hwndClient = NULLHANDLE; FRAMECDATA fcd; PSZ pszClientClass = NULL; PSZ pszTitle = NULL; QMSG qmsg; pbcRegisterClass(); PINITDATA pinitdata = new INITDATA; memset(pinitdata, 0, sizeof(INITDATA)); pinitdata->cbSize = sizeof(INITDATA); pinitdata->argc = argc; pinitdata->argv = argv; fcd.cb = sizeof(fcd); fcd.flCreateFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_MINMAX | FCF_SIZEBORDER | FCF_ICON | FCF_SHELLPOSITION | FCF_TASKLIST; fcd.hmodResources = NULLHANDLE; fcd.idResources = WIN_MAIN; pszClientClass = new char[128]; WinLoadString(ab, (HMODULE)NULLHANDLE, IDS_CLIENTCLASSNAME, 128, pszTitle); WinRegisterClass(ab, pszClientClass, MainWndProc, CS_SIZEREDRAW, QW_EXTRA); pszTitle = new char[128]; WinLoadString(ab, (HMODULE)NULLHANDLE, IDS_APPNAME, 128, pszTitle); hwndFrame = WinCreateWindow(HWND_DESKTOP, WC_FRAME, pszTitle, WS_ANIMATE, 0, 0, 0, 0, (HWND)NULLHANDLE, HWND_TOP, WIN_MAIN, (PVOID)&fcd, (PVOID)NULL); hwndClient = WinCreateWindow(hwndFrame, pszClientClass, (PSZ)NULL, 0, 0, 0, 0, 0, hwndFrame, HWND_TOP, FID_CLIENT, (PVOID)pinitdata, (PVOID)NULL); delete pszClientClass; delete pszTitle; if(hwndFrame == NULLHANDLE || hwndClient == NULLHANDLE) return 1; while(WinGetMsg(ab, &qmsg, NULL, NULL, NULL)) WinDispatchMsg(ab, &qmsg); WinDestroyWindow(hwndFrame); return 0; }
//************************************************************************************************ // The not so mighty ShutdownThread //************************************************************************************************ void _Optlink ShutdownThread(void *pArg) { HWND hWnd = (HWND)pArg; AnchorBlock ab; MessageQueue mq(ab); ULONG ulError = 0; MCI_STATUS_PARMS msp; MCI_GENERIC_PARMS mciGenericParms; USHORT usDeviceID = WinQueryWindowUShort(hWnd, QWS_DEVICEID); //********************************************************************************************* // Set the lowest posible priority to make us systemfriendly //********************************************************************************************* DosSetPriority(PRTYS_THREAD, PRTYC_IDLETIME, PRTYD_MINIMUM, 0); //********************************************************************************************* // Store windowpositoin //********************************************************************************************* SWP swp; WinQueryWindowPos(WinQueryWindow(hWnd, QW_PARENT), &swp); PrfWriteProfileData(HINI_USERPROFILE, "WavePlayer", "WindowPosition", (PVOID)&swp, sizeof(swp)); memset((void*)&msp, 0, sizeof(msp)); msp.ulItem = MCI_STATUS_MODE; ulError = mciSendCommand(usDeviceID, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, (PVOID)&msp, (USHORT)0); mciGenericParms.hwndCallback = NULL; if(msp.ulReturn == MCI_MODE_PLAY) mciSendCommand(usDeviceID, MCI_STOP, MCI_WAIT, (PVOID)&mciGenericParms, NULL); mciSendCommand(usDeviceID, MCI_CLOSE, MCI_WAIT, (PVOID)&mciGenericParms, (USHORT)0); plNuke(hWnd); WinPostMsg(hWnd, WM_QUIT, NULL, NULL); _endthread(); }
bool is_running() { #ifdef _DEBUG boost::interprocess::message_queue::remove(k_msg_queue_name); #endif try { boost::interprocess::message_queue mq( boost::interprocess::create_only, k_msg_queue_name, 1, sizeof(int)); } catch (boost::interprocess::interprocess_exception &/*ex*/) { //printf("%s\n", ex.what()); return true; } return false; }
int main(int argc, const char** argv) { // Check arguments. if ((argc < 3) || (argc > 4)) { usage(argv[0]); return -1; } bool sender; if (strcasecmp(argv[2], "sender") == 0) { sender = true; } else if (strcasecmp(argv[2], "receiver") == 0) { sender = false; } else { usage(argv[0]); return -1; } int timeout; if (argc == 4) { timeout = atoi(argv[3]); } else { timeout = kDefaultTimeout; } // Open/create message queue. ipc::message_queue mq(!sender); if (!mq.open(argv[1], kMaxMessages, kMaxMessageSize)) { fprintf(stderr, "Couldn't open queue (%s).\n", argv[1]); return -1; } pid_t pid = getpid(); // Install signal handlers. struct sigaction act; sigemptyset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = signal_handler; sigaction(SIGINT, &act, NULL); sigaction(SIGQUIT, &act, NULL); sigaction(SIGTERM, &act, NULL); running = true; if (sender) { // Send messages. for (unsigned i = 0; (running) && (i < kNumberMessages); i++) { char msg[64]; size_t len = snprintf(msg, sizeof(msg), "msg-%u-%04u", pid, i); // Send message. if (!mq.send(msg, len, timeout)) { fprintf(stderr, "Error sending message [%s].\n", msg); return -1; } printf("Sent message: [%s].\n", msg); } } else { // Receive messages. do { // Receive message. char msg[kMaxMessageSize + 1]; ssize_t ret; if ((ret = mq.recv(msg, sizeof(msg), timeout)) <= 0) { break; } printf("Received message: [%.*s].\n", static_cast<int>(ret), msg); } while (running); } return 0; }
int main(int argc, char** argv) { BinarySerializer bs; Point<double> p(2); p.mX[0] = 1; p.mX[1] = 2; bs << p; MultiPoint<double> mp(2,2); mp.mParam.mX[0] = 1; mp.mParam.mX[1] = 2; mp.mCrit.mX[0] = 3; mp.mCrit.mX[1] = 4; bs << mp; Point<double> q(2); bs.reset(); bs >> q; //rintf("%s\n", q.toString().c_str()); BNB_ASSERT((p.mX[0] == q.mX[0]) && (p.mX[1] == q.mX[1])); MultiPoint<double> mq(2,2); bs >> mq; //printf("%s\n", mq.toString().c_str()); BNB_ASSERT((mp.mParam.mX[0] == mq.mParam.mX[0]) && (mp.mParam.mX[1] == mq.mParam.mX[1])); BNB_ASSERT((mp.mCrit.mX[0] == mq.mCrit.mX[0]) && (mp.mCrit.mX[1] == mq.mCrit.mX[1])); MultiPoint<double> mp1(2,3); mp1.mParam.mX[0] = 0; mp1.mParam.mX[1] = 1; mp1.mCrit.mX[0] = 3; mp1.mCrit.mX[1] = 4; mp1.mCrit.mX[2] = 5; MultiPoint<double> mp2(2,3); mp2.mParam.mX[0] = 10; mp2.mParam.mX[1] = 11; mp2.mCrit.mX[0] = 5; mp2.mCrit.mX[1] = 4; mp2.mCrit.mX[2] = 3; MPSimpBag<double> mpsbag; mpsbag.put(mp1); mpsbag.put(mp2); bs.reset(); bs << mpsbag; bs.reset(); MPSimpBag<double> mpsbagn; bs >> mpsbagn; //printf("%s\n", mpsbagn.toString().c_str()); BNB_ASSERT(mpsbagn.size() == 2); bs.reset(); Box<double> bx1(2); bx1.mA[0] = 1; bx1.mA[1] = 2; bx1.mB[0] = 3; bx1.mB[1] = 4; bs << bx1; Box<double> bx2(2); bs.reset(); bs >> bx2; //printf("%s\n", BoxUtils::toString(bx2).c_str()); BNB_ASSERT(bx1.mA[0] == bx2.mA[0]); BNB_ASSERT(bx1.mA[1] == bx2.mA[1]); BNB_ASSERT(bx1.mB[0] == bx2.mB[0]); BNB_ASSERT(bx1.mB[1] == bx2.mB[1]); SimpBoxBag<double> sb; sb.put(bx1); sb.put(bx2); bs.reset(); bs << sb; bs.reset(); SimpBoxBag<double> sb1; bs >> sb1; //printf("sb1: %s\n", sb1.toString().c_str()); BNB_ASSERT(sb1.size() == 2); return 0; }
int main(int argc, char *argv[]) { // Do this early as we don't want to bother initializing if we are just calling IPC for (int i = 1; i < argc; i++) { if (strlen(argv[i]) > 7 && strncasecmp(argv[i], "bitcoin:", 8) == 0) { const char *strURL = argv[i]; try { boost::interprocess::message_queue mq(boost::interprocess::open_only, "BitcoinURL"); if(mq.try_send(strURL, strlen(strURL), 0)) exit(0); else break; } catch (boost::interprocess::interprocess_exception &ex) { break; } } } // Internal string conversion is all UTF-8 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForTr()); Q_INIT_RESOURCE(bitcoin); QApplication app(argc, argv); ParseParameters(argc, argv); // Get desired locale ("en_US") from command line or system locale QString lang_territory = QString::fromStdString(GetArg("-lang", QLocale::system().name().toStdString())); // Load language files for configured locale: // - First load the translator for the base language, without territory // - Then load the more specific locale translator QString lang = lang_territory; lang.truncate(lang_territory.lastIndexOf('_')); // "en" QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator; qtTranslatorBase.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang); if (!qtTranslatorBase.isEmpty()) app.installTranslator(&qtTranslatorBase); qtTranslator.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang_territory); if (!qtTranslator.isEmpty()) app.installTranslator(&qtTranslator); translatorBase.load(":/translations/"+lang); if (!translatorBase.isEmpty()) app.installTranslator(&translatorBase); translator.load(":/translations/"+lang_territory); if (!translator.isEmpty()) app.installTranslator(&translator); app.setApplicationName(QApplication::translate("main", "Bitcoin-Qt")); QSplashScreen splash(QPixmap(":/images/splash"), 0); splash.show(); splash.setAutoFillBackground(true); splashref = &splash; app.processEvents(); app.setQuitOnLastWindowClosed(false); try { if(AppInit2(argc, argv)) { { // Put this in a block, so that BitcoinGUI is cleaned up properly before // calling Shutdown() in case of exceptions. BitcoinGUI window; splash.finish(&window); OptionsModel optionsModel(pwalletMain); ClientModel clientModel(&optionsModel); WalletModel walletModel(pwalletMain, &optionsModel); guiref = &window; window.setClientModel(&clientModel); window.setWalletModel(&walletModel); // If -min option passed, start window minimized. if(GetBoolArg("-min")) { window.showMinimized(); } else { window.show(); } // Place this here as guiref has to be defined if we dont want to lose URLs ipcInit(); // Check for URL in argv for (int i = 1; i < argc; i++) { if (strlen(argv[i]) > 7 && strncasecmp(argv[i], "bitcoin:", 8) == 0) { const char *strURL = argv[i]; try { boost::interprocess::message_queue mq(boost::interprocess::open_only, "BitcoinURL"); mq.try_send(strURL, strlen(strURL), 0); } catch (boost::interprocess::interprocess_exception &ex) { } } } app.exec(); guiref = 0; } Shutdown(NULL); } else { return 1; } } catch (std::exception& e) { PrintException(&e, "Runaway exception"); } catch (...) { PrintException(NULL, "Runaway exception"); } return 0; }
void SetMQListData () { DEFINE_QUERY (qry); int i = 0; char sTemp[100]; /* char tmp[256] = {0}; if( g_iflowid ) sprintf(tmp,"and billflow_id = %d \0",g_iflowid); else strcpy(tmp," "); */ /* 设置控件中的内容 */ Control *pEdit = GetCtlByID(msgqueue_handle, 13); gStr2Arr(pEdit->sData); qry.close (); char tmp[256] = {0}; char sql[1024] = {0}; char sysuser[32] = {0}; sprintf( sysuser,"'%s'\0",getenv("LOGNAME") ); gArr2Str(tmp); if(!strlen(tmp)) strcpy(tmp,"0\0"); sprintf(sql,g_sMQListSql,tmp,g_iflowid[0],sysuser, IpcKeyMgr::getHostInfo(sTemp)); qry.setSQL (sql); // qry.setParameter ("bflowid",g_iflowid); qry.open (); while (qry.next ()) { g_tMQList[i].iFlowID = qry.field (0).asInteger(); g_tMQList[i].iProcessID = qry.field(1).asInteger(); strncpy (g_tMQList[i].sProcName, qry.field(5).asString(), PROCESS_NAME_LEN); g_tMQList[i].iMQID = qry.field(3).asInteger(); g_tMQList[i].iMaxMsgNum = qry.field(4).asInteger(); g_tMQList[i].iVpID=qry.field(6).asInteger(); msg_list_index[i] = msg_list_data[i]; i++; } qry.commit(); qry.close(); /* 设置控件中条目的数量 */ Control *pList = GetCtlByID (msgqueue_handle, 6); pList->iAdditional = g_iMQListCount = i; /* CommandCom *m_pCmdCom = NULL; m_pCmdCom = new CommandCom(); m_pCmdCom->InitClient(); int iPercent=0; int iQueueSize=1000; char sTemp2[20]={0}; */ for (i=0; i<g_iMQListCount; i++) { MessageQueue mq(g_tMQList[i].iMQID); if (!mq.exist ()) { strcpy (g_tMQList[i].sState, "----"); } else { strcpy (g_tMQList[i].sState, "存在"); } /* if(g_tMQList[i].iVpID>=1) { memset(sTemp2,0,sizeof(sTemp2)); sprintf(sTemp2,"vp%d_queue_size",g_tMQList[i].iVpID/1000); iQueueSize = m_pCmdCom->readIniInteger ("SCHEDULE", sTemp2, 0); //队列长度 if(iQueueSize>0){ iPercent=mq.getMessageNumber()*100/iQueueSize; }else{ iPercent=mq.getOccurPercent(); } }else{ iPercent=mq.getOccurPercent(); } */ sprintf (msg_list_data[i], "%-4d %6d %-20s %8d%9s%5d%5d%%", g_tMQList[i].iFlowID, g_tMQList[i].iProcessID, g_tMQList[i].sProcName, g_tMQList[i].iMQID, g_tMQList[i].sState, mq.getMessageNumber (), //iPercent mq.getOccurPercent() ); /* sprintf (msg_list_data[i], "%-4d %6d %-20s %8d%9s%5d%", g_tMQList[i].iFlowID, g_tMQList[i].iProcessID, g_tMQList[i].sProcName, g_tMQList[i].iMQID, g_tMQList[i].sState, mq.getMessageNumber () // mq.getOccurPercent() ); */ } pList->pData = msg_list_index; /* if(m_pCmdCom) { delete m_pCmdCom; m_pCmdCom=NULL; } */ }
//************************************************************************************************ // The allmighty StartupThread //************************************************************************************************ void _Optlink StartupThread(void *pArg) { AnchorBlock ab; MessageQueue mq(ab); PINITDATA pinit = (PINITDATA)pArg; int i; USHORT usDeviceIndex = 0; // default use default deviceindex USHORT usVolume = 75; // default 75% volume ULONG ulError = 0; // mci error MCI_OPEN_PARMS mciOpenParms; BOOL fDeviceOpen = FALSE; //********************************************************************************************* // Set the lowest posible priority to make us systemfriendly //********************************************************************************************* DosSetPriority(PRTYS_THREAD, PRTYC_IDLETIME, PRTYD_MINIMUM, 0); //********************************************************************************************* // Clear some evetual garbage, just in case.... //********************************************************************************************* WinSetWindowPtr(pinit->hWnd, QWP_PLAYLIST, NULL); WinSetWindowPtr(pinit->hWnd, QWP_CURRENTENTRY, NULL); WinSetWindowULong(pinit->hWnd, QWL_PLAYLISTENTRIES, 0); WinSetWindowUShort(pinit->hWnd, QWS_DEVICEID, 0); WinSetWindowULong(pinit->hWnd, QWL_LOOP, 0); // do not loop by default //********************************************************************************************* // Parse the commandline //********************************************************************************************* for(i = 1; i < pinit->argc; i++) { switch(pinit->argv[i][0]) { case '/': case '-': switch(pinit->argv[i][1]) { case 'i': case 'I': usDeviceIndex = (USHORT)atoi(&pinit->argv[i][2]); break; case 'l': case 'L': WinSetWindowULong(pinit->hWnd, QWL_LOOP, 1); break; case 'v': case 'V': usVolume = (USHORT)atoi(&pinit->argv[i][2]); break; } break; default: AddToPlaylist(pinit->hWnd, pinit->argv[i]); break; } } // make sure we're at the first entry of the playlist WinSetWindowPtr(pinit->hWnd, QWP_CURRENTENTRY, WinQueryWindowPtr(pinit->hWnd, QWP_PLAYLIST)); //********************************************************************************************* // open the waveaudio device //********************************************************************************************* memset((void*)&mciOpenParms, 0, sizeof(mciOpenParms)); mciOpenParms.pszDeviceType = (PSZ)MAKEULONG(MCI_DEVTYPE_WAVEFORM_AUDIO, usDeviceIndex); ulError = mciSendCommand((USHORT)0, MCI_OPEN, MCI_WAIT | MCI_OPEN_TYPE_ID, (PVOID)&mciOpenParms, 0); if(LOUSHORT(ulError) == MCIERR_SUCCESS) { fDeviceOpen = TRUE; WinSetWindowUShort(pinit->hWnd, QWS_DEVICEID, mciOpenParms.usDeviceID); } if((fDeviceOpen == TRUE) && (WinQueryWindowULong(pinit->hWnd, QWL_PLAYLISTENTRIES) != 0)) { MCI_SET_PARMS msp; msp.ulLevel = usVolume; msp.ulAudio = MCI_SET_AUDIO_ALL; ulError = mciSendCommand(mciOpenParms.usDeviceID, MCI_SET, MCI_WAIT | MCI_SET_AUDIO | MCI_SET_VOLUME, (PVOID)&msp, 0); if(LOUSHORT(ulError) == MCIERR_SUCCESS) { WinSendMsg(WinWindowFromID(pinit->hWnd, SLRD_VOLUME), SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), MPFROMSHORT(usVolume)); WinEnableWindow(WinWindowFromID(pinit->hWnd, SLRD_VOLUME), TRUE); } if((BOOL)WinSendMsg(pinit->hWnd, WMU_LOAD, NULL, NULL)) { WinSendMsg(pinit->hWnd, WMU_PLAY, NULL, NULL); } } //********************************************************************************************* // free the initdata buffer //********************************************************************************************* delete pinit; // show the window SWP swp; ULONG pulBufferMax = sizeof(swp); if(PrfQueryProfileData(HINI_USERPROFILE, "WavePlayer", "WindowPosition", (PVOID)&swp, &pulBufferMax)) WinSetWindowPos(WinQueryWindow(pinit->hWnd, QW_PARENT), HWND_TOP, swp.x, swp.y, swp.cx, swp.cy, SWP_SHOW | SWP_MOVE | SWP_SIZE); else WinShowWindow(WinQueryWindow(pinit->hWnd, QW_PARENT), TRUE); // bye, bye! _endthread(); }
int main(int argc, char *argv[]) { // Do this early as we don't want to bother initializing if we are just calling IPC for (int i = 1; i < argc; i++) { if (strlen(argv[i]) > 8 && strncasecmp(argv[i], "bitshekel:", 9) == 0) { const char *strURL = argv[i]; try { boost::interprocess::message_queue mq(boost::interprocess::open_only, "BitcoinURL"); if(mq.try_send(strURL, strlen(strURL), 0)) exit(0); else break; } catch (boost::interprocess::interprocess_exception &ex) { break; } } } // Internal string conversion is all UTF-8 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForTr()); Q_INIT_RESOURCE(bitcoin); QApplication app(argc, argv); // Command-line options take precedence: ParseParameters(argc, argv); // ... then bitcoin.conf: if (!ReadConfigFile(mapArgs, mapMultiArgs)) { fprintf(stderr, "Error: Specified directory does not exist\n"); return 1; } // Application identification (must be set before OptionsModel is initialized, // as it is used to locate QSettings) app.setOrganizationName("Bitcoin"); app.setOrganizationDomain("bitcoin.org"); if(GetBoolArg("-testnet")) // Separate UI settings for testnet app.setApplicationName("Bitshekel-Qt-testnet"); else app.setApplicationName("Bitshekel-Qt"); // ... then GUI settings: OptionsModel optionsModel; // Get desired locale ("en_US") from command line or system locale QString lang_territory = QString::fromStdString(GetArg("-lang", QLocale::system().name().toStdString())); // Load language files for configured locale: // - First load the translator for the base language, without territory // - Then load the more specific locale translator QString lang = lang_territory; lang.truncate(lang_territory.lastIndexOf('_')); // "en" QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator; qtTranslatorBase.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang); if (!qtTranslatorBase.isEmpty()) app.installTranslator(&qtTranslatorBase); qtTranslator.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang_territory); if (!qtTranslator.isEmpty()) app.installTranslator(&qtTranslator); translatorBase.load(":/translations/"+lang); if (!translatorBase.isEmpty()) app.installTranslator(&translatorBase); translator.load(":/translations/"+lang_territory); if (!translator.isEmpty()) app.installTranslator(&translator); QSplashScreen splash(QPixmap(":/images/splash"), 0); if (GetBoolArg("-splash", true) && !GetBoolArg("-min")) { splash.show(); splash.setAutoFillBackground(true); splashref = &splash; } app.processEvents(); app.setQuitOnLastWindowClosed(false); try { if(AppInit2(argc, argv)) { { // Put this in a block, so that BitcoinGUI is cleaned up properly before // calling Shutdown() in case of exceptions. optionsModel.Upgrade(); // Must be done after AppInit2 BitcoinGUI window; if (splashref) splash.finish(&window); ClientModel clientModel(&optionsModel); WalletModel walletModel(pwalletMain, &optionsModel); guiref = &window; window.setClientModel(&clientModel); window.setWalletModel(&walletModel); // If -min option passed, start window minimized. if(GetBoolArg("-min")) { window.showMinimized(); } else { window.show(); } // Place this here as guiref has to be defined if we dont want to lose URLs ipcInit(); // Check for URL in argv for (int i = 1; i < argc; i++) { if (strlen(argv[i]) > 8 && strncasecmp(argv[i], "bitshekel:", 9) == 0) { const char *strURL = argv[i]; try { boost::interprocess::message_queue mq(boost::interprocess::open_only, "BitcoinURL"); mq.try_send(strURL, strlen(strURL), 0); } catch (boost::interprocess::interprocess_exception &ex) { } } } app.exec(); guiref = 0; } Shutdown(NULL); } else { return 1; } } catch (std::exception& e) { handleRunawayException(&e); } catch (...) { handleRunawayException(NULL); } return 0; }
//计算通道的状态 int Channel::calcWater(int iVpID) { //找到通道任务数,下游最大任务数,下游VPID if(iVpID < 0) return 0; int iMessageNum = 0; int iPercent = 0; for (int i=0; i<m_pInfoHead->iProcNum; i++) //遍历所有进程 { if(iVpID == (m_pProcInfoHead+i)->iVpID) //查找 { if((m_pProcInfoHead+i)->iMqID > 0) { MessageQueue mq( (m_pProcInfoHead+i)->iMqID); if(mq.exist()) { iMessageNum = mq.getMessageNumber(); } else iMessageNum = 0; } else { iMessageNum = 0; } break; } } int iLowLevel = 0; int iHighLevel = 0; int iQueueSize = 0; //从核心参数中读取本通道的配置 int iState; char sTemp[100] = {0}; memset(sTemp,0,100); int iTemp = iVpID/1000; sprintf(sTemp,"vp%d.process_high_level",iTemp); iHighLevel = Channel::m_pCmdCom->readIniInteger ("SCHEDULE", sTemp, 100);//高水值 memset(sTemp,0,100); sprintf(sTemp,"vp%d.process_low_level",iTemp); iLowLevel = Channel::m_pCmdCom->readIniInteger ("SCHEDULE", sTemp, 0); //低水值 memset(sTemp,0,100); sprintf(sTemp,"vp%d.queue_size",iTemp); iQueueSize = Channel::m_pCmdCom->readIniInteger ("SCHEDULE", sTemp, 0); //队列长度 //int iRet = CalcState( iVpID, iTaskNum); if(iQueueSize > 0) iPercent = iMessageNum*100/iQueueSize; if(iPercent >= iHighLevel) iState = CHANNEL_HIGH; else if(iPercent <= iLowLevel) iState = CHANNEL_LOW; else iState = CHANNEL_NOMAL; if(iPercent == 0) iState = CHANNEL_EMPTY; if(iPercent >= 100) { iPercent = 100; iState = CHANNEL_FULL; } //根据拥塞情况启停指定模块 int iBlockLevel = 0; int iScheduleBlockVP = 0; iBlockLevel = Channel::m_pCmdCom->readIniInteger ("SCHEDULE", "schedule_block_level", 0); //拥塞级别 iScheduleBlockVP = Channel::m_pCmdCom->readIniInteger ("SCHEDULE", "schedule_block_vp", 0); //拥塞相关vp if( iScheduleBlockVP == iVpID / 1000 ) { if (iBlockLevel > 0) { iState = CHANNEL_HIGH; } } return iState; }
int main(int argc, char *argv[]) { int i; char c; char buf[2048]; int l; MessageQueue mq(10220); if (!mq) { cout << "Error1" << endl; return 0; } try { mq.open(false, true); } catch (Exception &e) { cout << e.descript() << endl; return 0; } catch (...) { cout << "xxx" << endl; } while (1) { cout << "1 Send Message\n2 Recv Message" << endl; cin >> i; if (i == 1) { l = 0; while (1) { cin >> c; if (c != '0') { buf[l] = c; l++; } else { buf[l] = 0; cout << "sending:" << buf << endl; try { if (mq.send(buf, l) != l) cout << "Error Send" << endl; else cout << "Success Send" << endl; } catch (Exception e) { cout << e.descript() << endl; } break; } } } else if (i == 2)