bool CIsa100Impl::doProcessorStats( void ) { m_systemStatus.processes.clear(); m_systemStatus.processes.push_back( ProcessStatus( "(scgi_svc)", "cgi") ); m_systemStatus.processes.push_back( ProcessStatus( "(MonitorHost)", "MonitorHost" ) ); m_systemStatus.processes.push_back( ProcessStatus( "(modbus_gw)", "MODBUS" ) ); #if defined( RELEASE_ISA ) m_systemStatus.processes.push_back( ProcessStatus( "(backbone)", "Backbone" ) ); #elif defined( RELEASE_WHART ) m_systemStatus.processes.push_back( ProcessStatus("(whaccesspoint)", "AccessPoint")); #endif #if defined( RELEASE_ISA ) m_systemStatus.processes.push_back( ProcessStatus( "(isa_gw)", "Gateway" ) ); m_systemStatus.processes.push_back( ProcessStatus( "(SystemManager)", "SystemManager" ) ); #endif #if defined( RELEASE_WHART ) m_systemStatus.processes.push_back( ProcessStatus("(WHart_GW.o)", "Gateway")); m_systemStatus.processes.push_back( ProcessStatus("(WHart_NM.o)", "NetworkManager")); #endif unsigned long long oldSysJiff = systemSnapshot( ); if( !oldSysJiff) return false; for( Processes::iterator it = m_systemStatus.processes.begin(); it != m_systemStatus.processes.end(); ++it ) { it->oldJiff = it->jiffies; it->jiffies = 0LL; } sleep(1); /// Distance between two snapshots - should be long enough unsigned long long crtSysJiff = systemSnapshot( ); unsigned long long deltaSysjiff = crtSysJiff - oldSysJiff; if ( !crtSysJiff || !deltaSysjiff ) return false; LOG("CPU delta %3llu", deltaSysjiff); Processes::iterator it = m_systemStatus.processes.begin(); while( it != m_systemStatus.processes.end() ) { sprintf( it->m_szProcessorUsage, "%.1f", (float)(100.0 * (it->jiffies - it->oldJiff) / deltaSysjiff) ); LOG("doProcessorStats: [%15s] jiff %6llu diff %3llu (%4s). Total CPU %4.1f %s", it->m_szName, it->jiffies, it->jiffies - it->oldJiff, it->m_szProcessorUsage, (float)(100.0 * it->jiffies / crtSysJiff), it->m_szStatus ); if( !strcmp( "(scgi_svc)", it->m_szName) ) it = m_systemStatus.processes.erase( it ); else ++it; } return true; }
/* This is declared as inline as there is only one call to it. */ static inline int ieee1394_Sync_withTimeout(u32 n500mSecUnits){ /* iop_sys_clock_t timeout_clk; u32 ef_result; USec2SysClock(n500mSecUnits*500000, &timeout_clk); SetAlarm(&timeout_clk, &alarm_cb, NULL); WaitEventFlag(sbp2_event_flag, WRITE_REQ_INCOMING|ERROR_TIME_OUT, WEF_OR|WEF_CLEAR, &ef_result); if(ef_result&ERROR_TIME_OUT){ XPRINTF("-=Time out=-\n"); return(-1); } else CancelAlarm(&alarm_cb, NULL); */ unsigned int i=0; while(RESP_SRC(((struct sbp2_status *)statusFIFO)->status)==0){ if(i>n500mSecUnits*10000){ XPRINTF("-=Time out=-\n"); return(-1); } DelayThread(50); i++; }; return(ProcessStatus()); }
int ieee1394_Sync(void){ // WaitEventFlag(sbp2_event_flag, WRITE_REQ_INCOMING, WEF_AND|WEF_CLEAR, NULL); while(RESP_SRC(((struct sbp2_status *)statusFIFO)->status)==0){ DelayThread(50); }; return(ProcessStatus()); }
void ZephyrXtreme::readyReadData() { char data[1024]; int n; while((n=zep_device->read(data,1024))>0) { for(int i=0;i<n;i++) { switch(data[i]) { case 13: ProcessStatus(zep_buffer); zep_buffer=""; break; case 10: break; default: zep_buffer+=data[i]; break; } } } }
void BtSs82::readyReadData() { char data[1024]; int n; while((n=bt_device->read(data,1024))>0) { for(int i=0;i<n;i++) { switch(data[i]) { case 13: ProcessStatus(bt_buffer); bt_buffer=""; break; case 10: break; default: bt_buffer+=data[i]; break; } } } }
int ContactSettingChanged(WPARAM hContact, LPARAM lParam) { if (hContact == NULL) return 0; char *szProto = GetContactProto(hContact); if (szProto == nullptr) return 0; DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam; if (db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) if (ProcessExtraStatus(cws, hContact)) return 0; if (!strcmp(cws->szSetting, "Status")) if (ProcessStatus(cws, hContact)) return 0; if (!strcmp(cws->szModule, "CList") && !strcmp(cws->szSetting, "StatusMsg")) if (ProcessStatusMessage(cws, hContact)) return 0; return 0; }
void GoEyeUtil::TestNakade(const SgPointSet& points, const GoBoard& bd, SgBlackWhite color, bool isFullyEnclosed, bool& isNakade, bool& makeNakade, bool& makeFalse, bool& maybeSeki, bool& sureSeki, SgPoint* vital) { // handles case // of more than 1 point passing vital point test. // passes back vital point if exactly one is found. // @todo handle case where vital is illegal or suicide (eye within eye?). // also test bigger, would-be-alive shapes in atari. // @todo handle seki. SG_UNUSED(makeFalse); isNakade = makeNakade = maybeSeki = sureSeki = false; SgPoint vitalP(SG_NULLPOINT); const SgBlackWhite opp = SgOppBW(color); const int nuPoints = points.Size(); SG_ASSERT(nuPoints >= 3); // don't call for smaller areas, no need, // and results in isNakade = false which is confusing. if (nuPoints == 4) // special case 4 point areas { if (IsBulkyFour(points)) { if ( isFullyEnclosed && TwoDiagonalStonesInBulkyFour(bd, points, opp) ) makeNakade = true; else isNakade = true; /* */ return; /* */ } else if ( isFullyEnclosed && points.SubsetOf(bd.AllEmpty()) && IsBentFour(points, bd.Size(), vital) ) { makeNakade = true; /* */ return; /* */ } } else if (isFullyEnclosed && nuPoints == 5) // special case 5 point areas { const GoEyeStatus status = BulkyFiveNakade(bd, points, opp); if (ProcessStatus(status, isNakade, makeNakade)) /* */ return; /* */ } else if (isFullyEnclosed && nuPoints == 6) // special case 6 point areas { if (Is2x3Area (points)) { GoEyeStatus status = Special2x3Cases(bd, points, opp); if (ProcessStatus(status, isNakade, makeNakade)) /* */ return; /* */ } } if ( isFullyEnclosed && AlmostFilledByNakade(bd, points, opp) ) { isNakade = true; /* */ return; /* */ } if ( isFullyEnclosed && ( AlmostFilledByLivingShape(bd, points, opp) || ContainsLivingShape(bd, points, opp) ) ) { // not nakade, 2 eyes /* */ return; /* */ } int nuMakeNakade = 0; int nuVitalOccupied = 0; bool hasDivider = false; // counting number of nakade fixes bug with stretched 5 pt eye // that had 3 vital pts, // one of them occupied. was classified as 'isNakade7 = 1 eye. // see sgf/ld200,#20 for (SgSetIterator it(points); it; ++it) { SgPoint p(*it); if (IsVitalPt(points, p, opp, bd)) { if (bd.IsEmpty(p)) { if (bd.IsLegal(p, opp)) { ++nuMakeNakade; vitalP = p; } else hasDivider = true; } else ++nuVitalOccupied; } } if (hasDivider) { // alive } else if (nuMakeNakade == 1) // exactly one way to make nakade here. { makeNakade = true; *vital = vitalP; } else if (nuMakeNakade > 0) isNakade = false; else if (nuVitalOccupied < 3) isNakade = true; else { maybeSeki = true; // @todo if (IsSureSekiShape(...)) sureSeki = true; } }
int main(int argc, char *argv[]) #endif { int list_s; int sock; short int port; struct sockaddr_in servaddr; int maxBuffer = PHS_GetRequestBufferLength(); unsigned char* request; unsigned int requestLen; unsigned int responseType; int res; unsigned char responseHeader[4]; unsigned char* response; unsigned int responseLength; char** cursor; int ok; int repeat; #if defined(WIN32) WSADATA data; if(WSAStartup(MAKEWORD(2, 2), &data)) { printf("WSAStartup failed\n"); exit(1); } #endif request = malloc(maxBuffer); if(argc < 3) { printf("Usage %s [ip4address:]port request ...\n",argv[0]); printf("where request is one of\n"); printf(" status logid\n"); printf(" fetch logid blockid\n"); printf(" stream logid latency buffersize\n"); exit(1); } /* Set up server address */ if(!FillAddress(argv[1],&servaddr)) { printf( "%s: Invalid server address %s\n",argv[0], argv[1]); exit(1); } cursor = argv+2; argc-=2; /* Create the socket */ if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { printf( "Error creating socket %d.\n",sock); perror("Error"); exit(1); } if(connect(sock, (struct sockaddr *) &servaddr, sizeof(servaddr))<0) { printf("Error calling connect()\n"); exit(1); } /* Loop round all requests on the command line */ ok = 1; while(argc) { /* Create a request */ if(!strcmp("status",cursor[0])) { int logid; if(argc<2) { printf("Usage: status logid\n"); exit(1); } logid = ParseInt(cursor[1],&ok); if(!ok) { printf("Invalid logid\n"); exit(1); } requestLen = PHS_MakeStatusRequest(request,maxBuffer,&responseType,logid); printf("Sending Status Request logid %d\n",logid); cursor += 2; argc -= 2; } else if(!strcmp("fetch",cursor[0])) { int logid, blockid; if(argc<3) { printf("Usage: fetch logid blockid\n"); exit(1); } logid = ParseInt(cursor[1],&ok); if(!ok) { printf("Invalid logid\n"); exit(1); } blockid = ParseInt(cursor[2],&ok); if(!ok) { printf("Invalid blockid\n"); exit(1); } requestLen = PHS_MakeFetchRequest(request,maxBuffer,&responseType, logid,blockid); printf("Sending Fetch Request logid %d blockid %d\n", logid,blockid); cursor += 3; argc -= 3; } else if(!strcmp("stream",cursor[0])) { int logid, latency, buffersize, tag; if(argc<5) { printf("Usage: stream logid latency buffersize highesttag\n"); exit(1); } logid = ParseInt(cursor[1],&ok); if(!ok) { printf("Invalid logid\n"); exit(1); } latency = ParseInt(cursor[2],&ok); if(!ok) { printf("Invalid latency\n"); exit(1); } buffersize = ParseInt(cursor[3],&ok); if(!ok) { printf("Invalid buffersize\n"); exit(1); } tag = ParseInt(cursor[4],&ok); if(!ok) { printf("Invalid highesttag\n"); exit(1); } requestLen = PHS_MakeStreamRequest(request,maxBuffer,&responseType, logid,latency,buffersize,tag); printf("Sending Stream Request logid %d latency %d buffersize %d tag %d\n", logid,latency,buffersize,tag); cursor += 5; argc -= 5; } else { printf("Request %s is not understood\n",cursor[0]); exit(1); } /* Send request out */ res = send(sock,request,requestLen,0); if(res != requestLen) { printf("Expected to write %d but only wrote %d\n",requestLen,res); } repeat = 1; while(repeat) { /* Read the length back */ res = Recv(sock,responseHeader,4,0); if(res != 4) { printf("Could not read response header\n"); exit(1); } /* Make space for the response */ responseLength=PHS_GetResponseRemaining(responseHeader); response = malloc(responseLength); /* Read the rest of the response */ res = Recv(sock,response,responseLength,0); if(res != responseLength) { printf("Could not read response body\n"); exit(1); } printf("Read %d bytes in body\n",responseLength); /* Check that response is valid or in error */ res = PHS_GetResponseError(response,responseLength,responseType); if(res) { printf("Response has error %d\n",res); exit(1); } switch(responseType) { case PHS_RQ_STATUS: ProcessStatus(response); repeat = 0; break; case PHS_RQ_FETCH: ProcessFetch(response); repeat = 0; break; case PHS_RQ_STREAM: ProcessStream(response); break; default: printf("Cannot handle response type %d\n",responseType); break; } free(response); } } return 0; }