void IPlugVST::GetTime(ITimeInfo* pTimeInfo) { VstTimeInfo* pTI = GetTimeInfo(mHostCallback, &mAEffect, kVstPpqPosValid | kVstTempoValid | kVstBarsValid | kVstCyclePosValid | kVstTimeSigValid ); if (pTI) { pTimeInfo->mSamplePos = pTI->samplePos; if ((pTI->flags & kVstPpqPosValid) && pTI->ppqPos >= 0.0) pTimeInfo->mPPQPos = pTI->ppqPos; if ((pTI->flags & kVstTempoValid) && pTI->tempo > 0.0) pTimeInfo->mTempo = pTI->tempo; if ((pTI->flags & kVstBarsValid) && pTI->barStartPos >= 0.0) pTimeInfo->mLastBar = pTI->barStartPos; if ((pTI->flags & kVstCyclePosValid) && pTI->cycleStartPos >= 0.0 && pTI->cycleEndPos >= 0.0) { pTimeInfo->mCycleStart = pTI->cycleStartPos; pTimeInfo->mCycleEnd = pTI->cycleEndPos; } if ((pTI->flags & kVstTimeSigValid) && pTI->timeSigNumerator > 0.0 && pTI->timeSigDenominator > 0.0) { pTimeInfo->mNumerator = pTI->timeSigNumerator; pTimeInfo->mDenominator = pTI->timeSigDenominator; } pTimeInfo->mTransportIsRunning = pTI->flags & kVstTransportPlaying; pTimeInfo->mTransportLoopEnabled = pTI->flags & kVstTransportCycleActive; } }
static int premia_interactive_menu( Planning *pt_plan, Model **models, Family **families, Pricing **pricings, int user) { Model* pt_model; Option* pt_option; Pricing* pt_pricing; PricingMethod* pt_method; DynamicTest* pt_test; PricingMethod* pt_methods_available[MAX_METHODS]; if (OutputFile(&out_stream)!=OK) return WRONG; if (SelectModel(user,pt_plan,models,families,pricings,&pt_model)!=OK) return WRONG; if (SelectOption(user,pt_plan,families,pt_model,pricings,&pt_option)!=OK) return WRONG; if (SelectPricing(user,pt_model,pt_option,pricings,&pt_pricing)!=OK) return WRONG; while(1){ if (SelectMethod(user,pt_plan,pt_pricing,pt_option,pt_model,&pt_method)!=OK) return FAIL; if (SelectTest(user,pt_plan,pt_pricing,pt_option,pt_model,pt_method,&pt_test)!=OK) return FAIL; if (GetTimeInfo(user,pt_plan,&computation_time_info)!=OK) return FAIL; if ((pt_plan->Action=='p')|| (( pt_plan->Action=='t')&& (GetTest(user,pt_plan,pt_pricing,pt_option,pt_test)==OK))){ (void)ShowPlanning(NAMEONLYTOFILE,pt_plan); (void)Action(pt_model,pt_option,pt_pricing, pt_method,pt_test,NAMEONLYTOFILE,pt_plan,&computation_time_info); Fprintf(TOSCREEN,"\nComputing...\n"); Iterate(pt_plan,&(pt_plan->Par[0]),0,pt_plan->Action,pt_model,pt_option, pt_pricing,pt_method,pt_test,TOFILE,&computation_time_info); pt_methods_available[pt_plan->NumberOfMethods]=pt_method; if (pt_plan->Action=='t' || MoreAction(&(pt_plan->NumberOfMethods))==FAIL) break; else free_premia_method(pt_method); } } fclose(out_stream); if ((pt_plan->Action=='p') && (pt_plan->VarNumber>0)) (void)BuildGnuStuff(pt_plan,pt_model,pt_option,pt_pricing,pt_methods_available); if (pt_plan->Action=='t') { (void)FreeTest(pt_test); (void)BuildGnuStuffTest(pt_model,pt_option,pt_pricing,pt_method,pt_test); } free_premia_model(pt_model); free_premia_option(pt_option); free_premia_method(pt_method); return OK; }
int IPlugVST::GetSamplePos() { VstTimeInfo* pTI = GetTimeInfo(mHostCallback, &mAEffect); if (pTI && pTI->samplePos >= 0.0) { return int(pTI->samplePos + 0.5); } return 0; }
void IPlugVST::GetTimeSig(int* pNum, int* pDenom) { *pNum = *pDenom = 0; VstTimeInfo* pTI = GetTimeInfo(mHostCallback, &mAEffect, kVstTimeSigValid); if (pTI && pTI->timeSigNumerator >= 0.0 && pTI->timeSigDenominator >= 0.0) { *pNum = pTI->timeSigNumerator; *pDenom = pTI->timeSigDenominator; } }
double IPlugVST::GetTempo() { if (mHostCallback) { VstTimeInfo* pTI = GetTimeInfo(mHostCallback, &mAEffect, kVstTempoValid); if (pTI && pTI->tempo >= 0.0) { return pTI->tempo; } } return 0.0; }
static void* AcceptSockets(void*) // accepts incoming connections from users { try { while(1) { char* time = GetTimeInfo()+SKIPWEEKDAY; TCPSocket *sock = serverSocket->accept(); LaunchClient((void*)sock); } } catch (SocketException &e) {printf("accept busy\r\n"); ReportBug("***Accept busy\r\n");} exit(1); return NULL; }
/* * Check for old archive (m_time older than dt) */ int check_old(char *name, time_t dt) { struct stat st; TIMEINFO ti; time_t t; GetTimeInfo(&ti); t = ti.time; if(stat(name, &st) == -1) return ERROR; return t - st.st_mtime > dt; }
/* * Read packet header from file */ int pkt_get_hdr(FILE *fp, Packet *pkt) { long val; struct tm t; int ozone, dzone; int cw, swap; int retVal; char xpkt[4]; struct tm *tm; TIMEINFO ti; retVal = OK; GetTimeInfo(&ti); tm = localtime(&ti.time); node_clear(&pkt->from); node_clear(&pkt->to); pkt->time = -1; pkt->baud = 0; pkt->version = 0; pkt->product_l = 0; pkt->product_h = 0; pkt->rev_min = 0; pkt->rev_maj = 0; pkt->passwd[0] = 0; pkt->capword = 0; /* Set zone to default, i.e. use the zone from your FIRST aka * specified in fidogate.conf */ pkt->from.zone = pkt->to.zone = cf_defzone(); /* Orig node */ if((val = pkt_get_int16(fp)) == ERROR) return ERROR; pkt->from.node = val; /* Dest node */ if((val = pkt_get_int16(fp)) == ERROR) return ERROR; pkt->to.node = val; /* Year */ if((val = pkt_get_int16(fp)) == ERROR) return ERROR; if(val == 0 || val < 1900 || val > 2099) #ifdef FIX_BAD_PKT_YEAR ; #else retVal = ERROR; #endif else
static bool GetParameterInfo(Cursor* cur, Py_ssize_t index, PyObject* param, ParamInfo& info) { // Determines the type of SQL parameter that will be used for this parameter based on the Python data type. // // Populates `info`. // TODO: if the param is a SQLParameter object, then bind to the wrapped value and use the input/output type from that // Hold a reference to param until info is freed, because info will often be holding data borrowed from param. if (PyObject_TypeCheck(param, (PyTypeObject*)SQLParameter_type)) { info.pParam = ((SQLParameter*)param)->value; info.InputOutputType = ((SQLParameter*)param)->type; } else { info.pParam = param; info.InputOutputType = SQL_PARAM_INPUT; } if (info.pParam == Py_None) return GetNullInfo(cur, index, info); if (info.pParam == null_binary) return GetNullBinaryInfo(cur, index, info); if (PyBytes_Check(info.pParam)) return GetBytesInfo(cur, index, info.pParam, info); if (PyUnicode_Check(info.pParam)) return GetUnicodeInfo(cur, index, info.pParam, info); if (PyBool_Check(info.pParam)) return GetBooleanInfo(cur, index, info.pParam, info); if (PyDateTime_Check(info.pParam)) return GetDateTimeInfo(cur, index, info.pParam, info); if (PyDate_Check(info.pParam)) return GetDateInfo(cur, index, info.pParam, info); if (PyTime_Check(info.pParam)) return GetTimeInfo(cur, index, info.pParam, info); if (PyLong_Check(info.pParam)) return GetLongInfo(cur, index, info.pParam, info); if (PyFloat_Check(info.pParam)) return GetFloatInfo(cur, index, info.pParam, info); if (PyDecimal_Check(info.pParam)) return GetDecimalInfo(cur, index, info.pParam, info); #if PY_VERSION_HEX >= 0x02060000 if (PyByteArray_Check(info.pParam)) return GetByteArrayInfo(cur, index, info.pParam, info); #endif #if PY_MAJOR_VERSION < 3 if (PyInt_Check(info.pParam)) return GetIntInfo(cur, index, info.pParam, info); if (PyBuffer_Check(info.pParam)) return GetBufferInfo(cur, index, info.pParam, info); #endif RaiseErrorV("HY105", ProgrammingError, "Invalid parameter type. param-index=%zd param-type=%s", index, Py_TYPE(info.pParam)->tp_name); return false; }
static void* HandleTCPClient(void *sock1) // individual client, data on STACK... might overflow... { clock_t starttime = ElapsedMilliseconds(); char* memory = (char*) malloc(2*SERVERTRANSERSIZE+2); // our data in 1st chunk, his reply info in 2nd if (!memory) return NULL; // ignore him if we run out of memory char* output = memory+SERVERTRANSERSIZE; *output = 0; char* buffer; TCPSocket *sock = (TCPSocket*) sock1; char IP[20]; try { strcpy(memory,sock->getForeignAddress().c_str()); // get IP address strcpy(IP,memory); buffer = memory + strlen(memory) + 1; // use this space after IP for messaging } catch (SocketException e) { ReportBug("Socket errx"); cerr << "Unable to get port" << endl; return Done(sock,memory); } char timeout = ' '; char userName[500]; *userName = 0; char* user; char* bot; char* msg; char* prior = ""; // A user name with a . in front of it means tie it with IP address so it remains unique try{ unsigned int len = sock->recv(buffer, SERVERTRANSERSIZE-50); // leave ip address in front alone memset(buffer+len,0,3); user = buffer; bot = user + strlen(user) + 1; msg = bot + strlen(bot) + 1; if (!*user) { if (*bot == '1' && bot[1] == 0) // echo test to prove server running (generates no log traces) { strcpy(output,"1"); return Done(sock,memory); } ReportBug("%s %s bot: %s msg: %s NO USER ID \r\n",IP,GetTimeInfo()+SKIPWEEKDAY,bot,msg); strcpy(output,"[you have no user id]\r\n"); return Done(sock,memory); } if (Blacklisted(memory,user)) // if he is blacklisted, we ignore him { PartialLogin(user,memory); // sets LOG file so we record his messages Log(SERVERLOG,"%s %s/%s %s msg: %s BLOCKED \r\n",IP,user,bot,GetTimeInfo()+SKIPWEEKDAY,msg); strcpy(output,"[ignoring you.]\r\n"); // response is JUST this Log(STDUSERLOG,"blocked %s => %s\r\n",msg,output); return Done(sock,memory); } strcpy(userName,user); // wait to get attention of chatbot server, timeout if doesnt come soon enough bool ready = ClientGetChatLock( ANSWERTIMELIMIT - (ElapsedMilliseconds() - starttime) ); // chatlock ... if (!ready) // if it takes to long waiting to get server attn, give up { PartialLogin(userName,memory); // sets LOG file so we record his messages switch(random(4)) { case 0: strcpy(output,"Hey, sorry. Had to answer the phone. What was I saying?"); break; case 1: strcpy(output,"Hey, sorry. There was a salesman at the door. Where were we?"); break; case 2: strcpy(output,"Hey, sorry. Got distracted. What did you say?"); break; case 3: strcpy(output,"Hey, sorry. What did you say?"); break; } Log(STDUSERLOG,"Timeout waiting for service: %s => %s\r\n",msg,output); return Done(sock,memory); } } catch (...) { ReportBug("***%s client presocket failed %s\r\n",IP,GetTimeInfo()+SKIPWEEKDAY); return Done(sock,memory); } clock_t serverstarttime = ElapsedMilliseconds(); try{ chatWanted = true; // indicate we want the chatbot server - no other client can get chatLock while this is true clientBuffer = memory; int remain = ANSWERTIMELIMIT - (ElapsedMilliseconds() - starttime); if (!ClientWaitForServer(memory,msg,remain)) // release lock, loop wait for data, and maybe we give up waiting for him { timeout = '*'; switch(random(4)) { case 0: strcpy(output,"Hey, sorry. Had to answer the phone. What was I saying?"); break; case 1: strcpy(output,"Hey, sorry. There was a salesman at the door. Where were we?"); break; case 2: strcpy(output,"Hey, sorry. Got distracted. What did you say?"); break; case 3: strcpy(output,"Hey, sorry. What did you say?"); break; } } unsigned int len = strlen(output); if (len) sock->send(output, len); prior = output + len + 1; // bot prior message to us } catch (...) { printf("client socket fail\r\n"); ReportBug("***%s client socket failed %s \r\n",IP,GetTimeInfo()+SKIPWEEKDAY);} delete sock; char* date = GetTimeInfo()+SKIPWEEKDAY; date[15] = 0; // suppress year clock_t endtime = ElapsedMilliseconds(); char* prior1 = prior + strlen(prior) + 1; int volleys = atoi(prior1); if (*msg) Log(SERVERLOG,"%c %s %s/%s %s time:%d/%d v:%d msg: %s => %s <= %s\n",timeout,IP,user,bot,date, (int)(endtime - starttime),(int)(endtime - serverstarttime),volleys,msg,output,prior); else Log(SERVERLOG,"%c %s %s/%s %s start => %s <= %s\n",timeout,IP,user,bot,date,output,prior); free(memory); #ifndef WIN32 pthread_exit(0); #endif return NULL; }
bool CProtocolDemo::ChangeValue(CPointDemoBase *pPoint) { switch(pPoint->m_nFunction) { //cpu case 10://CPU 占用率 GetCPUInfo(pPoint); break; //内存 主存 虚存 case 20://物理内存总数 GetMemoryInfo(pPoint); break; case 22://物理内存空闲 GetMemoryInfo(pPoint); break; case 24://物理内存使用 GetMemoryInfo(pPoint); break; case 26://虚内存总数 GetMemoryInfo(pPoint); break; case 28://虚内存空闲 GetMemoryInfo(pPoint); break; case 30://虚内存占用 GetMemoryInfo(pPoint); break; case 32://文件页总数 GetMemoryInfo(pPoint); break; case 34://文件页空闲 GetMemoryInfo(pPoint); break; case 36://文件页占用 GetMemoryInfo(pPoint); break; case 38://内存占用率 GetMemoryInfo(pPoint); // (2) 内存使用率 // 这里需要从/proc/meminfo文件中提取两个数据,当前内存的使用量(cmem)以及内存总量(amem)。 // 内存使用百分比 = 100 * (cmem / umem) break; case 40://当前程序占用空间 GetMemoryInfo(pPoint); break; case 42://内存使用峰值 GetMemoryInfo(pPoint); break; case 44://占用的虚拟内存大小 GetMemoryInfo(pPoint); break; case 46://占用的虚拟内存峰值 GetMemoryInfo(pPoint); break; //时间 当前时间,系统启动时间,程序运行时间 case 50://windows系统已经运行时间 // fValue=GetTimeInfo(pPoint->m_nFunction); GetTimeInfo(pPoint); break; case 52://程序启动时间 秒 // fValue=GetTimeInfo(pPoint->m_nFunction); GetTimeInfo(pPoint); break; case 54://程序运行时间 秒 // fValue=GetTimeInfo(pPoint->m_nFunction); GetTimeInfo(pPoint); break; case 56://内核时间 // fValue=GetTimeInfo(pPoint->m_nFunction); // GetTimeInfo(pPoint->m_nFunction); GetTimeInfo(pPoint); break; case 58://用户时间 // fValue=GetTimeInfo(pPoint->m_nFunction); // GetTimeInfo(pPoint->m_nFunction); GetTimeInfo(pPoint); break; //磁盘空间 a b c d e f g 占用/总/空闲 case 60: // fValue=GetDiskInfo(pPoint->m_nPara1,pPoint->m_nPara2); break; //各种随机数据 case 70://常量 参数为:70 常量值 GetRand(pPoint); break; case 72://一定范围内的随机量 参数为:72 最大值 最小值 GetRand(pPoint); break; case 74://单调增加 参数为:74 初值 终值 步长(<0 为单调递减) GetRand(pPoint); break; case 76://正弦变量 参数为:76 基值 幅值 步长(角度) GetRand(pPoint); break; case 78://方波 参数为:78 高值,低值(扫描周期就是方波长度) GetRand(pPoint); break; case 80://遥信量 参数为:80 (扫描周期就是变位周期) GetRand(pPoint); break; case 82://遥信量 参数为:82每次变位的可能性(0-100) GetRand(pPoint); break; default: Q_ASSERT(false);//"未定义的取值方式\n" break; } return true; }